@pmndrs/vdb 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.
- package/CHANGELOG.md +592 -2
- package/README.md +85 -37
- package/THIRD_PARTY_NOTICES.md +197 -29
- package/dist/core/compute/atlas.d.ts +10 -2
- package/dist/core/compute/atlas.js +6 -1
- package/dist/core/compute/atlas.js.map +1 -1
- package/dist/core/compute/index.d.ts +3 -3
- package/dist/core/compute/index.js +2 -2
- package/dist/core/compute/index.js.map +1 -1
- package/dist/core/compute/majorant-build.d.ts +45 -0
- package/dist/core/compute/majorant-build.js +193 -0
- package/dist/core/compute/majorant-build.js.map +1 -0
- package/dist/core/compute/multi-scale.d.ts +155 -0
- package/dist/core/compute/multi-scale.js +684 -0
- package/dist/core/compute/multi-scale.js.map +1 -0
- package/dist/core/compute/pyramid.d.ts +22 -7
- package/dist/core/compute/pyramid.js +22 -9
- package/dist/core/compute/pyramid.js.map +1 -1
- package/dist/core/compute/shared.d.ts +1 -0
- package/dist/core/compute/shared.js.map +1 -1
- package/dist/core/compute/stats.d.ts +10 -3
- package/dist/core/compute/stats.js +6 -1
- package/dist/core/compute/stats.js.map +1 -1
- package/dist/core/compute/value-transform.d.ts +8 -1
- package/dist/core/compute/value-transform.js +9 -3
- package/dist/core/compute/value-transform.js.map +1 -1
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.js +8 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/frame/emission.d.ts +85 -0
- package/dist/core/frame/emission.js +422 -0
- package/dist/core/frame/emission.js.map +1 -0
- package/dist/core/frame/environment.d.ts +47 -0
- package/dist/core/frame/environment.js +178 -0
- package/dist/core/frame/environment.js.map +1 -0
- package/dist/core/frame/index.d.ts +39 -0
- package/dist/core/frame/index.js +27 -0
- package/dist/core/frame/index.js.map +1 -0
- package/dist/core/frame/kernels.d.ts +115 -0
- package/dist/core/frame/kernels.js +496 -0
- package/dist/core/frame/kernels.js.map +1 -0
- package/dist/core/frame/limits.d.ts +67 -0
- package/dist/core/frame/limits.js +109 -0
- package/dist/core/frame/limits.js.map +1 -0
- package/dist/core/frame/phase.d.ts +17 -0
- package/dist/core/frame/phase.js +53 -0
- package/dist/core/frame/phase.js.map +1 -0
- package/dist/core/frame/pipelines.d.ts +49 -0
- package/dist/core/frame/pipelines.js +147 -0
- package/dist/core/frame/pipelines.js.map +1 -0
- package/dist/core/frame/renderer.d.ts +122 -0
- package/dist/core/frame/renderer.js +1712 -0
- package/dist/core/frame/renderer.js.map +1 -0
- package/dist/core/frame/resources.d.ts +71 -0
- package/dist/core/frame/resources.js +100 -0
- package/dist/core/frame/resources.js.map +1 -0
- package/dist/core/frame/scattering.d.ts +97 -0
- package/dist/core/frame/scattering.js +332 -0
- package/dist/core/frame/scattering.js.map +1 -0
- package/dist/core/frame/settings.d.ts +243 -0
- package/dist/core/frame/settings.js +67 -0
- package/dist/core/frame/settings.js.map +1 -0
- package/dist/core/frame/shadows.d.ts +55 -0
- package/dist/core/frame/shadows.js +460 -0
- package/dist/core/frame/shadows.js.map +1 -0
- package/dist/core/frame/types.d.ts +415 -0
- package/dist/core/frame/types.js +49 -0
- package/dist/core/frame/types.js.map +1 -0
- package/dist/core/frame/uniforms.d.ts +105 -0
- package/dist/core/frame/uniforms.js +276 -0
- package/dist/core/frame/uniforms.js.map +1 -0
- package/dist/core/frame/wgsl/chunks.d.ts +4 -0
- package/dist/core/frame/wgsl/chunks.js +728 -0
- package/dist/core/frame/wgsl/chunks.js.map +1 -0
- package/dist/core/frame/wgsl/emission.d.ts +82 -0
- package/dist/core/frame/wgsl/emission.js +353 -0
- package/dist/core/frame/wgsl/emission.js.map +1 -0
- package/dist/core/frame/wgsl/environment.d.ts +42 -0
- package/dist/core/frame/wgsl/environment.js +711 -0
- package/dist/core/frame/wgsl/environment.js.map +1 -0
- package/dist/core/frame/wgsl/gather.d.ts +55 -0
- package/dist/core/frame/wgsl/gather.js +850 -0
- package/dist/core/frame/wgsl/gather.js.map +1 -0
- package/dist/core/frame/wgsl/integrate.d.ts +78 -0
- package/dist/core/frame/wgsl/integrate.js +213 -0
- package/dist/core/frame/wgsl/integrate.js.map +1 -0
- package/dist/core/frame/wgsl/lighting.d.ts +103 -0
- package/dist/core/frame/wgsl/lighting.js +1636 -0
- package/dist/core/frame/wgsl/lighting.js.map +1 -0
- package/dist/core/frame/wgsl/occluders.d.ts +20 -0
- package/dist/core/frame/wgsl/occluders.js +95 -0
- package/dist/core/frame/wgsl/occluders.js.map +1 -0
- package/dist/core/frame/wgsl/resolve.d.ts +19 -0
- package/dist/core/frame/wgsl/resolve.js +205 -0
- package/dist/core/frame/wgsl/resolve.js.map +1 -0
- package/dist/core/frame/wgsl/shadows.d.ts +35 -0
- package/dist/core/frame/wgsl/shadows.js +328 -0
- package/dist/core/frame/wgsl/shadows.js.map +1 -0
- package/dist/core/half.d.ts +11 -0
- package/dist/core/half.js +22 -0
- package/dist/core/half.js.map +1 -0
- package/dist/core/index.d.ts +25 -3
- package/dist/core/index.js +23 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/internal.d.ts +17 -1
- package/dist/core/internal.js +18 -1
- package/dist/core/internal.js.map +1 -1
- package/dist/core/pool/image-header.d.ts +13 -2
- package/dist/core/pool/image-header.js +24 -5
- package/dist/core/pool/image-header.js.map +1 -1
- package/dist/core/pool/layout.d.ts +35 -1
- package/dist/core/pool/layout.js +51 -2
- package/dist/core/pool/layout.js.map +1 -1
- package/dist/core/pool/limits.d.ts +1 -0
- package/dist/core/pool/limits.js +1 -0
- package/dist/core/pool/limits.js.map +1 -1
- package/dist/core/pool/pool.d.ts +120 -15
- package/dist/core/pool/pool.js +255 -24
- package/dist/core/pool/pool.js.map +1 -1
- package/dist/core/reference/index.d.ts +6 -0
- package/dist/core/reference/index.js +7 -0
- package/dist/core/reference/index.js.map +1 -0
- package/dist/core/reference/renderer.d.ts +105 -0
- package/dist/core/reference/renderer.js +474 -0
- package/dist/core/reference/renderer.js.map +1 -0
- package/dist/core/reference/wgsl.d.ts +65 -0
- package/dist/core/reference/wgsl.js +803 -0
- package/dist/core/reference/wgsl.js.map +1 -0
- package/dist/{three → core}/sequence.d.ts +32 -2
- package/dist/{three → core}/sequence.js +24 -2
- package/dist/core/sequence.js.map +1 -0
- package/dist/core/source/brick-cache.d.ts +165 -0
- package/dist/core/source/brick-cache.js +627 -0
- package/dist/core/source/brick-cache.js.map +1 -0
- package/dist/core/source/dense-fill.d.ts +53 -0
- package/dist/core/source/dense-fill.js +377 -0
- package/dist/core/source/dense-fill.js.map +1 -0
- package/dist/core/source/dense.d.ts +33 -2
- package/dist/core/source/dense.js +121 -24
- package/dist/core/source/dense.js.map +1 -1
- package/dist/core/source/sparse-wgsl.d.ts +92 -0
- package/dist/core/source/sparse-wgsl.js +481 -0
- package/dist/core/source/sparse-wgsl.js.map +1 -0
- package/dist/core/source/sparse.d.ts +192 -0
- package/dist/core/source/sparse.js +762 -0
- package/dist/core/source/sparse.js.map +1 -0
- package/dist/core/source/types.d.ts +59 -2
- package/dist/core/source/types.js.map +1 -1
- package/dist/core/surface/index.d.ts +10 -0
- package/dist/core/surface/index.js +9 -0
- package/dist/core/surface/index.js.map +1 -0
- package/dist/core/surface/level-set-pass.d.ts +140 -0
- package/dist/core/surface/level-set-pass.js +291 -0
- package/dist/core/surface/level-set-pass.js.map +1 -0
- package/dist/core/surface/level-set-wgsl.d.ts +46 -0
- package/dist/core/surface/level-set-wgsl.js +99 -0
- package/dist/core/surface/level-set-wgsl.js.map +1 -0
- package/dist/core/surface/points.d.ts +109 -0
- package/dist/core/surface/points.js +226 -0
- package/dist/core/surface/points.js.map +1 -0
- package/dist/core/types.d.ts +12 -3
- package/dist/core/types.js +6 -2
- package/dist/core/types.js.map +1 -1
- package/dist/core/wgsl/api.d.ts +29 -5
- package/dist/core/wgsl/api.js +110 -27
- package/dist/core/wgsl/api.js.map +1 -1
- package/dist/core/wgsl/generate.d.ts +8 -0
- package/dist/core/wgsl/generate.js +195 -22
- package/dist/core/wgsl/generate.js.map +1 -1
- package/dist/core/wgsl/lean.d.ts +50 -0
- package/dist/core/wgsl/lean.js +327 -0
- package/dist/core/wgsl/lean.js.map +1 -0
- package/dist/core/wgsl/level-set.d.ts +5 -1
- package/dist/core/wgsl/level-set.js +11 -5
- package/dist/core/wgsl/level-set.js.map +1 -1
- package/dist/core/wgsl/majorant.d.ts +62 -0
- package/dist/core/wgsl/majorant.js +381 -0
- package/dist/core/wgsl/majorant.js.map +1 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
- package/dist/core/wgsl/types.d.ts +97 -3
- package/dist/core/wgsl/types.js.map +1 -1
- package/dist/three/coarse-first.d.ts +53 -8
- package/dist/three/coarse-first.js +24 -6
- package/dist/three/coarse-first.js.map +1 -1
- package/dist/three/compute.d.ts +12 -2
- package/dist/three/compute.js +16 -6
- package/dist/three/compute.js.map +1 -1
- package/dist/three/device.d.ts +7 -0
- package/dist/three/device.js +3 -0
- package/dist/three/device.js.map +1 -1
- package/dist/three/frame/core-environment.d.ts +38 -0
- package/dist/three/frame/core-environment.js +154 -0
- package/dist/three/frame/core-environment.js.map +1 -0
- package/dist/three/frame/core-integrate-material.d.ts +34 -0
- package/dist/three/frame/core-integrate-material.js +162 -0
- package/dist/three/frame/core-integrate-material.js.map +1 -0
- package/dist/three/frame/core-occluders.d.ts +53 -0
- package/dist/three/frame/core-occluders.js +193 -0
- package/dist/three/frame/core-occluders.js.map +1 -0
- package/dist/three/frame/core-structs.d.ts +34 -0
- package/dist/three/frame/core-structs.js +61 -0
- package/dist/three/frame/core-structs.js.map +1 -0
- package/dist/three/frame/core-textures.d.ts +41 -0
- package/dist/three/frame/core-textures.js +114 -0
- package/dist/three/frame/core-textures.js.map +1 -0
- package/dist/three/frame/emission-light.d.ts +64 -114
- package/dist/three/frame/emission-light.js +188 -567
- package/dist/three/frame/emission-light.js.map +1 -1
- package/dist/three/frame/index.d.ts +11 -31
- package/dist/three/frame/index.js +9 -29
- package/dist/three/frame/index.js.map +1 -1
- package/dist/three/frame/medium.d.ts +12 -0
- package/dist/three/frame/medium.js.map +1 -1
- package/dist/three/frame/renderer.d.ts +58 -454
- package/dist/three/frame/renderer.js +409 -1427
- package/dist/three/frame/renderer.js.map +1 -1
- package/dist/three/frame/spectrum.d.ts +0 -14
- package/dist/three/frame/spectrum.js +2 -23
- package/dist/three/frame/spectrum.js.map +1 -1
- package/dist/three/frame/three-internals.d.ts +3 -8
- package/dist/three/frame/three-internals.js +13 -11
- package/dist/three/frame/three-internals.js.map +1 -1
- package/dist/three/frame/volume-shadows.d.ts +93 -107
- package/dist/three/frame/volume-shadows.js +278 -631
- package/dist/three/frame/volume-shadows.js.map +1 -1
- package/dist/three/frame/volume.d.ts +91 -33
- package/dist/three/frame/volume.js +63 -51
- package/dist/three/frame/volume.js.map +1 -1
- package/dist/three/grid-node.d.ts +34 -1
- package/dist/three/grid-node.js +36 -1
- package/dist/three/grid-node.js.map +1 -1
- package/dist/three/index.d.ts +20 -11
- package/dist/three/index.js +21 -12
- package/dist/three/index.js.map +1 -1
- package/dist/three/internal.d.ts +14 -8
- package/dist/three/internal.js +11 -7
- package/dist/three/internal.js.map +1 -1
- package/dist/three/level-set-material.d.ts +81 -8
- package/dist/three/level-set-material.js +162 -125
- package/dist/three/level-set-material.js.map +1 -1
- package/dist/three/level-set-physical-material.d.ts +154 -0
- package/dist/three/level-set-physical-material.js +253 -0
- package/dist/three/level-set-physical-material.js.map +1 -0
- package/dist/three/level-set-velocity.d.ts +94 -0
- package/dist/three/level-set-velocity.js +208 -0
- package/dist/three/level-set-velocity.js.map +1 -0
- package/dist/three/material.d.ts +141 -11
- package/dist/three/material.js +161 -18
- package/dist/three/material.js.map +1 -1
- package/dist/three/points.d.ts +60 -4
- package/dist/three/points.js +140 -9
- package/dist/three/points.js.map +1 -1
- package/dist/three/sparse-source.d.ts +49 -117
- package/dist/three/sparse-source.js +109 -580
- package/dist/three/sparse-source.js.map +1 -1
- package/dist/three/volume-source.d.ts +11 -156
- package/dist/three/volume-source.js +29 -272
- package/dist/three/volume-source.js.map +1 -1
- package/dist/tools/cpu/brick-atlas.d.ts +36 -0
- package/dist/tools/cpu/brick-atlas.js +129 -0
- package/dist/tools/cpu/brick-atlas.js.map +1 -0
- package/dist/tools/cpu/compute.d.ts +23 -4
- package/dist/tools/cpu/compute.js +35 -14
- package/dist/tools/cpu/compute.js.map +1 -1
- package/dist/tools/cpu/lean-reads.d.ts +81 -0
- package/dist/tools/cpu/lean-reads.js +262 -0
- package/dist/tools/cpu/lean-reads.js.map +1 -0
- package/dist/tools/cpu/level-set.d.ts +42 -3
- package/dist/tools/cpu/level-set.js +59 -7
- package/dist/tools/cpu/level-set.js.map +1 -1
- package/dist/tools/cpu/majorant.d.ts +265 -0
- package/dist/tools/cpu/majorant.js +541 -0
- package/dist/tools/cpu/majorant.js.map +1 -0
- package/dist/tools/cpu/march.d.ts +93 -2
- package/dist/tools/cpu/march.js +165 -14
- package/dist/tools/cpu/march.js.map +1 -1
- package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
- package/dist/tools/cpu/mesh-decimate.js +1225 -0
- package/dist/tools/cpu/mesh-decimate.js.map +1 -0
- package/dist/tools/cpu/points.d.ts +29 -0
- package/dist/tools/cpu/points.js +38 -0
- package/dist/tools/cpu/points.js.map +1 -0
- package/dist/tools/cpu/read-value.d.ts +19 -6
- package/dist/tools/cpu/read-value.js +32 -17
- package/dist/tools/cpu/read-value.js.map +1 -1
- package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
- package/dist/tools/cpu/sample-trilinear.js +19 -7
- package/dist/tools/cpu/sample-trilinear.js.map +1 -1
- package/dist/tools/cpu/stride-tables.d.ts +2 -2
- package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
- package/dist/tools/cpu/stride-tables.generated.js +7 -6
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
- package/dist/tools/cpu/stride-tables.js +1 -1
- package/dist/tools/cpu/stride-tables.js.map +1 -1
- package/dist/tools/cpu/surface-nets.d.ts +90 -0
- package/dist/tools/cpu/surface-nets.js +597 -0
- package/dist/tools/cpu/surface-nets.js.map +1 -0
- package/dist/tools/errors.d.ts +9 -0
- package/dist/tools/errors.js +9 -0
- package/dist/tools/errors.js.map +1 -1
- package/dist/tools/frame/ambient.d.ts +98 -0
- package/dist/tools/frame/ambient.js +274 -0
- package/dist/tools/frame/ambient.js.map +1 -0
- package/dist/tools/frame/blackbody.d.ts +15 -0
- package/dist/tools/frame/blackbody.js +35 -0
- package/dist/tools/frame/blackbody.js.map +1 -1
- package/dist/tools/frame/brick-cache.d.ts +165 -0
- package/dist/tools/frame/brick-cache.js +326 -0
- package/dist/tools/frame/brick-cache.js.map +1 -0
- package/dist/tools/frame/emission.d.ts +9 -0
- package/dist/tools/frame/emission.js +9 -1
- package/dist/tools/frame/emission.js.map +1 -1
- package/dist/tools/frame/environment-gpu.d.ts +111 -0
- package/dist/tools/frame/environment-gpu.js +280 -0
- package/dist/tools/frame/environment-gpu.js.map +1 -0
- package/dist/tools/frame/environment.d.ts +3 -2
- package/dist/tools/frame/environment.js +8 -4
- package/dist/tools/frame/environment.js.map +1 -1
- package/dist/tools/frame/froxel.d.ts +58 -0
- package/dist/tools/frame/froxel.js +115 -0
- package/dist/tools/frame/froxel.js.map +1 -0
- package/dist/tools/frame/grid.d.ts +90 -0
- package/dist/tools/frame/grid.js +112 -13
- package/dist/tools/frame/grid.js.map +1 -1
- package/dist/tools/frame/index.d.ts +14 -0
- package/dist/tools/frame/index.js +45 -4
- package/dist/tools/frame/index.js.map +1 -1
- package/dist/tools/frame/medium.d.ts +16 -0
- package/dist/tools/frame/medium.js +3 -1
- package/dist/tools/frame/medium.js.map +1 -1
- package/dist/tools/frame/mie.d.ts +9 -0
- package/dist/tools/frame/mie.js +18 -0
- package/dist/tools/frame/mie.js.map +1 -1
- package/dist/tools/frame/mlp-nn.d.ts +36 -0
- package/dist/tools/frame/mlp-nn.js +159 -0
- package/dist/tools/frame/mlp-nn.js.map +1 -0
- package/dist/tools/frame/mlp-tza.d.ts +29 -0
- package/dist/tools/frame/mlp-tza.js +186 -0
- package/dist/tools/frame/mlp-tza.js.map +1 -0
- package/dist/tools/frame/mlp.d.ts +183 -0
- package/dist/tools/frame/mlp.js +434 -0
- package/dist/tools/frame/mlp.js.map +1 -0
- package/dist/tools/frame/ms-exit.d.ts +42 -0
- package/dist/tools/frame/ms-exit.js +90 -0
- package/dist/tools/frame/ms-exit.js.map +1 -0
- package/dist/tools/frame/multi-scale.d.ts +152 -0
- package/dist/tools/frame/multi-scale.js +302 -0
- package/dist/tools/frame/multi-scale.js.map +1 -0
- package/dist/tools/frame/neural-weights.d.ts +6 -5
- package/dist/tools/frame/neural-weights.js +234 -235
- package/dist/tools/frame/neural-weights.js.map +1 -1
- package/dist/tools/frame/neural.js +1 -1
- package/dist/tools/frame/neural.js.map +1 -1
- package/dist/tools/frame/occluders.d.ts +51 -0
- package/dist/tools/frame/occluders.js +72 -0
- package/dist/tools/frame/occluders.js.map +1 -0
- package/dist/tools/frame/pyramid-layout.d.ts +17 -0
- package/dist/tools/frame/pyramid-layout.js +47 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -1
- package/dist/tools/frame/shadows.d.ts +110 -0
- package/dist/tools/frame/shadows.js +286 -0
- package/dist/tools/frame/shadows.js.map +1 -1
- package/dist/tools/frame/sparse.d.ts +82 -0
- package/dist/tools/frame/sparse.js +242 -1
- package/dist/tools/frame/sparse.js.map +1 -1
- package/dist/tools/frame/spectral-stack.d.ts +159 -0
- package/dist/tools/frame/spectral-stack.js +391 -0
- package/dist/tools/frame/spectral-stack.js.map +1 -0
- package/dist/tools/frame/spectral.d.ts +21 -2
- package/dist/tools/frame/spectral.js +30 -8
- package/dist/tools/frame/spectral.js.map +1 -1
- package/dist/tools/frame/stack.d.ts +115 -0
- package/dist/tools/frame/stack.js +290 -0
- package/dist/tools/frame/stack.js.map +1 -0
- package/dist/tools/frame/view.d.ts +131 -0
- package/dist/tools/frame/view.js +337 -0
- package/dist/tools/frame/view.js.map +1 -0
- package/dist/tools/index.d.ts +66 -15
- package/dist/tools/index.js +55 -11
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/internal.d.ts +58 -17
- package/dist/tools/internal.js +65 -11
- package/dist/tools/internal.js.map +1 -1
- package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
- package/dist/tools/nanovdb/build-from-vdb.js +10 -2
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
- package/dist/tools/nanovdb/bytes.d.ts +17 -4
- package/dist/tools/nanovdb/bytes.js +46 -3
- package/dist/tools/nanovdb/bytes.js.map +1 -1
- package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
- package/dist/tools/nanovdb/coarse-first.js +7 -1
- package/dist/tools/nanovdb/coarse-first.js.map +1 -1
- package/dist/tools/nanovdb/half.d.ts +22 -0
- package/dist/tools/nanovdb/half.js +73 -0
- package/dist/tools/nanovdb/half.js.map +1 -0
- package/dist/tools/nanovdb/index.d.ts +3 -1
- package/dist/tools/nanovdb/index.js +2 -1
- package/dist/tools/nanovdb/index.js.map +1 -1
- package/dist/tools/nanovdb/inspect.d.ts +10 -1
- package/dist/tools/nanovdb/inspect.js +8 -1
- package/dist/tools/nanovdb/inspect.js.map +1 -1
- package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
- package/dist/tools/nanovdb/leaf-codec.js +40 -4
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
- package/dist/tools/nanovdb/quantize.d.ts +39 -10
- package/dist/tools/nanovdb/quantize.js +96 -44
- package/dist/tools/nanovdb/quantize.js.map +1 -1
- package/dist/tools/nanovdb/resample.d.ts +20 -3
- package/dist/tools/nanovdb/resample.js +20 -7
- package/dist/tools/nanovdb/resample.js.map +1 -1
- package/dist/tools/nanovdb/serialize.d.ts +34 -3
- package/dist/tools/nanovdb/serialize.js +51 -7
- package/dist/tools/nanovdb/serialize.js.map +1 -1
- package/dist/tools/nanovdb/stats.d.ts +34 -5
- package/dist/tools/nanovdb/stats.js +87 -11
- package/dist/tools/nanovdb/stats.js.map +1 -1
- package/dist/tools/nanovdb/transform.d.ts +4 -0
- package/dist/tools/nanovdb/transform.js +3 -0
- package/dist/tools/nanovdb/transform.js.map +1 -1
- package/dist/tools/nanovdb/tree.d.ts +14 -3
- package/dist/tools/nanovdb/tree.js +25 -13
- package/dist/tools/nanovdb/tree.js.map +1 -1
- package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
- package/dist/tools/nanovdb/write-nvdb.js +108 -28
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
- package/dist/tools/nvdb-file.d.ts +77 -7
- package/dist/tools/nvdb-file.js +177 -20
- package/dist/tools/nvdb-file.js.map +1 -1
- package/dist/tools/nvdb-stream.d.ts +23 -7
- package/dist/tools/nvdb-stream.js +78 -34
- package/dist/tools/nvdb-stream.js.map +1 -1
- package/dist/tools/reference/analytic.d.ts +41 -0
- package/dist/tools/reference/analytic.js +95 -0
- package/dist/tools/reference/analytic.js.map +1 -0
- package/dist/tools/reference/environment.d.ts +62 -0
- package/dist/tools/reference/environment.js +154 -0
- package/dist/tools/reference/environment.js.map +1 -0
- package/dist/tools/reference/index.d.ts +12 -0
- package/dist/tools/reference/index.js +13 -0
- package/dist/tools/reference/index.js.map +1 -0
- package/dist/tools/reference/media.d.ts +14 -0
- package/dist/tools/reference/media.js +30 -0
- package/dist/tools/reference/media.js.map +1 -0
- package/dist/tools/reference/rng.d.ts +20 -0
- package/dist/tools/reference/rng.js +30 -0
- package/dist/tools/reference/rng.js.map +1 -0
- package/dist/tools/reference/scene.d.ts +312 -0
- package/dist/tools/reference/scene.js +169 -0
- package/dist/tools/reference/scene.js.map +1 -0
- package/dist/tools/reference/tables.d.ts +98 -0
- package/dist/tools/reference/tables.js +264 -0
- package/dist/tools/reference/tables.js.map +1 -0
- package/dist/tools/reference/trace.d.ts +160 -0
- package/dist/tools/reference/trace.js +497 -0
- package/dist/tools/reference/trace.js.map +1 -0
- package/dist/tools/vdb/blosc-write.d.ts +43 -0
- package/dist/tools/vdb/blosc-write.js +197 -0
- package/dist/tools/vdb/blosc-write.js.map +1 -0
- package/dist/tools/vdb/blosc.d.ts +35 -5
- package/dist/tools/vdb/blosc.js +82 -26
- package/dist/tools/vdb/blosc.js.map +1 -1
- package/dist/tools/vdb/blosclz.d.ts +33 -0
- package/dist/tools/vdb/blosclz.js +112 -0
- package/dist/tools/vdb/blosclz.js.map +1 -0
- package/dist/tools/vdb/byte-reader.d.ts +13 -3
- package/dist/tools/vdb/byte-reader.js +26 -4
- package/dist/tools/vdb/byte-reader.js.map +1 -1
- package/dist/tools/vdb/compression.d.ts +13 -5
- package/dist/tools/vdb/compression.js +13 -2
- package/dist/tools/vdb/compression.js.map +1 -1
- package/dist/tools/vdb/grid.js +8 -2
- package/dist/tools/vdb/grid.js.map +1 -1
- package/dist/tools/vdb/index.d.ts +2 -1
- package/dist/tools/vdb/index.js.map +1 -1
- package/dist/tools/vdb/lz4.d.ts +30 -0
- package/dist/tools/vdb/lz4.js +228 -0
- package/dist/tools/vdb/lz4.js.map +1 -0
- package/dist/tools/vdb/metadata.js +1 -1
- package/dist/tools/vdb/metadata.js.map +1 -1
- package/dist/tools/vdb/parse.d.ts +24 -2
- package/dist/tools/vdb/parse.js +102 -32
- package/dist/tools/vdb/parse.js.map +1 -1
- package/dist/tools/vdb/point-render-data.d.ts +49 -1
- package/dist/tools/vdb/point-render-data.js +91 -11
- package/dist/tools/vdb/point-render-data.js.map +1 -1
- package/dist/tools/vdb/points.d.ts +26 -0
- package/dist/tools/vdb/points.js +46 -5
- package/dist/tools/vdb/points.js.map +1 -1
- package/dist/tools/vdb/types.d.ts +59 -2
- package/dist/tools/vdb/types.js.map +1 -1
- package/dist/tools/wvdb/bake.d.ts +38 -9
- package/dist/tools/wvdb/bake.js +63 -13
- package/dist/tools/wvdb/bake.js.map +1 -1
- package/dist/tools/wvdb/dense.d.ts +80 -1
- package/dist/tools/wvdb/dense.js +67 -8
- package/dist/tools/wvdb/dense.js.map +1 -1
- package/dist/tools/wvdb/format.d.ts +59 -0
- package/dist/tools/wvdb/format.js +3 -0
- package/dist/tools/wvdb/format.js.map +1 -1
- package/dist/tools/wvdb/index.d.ts +1 -0
- package/dist/tools/wvdb/index.js +1 -0
- package/dist/tools/wvdb/index.js.map +1 -1
- package/dist/tools/wvdb/level-set.d.ts +10 -2
- package/dist/tools/wvdb/level-set.js.map +1 -1
- package/dist/tools/wvdb/nanovdb.d.ts +6 -1
- package/dist/tools/wvdb/nanovdb.js +5 -1
- package/dist/tools/wvdb/nanovdb.js.map +1 -1
- package/dist/tools/wvdb/partial.d.ts +74 -0
- package/dist/tools/wvdb/partial.js +233 -0
- package/dist/tools/wvdb/partial.js.map +1 -0
- package/dist/tools/wvdb/read.d.ts +77 -1
- package/dist/tools/wvdb/read.js +30 -7
- package/dist/tools/wvdb/read.js.map +1 -1
- package/dist/tools/wvdb/write.d.ts +23 -1
- package/dist/tools/wvdb/write.js +8 -1
- package/dist/tools/wvdb/write.js.map +1 -1
- package/package.json +2 -1
- package/vendor/VENDOR.md +21 -6
- package/vendor/pnanovdb.wgsl +52 -14
- package/dist/three/frame/blackbody.d.ts +0 -42
- package/dist/three/frame/blackbody.js +0 -74
- package/dist/three/frame/blackbody.js.map +0 -1
- package/dist/three/frame/chunks.d.ts +0 -157
- package/dist/three/frame/chunks.js +0 -559
- package/dist/three/frame/chunks.js.map +0 -1
- package/dist/three/frame/density-material.d.ts +0 -53
- package/dist/three/frame/density-material.js +0 -353
- package/dist/three/frame/density-material.js.map +0 -1
- package/dist/three/frame/environment-grid-material.d.ts +0 -21
- package/dist/three/frame/environment-grid-material.js +0 -184
- package/dist/three/frame/environment-grid-material.js.map +0 -1
- package/dist/three/frame/environment-material.d.ts +0 -22
- package/dist/three/frame/environment-material.js +0 -87
- package/dist/three/frame/environment-material.js.map +0 -1
- package/dist/three/frame/grid-mip-material.d.ts +0 -12
- package/dist/three/frame/grid-mip-material.js +0 -61
- package/dist/three/frame/grid-mip-material.js.map +0 -1
- package/dist/three/frame/inject-material.d.ts +0 -56
- package/dist/three/frame/inject-material.js +0 -424
- package/dist/three/frame/inject-material.js.map +0 -1
- package/dist/three/frame/integrate-material.d.ts +0 -26
- package/dist/three/frame/integrate-material.js +0 -198
- package/dist/three/frame/integrate-material.js.map +0 -1
- package/dist/three/frame/layout.d.ts +0 -34
- package/dist/three/frame/layout.js +0 -48
- package/dist/three/frame/layout.js.map +0 -1
- package/dist/three/frame/lighting-material.d.ts +0 -41
- package/dist/three/frame/lighting-material.js +0 -257
- package/dist/three/frame/lighting-material.js.map +0 -1
- package/dist/three/frame/lights.d.ts +0 -11
- package/dist/three/frame/lights.js +0 -16
- package/dist/three/frame/lights.js.map +0 -1
- package/dist/three/frame/neural.d.ts +0 -14
- package/dist/three/frame/neural.js +0 -105
- package/dist/three/frame/neural.js.map +0 -1
- package/dist/three/frame/phase.d.ts +0 -44
- package/dist/three/frame/phase.js +0 -80
- package/dist/three/frame/phase.js.map +0 -1
- package/dist/three/frame/shadow-density-material.d.ts +0 -30
- package/dist/three/frame/shadow-density-material.js +0 -123
- package/dist/three/frame/shadow-density-material.js.map +0 -1
- package/dist/three/frame/temporal-material.d.ts +0 -29
- package/dist/three/frame/temporal-material.js +0 -152
- package/dist/three/frame/temporal-material.js.map +0 -1
- package/dist/three/frame/transmittance-material.d.ts +0 -31
- package/dist/three/frame/transmittance-material.js +0 -315
- package/dist/three/frame/transmittance-material.js.map +0 -1
- package/dist/three/frame/view.d.ts +0 -103
- package/dist/three/frame/view.js +0 -296
- package/dist/three/frame/view.js.map +0 -1
- package/dist/three/frame/volume-shadow-material.d.ts +0 -36
- package/dist/three/frame/volume-shadow-material.js +0 -128
- package/dist/three/frame/volume-shadow-material.js.map +0 -1
- package/dist/three/sequence.js.map +0 -1
package/dist/tools/nvdb-file.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* - fixtures/downloads/openvdb-sparse/nanovdb/nanovdb/NanoVDB.h
|
|
12
12
|
* (magic numbers, Version packing, GridType/GridClass enums, GridData)
|
|
13
13
|
* - vendor/stride-tables.json (extracted PNanoVDB.h defines: GridData,
|
|
14
|
-
* TreeData and RootData offsets, ABI 32.9.1)
|
|
14
|
+
* TreeData and RootData offsets, ABI 32.11.0; unchanged since 32.9.1)
|
|
15
15
|
*
|
|
16
16
|
* ## `.nvdb` "segment" format (FileHeader magic `NanoVDB0`/`NanoVDB2`)
|
|
17
17
|
*
|
|
@@ -61,9 +61,16 @@
|
|
|
61
61
|
* followed by that many bytes of zlib-format (RFC 1950) compressed data —
|
|
62
62
|
* i.e. exactly what C's `compress()`/`uncompress()` (and fflate's
|
|
63
63
|
* `zlibSync`/`unzlibSync`) produce/consume. The decompressed length must
|
|
64
|
-
* equal the grid's `gridSize` field.
|
|
65
|
-
*
|
|
66
|
-
*
|
|
64
|
+
* equal the grid's `gridSize` field.
|
|
65
|
+
*
|
|
66
|
+
* ## BLOSC on-disk framing (K7.C; `io::Internal::write`/`read`, IO.h @ v14.0.0)
|
|
67
|
+
*
|
|
68
|
+
* Per grid: one or more chunks, each an 8-byte LE u64 compressed size and one
|
|
69
|
+
* Blosc1 frame, until the frames' uncompressed bytes add up to `gridSize`.
|
|
70
|
+
* NanoVDB splits at 1 GiB (`MAX_SIZE`) and writes LZ4 frames (byte shuffle,
|
|
71
|
+
* typesize 4, 256 KiB blocks); NVIDIA Warp writes one BloscLZ frame per grid
|
|
72
|
+
* (python-blosc defaults), which NanoVDB 14 reads too. We accept any chunking
|
|
73
|
+
* whose sizes add up (DIVERGES V69). Frames decode with `tools/vdb/blosc.ts`.
|
|
67
74
|
*
|
|
68
75
|
* ## Raw grid buffer format (magic `NanoVDB1`, no FileHeader)
|
|
69
76
|
*
|
|
@@ -76,6 +83,7 @@
|
|
|
76
83
|
*/
|
|
77
84
|
import { unzlibSync } from "fflate";
|
|
78
85
|
import { NvdbFormatError, VDBToolsError, VDBUnsupportedError } from "./errors.js";
|
|
86
|
+
import { BLOSC_HEADER_SIZE, decompressBloscInto } from "./vdb/blosc.js";
|
|
79
87
|
export { NvdbFormatError } from "./errors.js";
|
|
80
88
|
/** `.nvdb` FileHeader size in bytes (magic + version + grid count + codec). */
|
|
81
89
|
export const FILE_HEADER_SIZE = 16;
|
|
@@ -89,14 +97,26 @@ export const GRID_DATA_SIZE = 672;
|
|
|
89
97
|
* by `NvdbFile.fromArrayBuffer`.
|
|
90
98
|
*/
|
|
91
99
|
export const MAGIC_ASCII = ["NanoVDB0", "NanoVDB1", "NanoVDB2"];
|
|
92
|
-
/**
|
|
100
|
+
/** `.nvdb` file codecs: all three are read (ZIP through fflate, BLOSC LZ4/BloscLZ since K7.C). */
|
|
93
101
|
export const NvdbCodec = {
|
|
94
102
|
NONE: 0,
|
|
95
103
|
ZIP: 1,
|
|
96
104
|
BLOSC: 2,
|
|
97
105
|
};
|
|
98
|
-
/** Grid types targeted for v1 (FogVolume rendering). */
|
|
99
|
-
export const NVDB_SUPPORTED_GRID_TYPES = ["Float", "Fp4", "Fp8", "Fp16", "FpN"];
|
|
106
|
+
/** Grid types targeted for v1 (FogVolume rendering); Half (NanoVDB 13.2 raw binary16) since K7.H. */
|
|
107
|
+
export const NVDB_SUPPORTED_GRID_TYPES = ["Float", "Fp4", "Fp8", "Fp16", "FpN", "Half"];
|
|
108
|
+
/**
|
|
109
|
+
* The pool / WGSL module type name of a `.nvdb` grid type (P1.17): the file's metadata spells NanoVDB's
|
|
110
|
+
* `GridType` names (`'Float'`, `'Fp8'`, `'FpN'`, `'Half'`), a `VDBGridPool`, `vdbModuleWgsl({ types })` and
|
|
111
|
+
* `vdbQuantize` take them in lower case (`'float'`, `'fp8'`, `'fpn'`, `'half'`).
|
|
112
|
+
*
|
|
113
|
+
* @param gridType A grid's metadata, or its `gridType` string.
|
|
114
|
+
* @returns The lower-case name, or `null` for a type the pool does not hold (`'Vec3f'`, `'Double'`, ...).
|
|
115
|
+
*/
|
|
116
|
+
export function nvdbPoolType(gridType) {
|
|
117
|
+
const name = typeof gridType === "string" ? gridType : gridType.gridType;
|
|
118
|
+
return SUPPORTED_GRID_TYPES_SET.includes(name) ? name.toLowerCase() : null;
|
|
119
|
+
}
|
|
100
120
|
// ---------------------------------------------------------------------------
|
|
101
121
|
// FileHeader / FileMetaData byte offsets (see module doc comment for the
|
|
102
122
|
// full field table; these are the raw numbers used below).
|
|
@@ -203,14 +223,20 @@ function parseVersion(raw) {
|
|
|
203
223
|
function formatVersion(v) {
|
|
204
224
|
return `${v.major}.${v.minor}.${v.patch}`;
|
|
205
225
|
}
|
|
206
|
-
/** ABI major version this loader targets (vendor/stride-tables.json `$meta.abi` = "32.
|
|
226
|
+
/** ABI major version this loader targets (vendor/stride-tables.json `$meta.abi` = "32.11.0"). */
|
|
207
227
|
const NANOVDB_MAJOR_VERSION = 32;
|
|
228
|
+
/**
|
|
229
|
+
* NanoVDB's own rule (`Version::isCompatible`): only the major version must match; a minor
|
|
230
|
+
* version bump keeps the grid layout (NanoVDB 32.11 of OpenVDB v14 included). A different
|
|
231
|
+
* major is a layout this loader can't read, so it fails before any field is trusted (K7.C).
|
|
232
|
+
*/
|
|
208
233
|
export function checkVersion(raw) {
|
|
209
234
|
const v = parseVersion(raw);
|
|
210
235
|
if (v.major !== NANOVDB_MAJOR_VERSION) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
`
|
|
236
|
+
const when = v.major > NANOVDB_MAJOR_VERSION ? "a newer" : "an older";
|
|
237
|
+
throw new VDBUnsupportedError(`NvdbFile: incompatible NanoVDB version ${formatVersion(v)}, written by ${when} NanoVDB ` +
|
|
238
|
+
`(this loader reads NanoVDB ${NANOVDB_MAJOR_VERSION}.x, the grid ABI of OpenVDB 10 to 14). ` +
|
|
239
|
+
`Re-export the file with a NanoVDB whose major version is ${NANOVDB_MAJOR_VERSION}.`);
|
|
214
240
|
}
|
|
215
241
|
return v;
|
|
216
242
|
}
|
|
@@ -272,7 +298,7 @@ export function validateGridType(gridType, gridName) {
|
|
|
272
298
|
if (!SUPPORTED_GRID_TYPES_SET.includes(gridType)) {
|
|
273
299
|
throw new VDBUnsupportedError(`NvdbFile: grid "${gridName}" is a ${gridType} grid, which this loader does not ` +
|
|
274
300
|
`support — v1 only handles FogVolume grids of type ${NVDB_SUPPORTED_GRID_TYPES.join("/")}. ` +
|
|
275
|
-
`Re-export as float/fp4/fp8/fp16
|
|
301
|
+
`Re-export as float/fp4/fp8/fp16/fpn/half, e.g. \`nanovdb_convert --fp8 in.vdb out.nvdb\`.`);
|
|
276
302
|
}
|
|
277
303
|
}
|
|
278
304
|
/** Zero-copy u32 view when the input is already 4-byte aligned; a copy otherwise. */
|
|
@@ -334,15 +360,90 @@ export function readFileHeader(view, offset) {
|
|
|
334
360
|
checkVersion(view.getUint32(offset + FILE_HEADER_OFF_VERSION, true));
|
|
335
361
|
const gridCount = view.getUint16(offset + FILE_HEADER_OFF_GRID_COUNT, true);
|
|
336
362
|
const codec = view.getUint16(offset + FILE_HEADER_OFF_CODEC, true);
|
|
337
|
-
if (codec
|
|
338
|
-
throw new
|
|
339
|
-
"
|
|
340
|
-
}
|
|
341
|
-
if (codec !== NvdbCodec.NONE && codec !== NvdbCodec.ZIP) {
|
|
342
|
-
throw new NvdbFormatError(`NvdbFile: unknown codec value ${codec} in FileHeader`);
|
|
363
|
+
if (codec !== NvdbCodec.NONE && codec !== NvdbCodec.ZIP && codec !== NvdbCodec.BLOSC) {
|
|
364
|
+
throw new NvdbFormatError(`NvdbFile: unknown codec value ${codec} in FileHeader (NanoVDB writes 0 NONE, 1 ZIP or 2 BLOSC; ` +
|
|
365
|
+
"`nanovdb_convert -z/--zip` or `-b/--blosc`).");
|
|
343
366
|
}
|
|
344
367
|
return { gridCount, codec: codec };
|
|
345
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* The most a Blosc1 frame from a NanoVDB or Warp writer can expand: LZ4 and BloscLZ add at most
|
|
371
|
+
* 255 output bytes per input byte (a run-length byte), so a grid larger than this many times the
|
|
372
|
+
* bytes left in the file can't be in it. Checked before the grid is allocated.
|
|
373
|
+
*/
|
|
374
|
+
export const BLOSC_MAX_EXPANSION = 256;
|
|
375
|
+
/**
|
|
376
|
+
* Largest stored size of a BLOSC chunk that decodes to at most `remaining` bytes: c-blosc stores a
|
|
377
|
+
* frame raw (memcpy'd, `nbytes` + 16 header bytes) when compressing would not fit in that, and
|
|
378
|
+
* every writer (`nanovdb_blosc_compress_ctx`, python-blosc) sizes the output so.
|
|
379
|
+
*/
|
|
380
|
+
export function bloscChunkBound(remaining) {
|
|
381
|
+
return remaining + BLOSC_HEADER_SIZE;
|
|
382
|
+
}
|
|
383
|
+
/** Checks a BLOSC chunk's u64 size prefix against what the grid still needs. */
|
|
384
|
+
export function checkBloscChunkSize(size, remaining, i, name) {
|
|
385
|
+
if (!Number.isSafeInteger(size) || size < BLOSC_HEADER_SIZE || size > bloscChunkBound(remaining)) {
|
|
386
|
+
throw new NvdbFormatError(`NvdbFile: BLOSC grid #${i} ("${name}") has a ${size}-byte chunk, but a chunk holds a ${BLOSC_HEADER_SIZE}-byte ` +
|
|
387
|
+
`Blosc header and at most ${bloscChunkBound(remaining)} bytes for the ${remaining} bytes the grid still needs.`);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/** Strips the class prefix from an inner tools error's message, to rethrow it in `.nvdb` terms. */
|
|
391
|
+
function innerMessage(err) {
|
|
392
|
+
return err.message.replace(/^@pmndrs\/vdb\/tools \[[A-Z_]+\]: (malformed \.vdb: |not supported: )?/, "");
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Decodes one BLOSC chunk (a whole Blosc1 frame) into the start of `dest` (the grid bytes still
|
|
396
|
+
* missing) and returns how many bytes it wrote. As NanoVDB (`count < 1` is a read error), an empty
|
|
397
|
+
* chunk is rejected; a frame claiming more than `dest` holds fails before decoding.
|
|
398
|
+
*/
|
|
399
|
+
export function decodeBloscChunk(frame, dest, i, name) {
|
|
400
|
+
let n;
|
|
401
|
+
try {
|
|
402
|
+
n = decompressBloscInto(frame, dest, frame.length);
|
|
403
|
+
}
|
|
404
|
+
catch (err) {
|
|
405
|
+
if (err instanceof VDBUnsupportedError) {
|
|
406
|
+
throw new VDBUnsupportedError(`NvdbFile: BLOSC grid #${i} ("${name}"): ${innerMessage(err)}`);
|
|
407
|
+
}
|
|
408
|
+
if (err instanceof VDBToolsError || err instanceof RangeError) {
|
|
409
|
+
throw new NvdbFormatError(`NvdbFile: BLOSC grid #${i} ("${name}"): ${innerMessage(err)}`);
|
|
410
|
+
}
|
|
411
|
+
throw err;
|
|
412
|
+
}
|
|
413
|
+
if (n < 1) {
|
|
414
|
+
throw new NvdbFormatError(`NvdbFile: BLOSC grid #${i} ("${name}") has a chunk that decodes to 0 bytes.`);
|
|
415
|
+
}
|
|
416
|
+
return n;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Reads a BLOSC grid's chunks from `src` at `offset` until they hold `gridSize` bytes; returns the
|
|
420
|
+
* image and the offset after its last chunk.
|
|
421
|
+
*/
|
|
422
|
+
function readBloscGrid(src, offset, gridSize, i, name) {
|
|
423
|
+
const available = src.length - offset;
|
|
424
|
+
if (gridSize > available * BLOSC_MAX_EXPANSION + 1024) {
|
|
425
|
+
throw new NvdbFormatError(`NvdbFile: BLOSC grid #${i} ("${name}") declares ${gridSize} bytes, but the ${available} bytes left in the file ` +
|
|
426
|
+
`can't decode to more than ${available * BLOSC_MAX_EXPANSION + 1024} (Blosc expands at most ${BLOSC_MAX_EXPANSION}:1).`);
|
|
427
|
+
}
|
|
428
|
+
const view = new DataView(src.buffer, src.byteOffset, src.byteLength);
|
|
429
|
+
const out = new Uint8Array(gridSize);
|
|
430
|
+
let filled = 0;
|
|
431
|
+
while (filled < gridSize) {
|
|
432
|
+
if (offset + 8 > src.length) {
|
|
433
|
+
throw new NvdbFormatError(`NvdbFile: truncated buffer while reading a BLOSC chunk size for grid #${i} ("${name}")`);
|
|
434
|
+
}
|
|
435
|
+
const size = Number(view.getBigUint64(offset, true));
|
|
436
|
+
offset += 8;
|
|
437
|
+
checkBloscChunkSize(size, gridSize - filled, i, name);
|
|
438
|
+
if (offset + size > src.length) {
|
|
439
|
+
throw new NvdbFormatError(`NvdbFile: truncated buffer while reading a ${size}-byte BLOSC chunk of grid #${i} ("${name}") ` +
|
|
440
|
+
`(${src.length - offset} bytes left)`);
|
|
441
|
+
}
|
|
442
|
+
filled += decodeBloscChunk(src.subarray(offset, offset + size), out.subarray(filled), i, name);
|
|
443
|
+
offset += size;
|
|
444
|
+
}
|
|
445
|
+
return { bytes: out, end: offset };
|
|
446
|
+
}
|
|
346
447
|
/**
|
|
347
448
|
* Inflates one ZIP grid payload into exactly `gridSize` bytes, bounded
|
|
348
449
|
* (Finding 2): a zip-bomb would otherwise inflate fully in memory before any
|
|
@@ -377,21 +478,48 @@ export function inflateZipGrid(compressed, gridSize, i, name) {
|
|
|
377
478
|
}
|
|
378
479
|
return decompressed;
|
|
379
480
|
}
|
|
481
|
+
/**
|
|
482
|
+
* NVIDIA Warp's `Volume.save_to_nvdb` leaves FileMetaData's `indexBBox` and `voxelCount` zero
|
|
483
|
+
* (and its `fileSize` excludes the codec's 8-byte size prefix). When both are zero, the image's
|
|
484
|
+
* own RootData bbox and TreeData voxel count stand in for them (K7.C; DIVERGES V69).
|
|
485
|
+
*/
|
|
486
|
+
function metadataFromImage(meta, gridBytes) {
|
|
487
|
+
const zeroBox = [...meta.indexBBox.min, ...meta.indexBBox.max].every((c) => c === 0);
|
|
488
|
+
if (!zeroBox || meta.voxelCount !== 0)
|
|
489
|
+
return meta;
|
|
490
|
+
const view = new DataView(gridBytes.buffer, gridBytes.byteOffset, gridBytes.byteLength);
|
|
491
|
+
const treeOffset = GRID_DATA_SIZE;
|
|
492
|
+
if (treeOffset + TREE_SIZE > gridBytes.byteLength)
|
|
493
|
+
return meta;
|
|
494
|
+
const rootOffset = treeOffset + Number(view.getBigUint64(treeOffset + TREE_OFF_NODE_OFFSET_ROOT, true));
|
|
495
|
+
if (!Number.isSafeInteger(rootOffset) || rootOffset + ROOT_BASE_SIZE > gridBytes.byteLength)
|
|
496
|
+
return meta;
|
|
497
|
+
const vec = (at) => [
|
|
498
|
+
view.getInt32(at, true),
|
|
499
|
+
view.getInt32(at + 4, true),
|
|
500
|
+
view.getInt32(at + 8, true),
|
|
501
|
+
];
|
|
502
|
+
return {
|
|
503
|
+
indexBBox: { min: vec(rootOffset + ROOT_OFF_BBOX_MIN), max: vec(rootOffset + ROOT_OFF_BBOX_MAX) },
|
|
504
|
+
voxelCount: Number(view.getBigUint64(treeOffset + TREE_OFF_VOXEL_COUNT, true)),
|
|
505
|
+
};
|
|
506
|
+
}
|
|
380
507
|
/** Runs the shared checks on a decoded grid image and builds its record. */
|
|
381
508
|
export function finishGridRecord(meta, name, i, gridBytes) {
|
|
382
509
|
checkInternalGridSize(gridBytes, meta.gridSize, i, name);
|
|
383
510
|
const gridType = gridTypeName(meta.gridTypeId);
|
|
384
511
|
const gridClass = gridClassName(meta.gridClassId);
|
|
385
512
|
validateGridType(gridType, name);
|
|
513
|
+
const { indexBBox, voxelCount } = metadataFromImage(meta, gridBytes);
|
|
386
514
|
return {
|
|
387
515
|
metadata: {
|
|
388
516
|
name,
|
|
389
517
|
gridType,
|
|
390
518
|
gridClass,
|
|
391
519
|
worldBBox: meta.worldBBox,
|
|
392
|
-
indexBBox
|
|
520
|
+
indexBBox,
|
|
393
521
|
voxelSize: meta.voxelSize,
|
|
394
|
-
voxelCount
|
|
522
|
+
voxelCount,
|
|
395
523
|
gridByteSize: meta.gridSize,
|
|
396
524
|
},
|
|
397
525
|
image: u32View(gridBytes),
|
|
@@ -439,6 +567,11 @@ function parseSegments(buffer) {
|
|
|
439
567
|
gridBytes = new Uint8Array(buffer, offset, meta.gridSize);
|
|
440
568
|
offset += meta.gridSize;
|
|
441
569
|
}
|
|
570
|
+
else if (codec === NvdbCodec.BLOSC) {
|
|
571
|
+
const { bytes, end } = readBloscGrid(new Uint8Array(buffer), offset, meta.gridSize, i, name);
|
|
572
|
+
gridBytes = bytes;
|
|
573
|
+
offset = end;
|
|
574
|
+
}
|
|
442
575
|
else {
|
|
443
576
|
// Codec.ZIP: 8-byte LE compressed-size prefix, then that many bytes of
|
|
444
577
|
// zlib (RFC 1950) compressed data (io::Internal::write/read, IO.h).
|
|
@@ -473,7 +606,16 @@ function parseRawGridBuffer(buffer) {
|
|
|
473
606
|
const gridCount = view.getUint32(offset + GRID_OFF_GRID_COUNT, true);
|
|
474
607
|
expectedCount ??= gridCount;
|
|
475
608
|
void view.getUint32(offset + GRID_OFF_GRID_INDEX, true); // mGridIndex, unused
|
|
609
|
+
// K7.C: the grid-size walk is NanoVDB's own (`GridHandle::read`), which sums and skips by
|
|
610
|
+
// mGridSize unchecked (the overflow class OpenVDB 13.2 fixed for segments). Each size must
|
|
611
|
+
// be a safe integer that holds at least GridData + TreeData and fits in the buffer, so the
|
|
612
|
+
// walk always moves forward and ends within the buffer.
|
|
476
613
|
const gridSize = Number(view.getBigUint64(offset + GRID_OFF_GRID_SIZE, true));
|
|
614
|
+
assertSafeGridSize(gridSize, `raw grid #${index}'s GridData.mGridSize`);
|
|
615
|
+
if (gridSize < GRID_DATA_SIZE + TREE_SIZE) {
|
|
616
|
+
throw new NvdbFormatError(`NvdbFile: raw grid #${index} declares mGridSize ${gridSize}, smaller than its ${GRID_DATA_SIZE + TREE_SIZE}-byte ` +
|
|
617
|
+
`GridData + TreeData headers; the buffer is corrupt.`);
|
|
618
|
+
}
|
|
477
619
|
requireBytes(buffer, offset + gridSize, `grid image for grid #${index}`);
|
|
478
620
|
const name = decodeCString(new Uint8Array(buffer, offset + GRID_OFF_GRID_NAME, GRID_NAME_MAX));
|
|
479
621
|
const gridTypeId = view.getUint32(offset + GRID_OFF_GRID_TYPE, true);
|
|
@@ -561,10 +703,19 @@ function sniffFormat(buffer) {
|
|
|
561
703
|
export class NvdbFile {
|
|
562
704
|
records;
|
|
563
705
|
sourceBuffer;
|
|
706
|
+
/**
|
|
707
|
+
* @param sourceBuffer The parsed file's bytes.
|
|
708
|
+
* @param records The parsed grid records.
|
|
709
|
+
*/
|
|
564
710
|
constructor(sourceBuffer, records) {
|
|
565
711
|
this.sourceBuffer = sourceBuffer;
|
|
566
712
|
this.records = records;
|
|
567
713
|
}
|
|
714
|
+
/**
|
|
715
|
+
* Fetches and parses a `.nvdb` file.
|
|
716
|
+
*
|
|
717
|
+
* @param url The file's URL; a non-OK response throws.
|
|
718
|
+
*/
|
|
568
719
|
static async fromURL(url) {
|
|
569
720
|
const response = await fetch(url);
|
|
570
721
|
if (!response.ok) {
|
|
@@ -573,11 +724,17 @@ export class NvdbFile {
|
|
|
573
724
|
const buffer = await response.arrayBuffer();
|
|
574
725
|
return NvdbFile.fromArrayBuffer(buffer);
|
|
575
726
|
}
|
|
727
|
+
/**
|
|
728
|
+
* Parses a `.nvdb` file (or raw grid buffer) already in memory.
|
|
729
|
+
*
|
|
730
|
+
* @param buffer The file's bytes; throws `NvdbFormatError` when malformed.
|
|
731
|
+
*/
|
|
576
732
|
static fromArrayBuffer(buffer) {
|
|
577
733
|
const format = sniffFormat(buffer);
|
|
578
734
|
const records = format === "segment" ? parseSegments(buffer) : parseRawGridBuffer(buffer);
|
|
579
735
|
return new NvdbFile(buffer, records);
|
|
580
736
|
}
|
|
737
|
+
/** The metadata of every grid in the file, in file order. */
|
|
581
738
|
get grids() {
|
|
582
739
|
return this.records.map((r) => r.metadata);
|
|
583
740
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nvdb-file.js","sourceRoot":"","sources":["../../src/tools/nvdb-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AAEH,OAAO,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IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,KAAK,CAAC;IAC9C,CAAC;IAED;;;;;;OAMG;IACH,mBAAmB,CAAC,CAAS;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,YAAY,CAAC;IACrF,CAAC;IAEO,SAAS,CAAC,CAAS,EAAE,MAAc;QACzC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,aAAa,CAAC,gBAAgB,EAAE,YAAY,MAAM,WAAW,CAAC,2BAA2B,IAAI,CAAC,OAAO,CAAC,MAAM,WAAW,CAAC,CAAC;QACrI,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["/**\n * `.nvdb` loader — Phase 1 (docs/archive/v1/PLAN.md), implementing the `NvdbFile`\n * contract from docs/archive/v1/SPEC.md §2.2: parse a `.nvdb` file (or a raw NanoVDB\n * grid buffer) into GPU-ready grid images — \"a valid NanoVDB grid image in\n * a flat u32 buffer\" (SPEC §1).\n *\n * Ground truth for every byte offset below is the C++ that wrote the test\n * fixtures:\n * - fixtures/downloads/openvdb-sparse/nanovdb/nanovdb/io/IO.h\n * (FileHeader/FileMetaData layout, Segment/Codec framing)\n * - fixtures/downloads/openvdb-sparse/nanovdb/nanovdb/NanoVDB.h\n * (magic numbers, Version packing, GridType/GridClass enums, GridData)\n * - vendor/stride-tables.json (extracted PNanoVDB.h defines: GridData,\n * TreeData and RootData offsets, ABI 32.9.1)\n *\n * ## `.nvdb` \"segment\" format (FileHeader magic `NanoVDB0`/`NanoVDB2`)\n *\n * FileHeader (16B), [FileMetaData (176B), gridName (nameSize B)] x gridCount,\n * [grid data (compressed per codec)] x gridCount\n *\n * A file is one or more such segments back to back (`io::Segment::write`\n * writes the header and every grid's metadata before the grids;\n * `writeGrids` writes one segment per GridHandle). With one grid per segment\n * the layout is FileHeader, FileMetaData, name, grid data.\n *\n * FileHeader (`struct FileHeader`, IO.h/NanoVDB.h, 16 bytes):\n *\n * field | offset | size | type\n * -----------|--------|------|------\n * magic | 0 | 8 | u64 (ASCII \"NanoVDB0\"/\"NanoVDB2\")\n * version | 8 | 4 | u32 (major<<21 | minor<<10 | patch)\n * gridCount | 12 | 2 | u16\n * codec | 14 | 2 | u16 (0=NONE, 1=ZIP, 2=BLOSC)\n *\n * FileMetaData (`struct FileMetaData`, NanoVDB.h, 176 bytes):\n *\n * field | offset | size | type\n * ----------------|--------|------|------\n * gridSize | 0 | 8 | u64 (decompressed grid image bytes)\n * fileSize | 8 | 8 | u64 (on-disk bytes incl. codec framing)\n * nameKey | 16 | 8 | u64 (io::stringHash(gridName))\n * voxelCount | 24 | 8 | u64 (active voxel count)\n * gridType | 32 | 4 | u32 (GridType enum)\n * gridClass | 36 | 4 | u32 (GridClass enum)\n * worldBBox.min | 40 | 24 | f64 x3\n * worldBBox.max | 64 | 24 | f64 x3\n * indexBBox.min | 88 | 12 | i32 x3\n * indexBBox.max | 100 | 12 | i32 x3\n * voxelSize | 112 | 24 | f64 x3\n * nameSize | 136 | 4 | u32 (grid name bytes, incl. NUL)\n * nodeCount[4] | 140 | 16 | u32 x4 (unused by this loader)\n * tileCount[3] | 156 | 12 | u32 x3 (unused by this loader)\n * codec | 168 | 2 | u16 (mirrors FileHeader.codec)\n * blindDataCount | 170 | 2 | u16 (unused by this loader)\n * version | 172 | 4 | u32\n * total: 176 bytes\n *\n * ## ZIP on-disk framing (`io::Internal::write`/`read`, IO.h)\n *\n * Per grid: an 8-byte little-endian u64 giving the *compressed* byte count,\n * followed by that many bytes of zlib-format (RFC 1950) compressed data —\n * i.e. exactly what C's `compress()`/`uncompress()` (and fflate's\n * `zlibSync`/`unzlibSync`) produce/consume. The decompressed length must\n * equal the grid's `gridSize` field. BLOSC uses the same 8-byte-prefixed\n * chunk framing but with blosc-compressed chunks; it is not implemented\n * (SPEC §7 non-goal) — callers get an actionable error instead.\n *\n * ## Raw grid buffer format (magic `NanoVDB1`, no FileHeader)\n *\n * The buffer starts directly with `GridData` (672 bytes, layout below, from\n * vendor/stride-tables.json), immediately followed by `TreeData` (64 bytes)\n * and then the rest of the tree. Multiple grids may be concatenated\n * (`GridData.mGridCount` grids total); each grid's byte length is its own\n * `mGridSize` field, so grids are found by walking `mGridSize` forward.\n * Raw buffers are always uncompressed.\n */\n\nimport { unzlibSync } from \"fflate\";\nimport { NvdbFormatError, VDBToolsError, VDBUnsupportedError } from \"./errors.js\";\n\nexport { NvdbFormatError } from \"./errors.js\";\n\n/** `.nvdb` FileHeader size in bytes (magic + version + grid count + codec). */\nexport const FILE_HEADER_SIZE = 16;\n\n/** Per-grid FileMetaData size in bytes (excluding the trailing grid name). */\nexport const FILE_METADATA_SIZE = 176;\n\n/** GridData block size in bytes (start of every NanoVDB grid image). */\nexport const GRID_DATA_SIZE = 672;\n\n/**\n * NanoVDB 8-byte magic strings: `NanoVDB0` = legacy file header / grid,\n * `NanoVDB1` = raw grid buffer, `NanoVDB2` = current file header. Sniffed\n * by `NvdbFile.fromArrayBuffer`.\n */\nexport const MAGIC_ASCII = [\"NanoVDB0\", \"NanoVDB1\", \"NanoVDB2\"] as const;\n\n/** File codecs we know about; v1 supports NONE and ZIP (fflate). */\nexport const NvdbCodec = {\n NONE: 0,\n ZIP: 1,\n BLOSC: 2,\n} as const;\nexport type NvdbCodec = (typeof NvdbCodec)[keyof typeof NvdbCodec];\n\n/** Grid types targeted for v1 (FogVolume rendering). */\nexport const NVDB_SUPPORTED_GRID_TYPES = [\"Float\", \"Fp4\", \"Fp8\", \"Fp16\", \"FpN\"] as const;\n\nexport interface NvdbGridMetadata {\n name: string;\n gridType: string;\n gridClass: string;\n worldBBox: { min: [number, number, number]; max: [number, number, number] };\n indexBBox: { min: [number, number, number]; max: [number, number, number] };\n voxelSize: [number, number, number];\n voxelCount: number;\n gridByteSize: number;\n}\n\n// ---------------------------------------------------------------------------\n// FileHeader / FileMetaData byte offsets (see module doc comment for the\n// full field table; these are the raw numbers used below).\n// ---------------------------------------------------------------------------\n\nconst FILE_HEADER_OFF_VERSION = 8;\nconst FILE_HEADER_OFF_GRID_COUNT = 12;\nconst FILE_HEADER_OFF_CODEC = 14;\n\nconst META_OFF_GRID_SIZE = 0;\nconst META_OFF_FILE_SIZE = 8;\nconst META_OFF_VOXEL_COUNT = 24;\nconst META_OFF_GRID_TYPE = 32;\nconst META_OFF_GRID_CLASS = 36;\nconst META_OFF_WORLD_BBOX_MIN = 40;\nconst META_OFF_WORLD_BBOX_MAX = 64;\nconst META_OFF_INDEX_BBOX_MIN = 88;\nconst META_OFF_INDEX_BBOX_MAX = 100;\nconst META_OFF_VOXEL_SIZE = 112;\nconst META_OFF_NAME_SIZE = 136;\n\n// ---------------------------------------------------------------------------\n// GridData / TreeData / RootData byte offsets, for the raw-grid-buffer path\n// (magic `NanoVDB1`). Values are the PNanoVDB.h defines baked into\n// vendor/stride-tables.json.\n// ---------------------------------------------------------------------------\n\nconst GRID_OFF_VERSION = 16;\nconst GRID_OFF_GRID_INDEX = 24;\nconst GRID_OFF_GRID_COUNT = 28;\nconst GRID_OFF_GRID_SIZE = 32;\nconst GRID_OFF_GRID_NAME = 40;\nconst GRID_NAME_MAX = 256; // GridData::MaxNameSize\nconst GRID_OFF_WORLD_BBOX = 560;\nconst GRID_OFF_VOXEL_SIZE = 608;\nconst GRID_OFF_GRID_CLASS = 632;\nconst GRID_OFF_GRID_TYPE = 636;\n\nconst TREE_SIZE = 64;\nconst TREE_OFF_NODE_OFFSET_ROOT = 24;\nconst TREE_OFF_VOXEL_COUNT = 56;\n\nconst ROOT_OFF_BBOX_MIN = 0;\nconst ROOT_OFF_BBOX_MAX = 12;\nconst ROOT_BASE_SIZE = 28;\n\n// ---------------------------------------------------------------------------\n// Small helpers\n// ---------------------------------------------------------------------------\n\nexport function requireBytes(buffer: ArrayBuffer, minLength: number, what: string): void {\n if (buffer.byteLength < minLength) {\n throw new NvdbFormatError(\n `NvdbFile: truncated buffer while reading ${what} ` +\n `(need ${minLength} bytes, buffer has ${buffer.byteLength})`,\n );\n }\n}\n\n/**\n * `gridSize` is read off a u64 (FileMetaData.gridSize / mGridSize); most of\n * the u64 range does not fit in a JS `number` without loss of precision. A\n * corrupt or malicious file can set that u64 to something outside\n * `Number.isSafeInteger` range, which would otherwise silently corrupt the\n * arithmetic used to slice/allocate the grid image (Finding 2). Guard it\n * before it's used for anything.\n */\nexport function assertSafeGridSize(gridSize: number, context: string): void {\n if (!Number.isSafeInteger(gridSize) || gridSize < 0) {\n throw new NvdbFormatError(\n `NvdbFile: ${context} has an unrepresentable gridSize (${gridSize}) — the on-disk u64 does not fit ` +\n `in a safe JS integer, so the file is corrupt or malicious.`,\n );\n }\n}\n\n/**\n * Cross-checks FileMetaData's declared `gridSize` (what the loader used to\n * slice/decompress the grid image) against the grid image's own internal\n * `GridData.mGridSize` (u64 at byte offset 32 of every grid image, see\n * NanoVDB.h). A file whose metadata lies (truncation, corruption, or a\n * malicious re-encode) would otherwise yield a silently short/long image and\n * silently wrong voxels downstream — Finding 1 from the T2 verification\n * pass. `gridBytes` must be at least `GRID_OFF_GRID_SIZE + 8` bytes for the\n * field to be readable; anything shorter is itself proof of a mismatch.\n */\nfunction checkInternalGridSize(gridBytes: Uint8Array, expectedGridSize: number, i: number, name: string): void {\n if (gridBytes.byteLength < GRID_OFF_GRID_SIZE + 8) {\n throw new NvdbFormatError(\n `NvdbFile: grid #${i} (\"${name}\") image is only ${gridBytes.byteLength} bytes — too short to contain ` +\n `a GridData header, so its internal mGridSize can't be verified against FileMetaData.gridSize ` +\n `(${expectedGridSize}). The file is corrupt or truncated.`,\n );\n }\n const view = new DataView(gridBytes.buffer, gridBytes.byteOffset, gridBytes.byteLength);\n const internalGridSize = Number(view.getBigUint64(GRID_OFF_GRID_SIZE, true));\n if (internalGridSize !== expectedGridSize) {\n throw new NvdbFormatError(\n `NvdbFile: grid #${i} (\"${name}\")'s FileMetaData.gridSize (${expectedGridSize}) does not match its ` +\n `own internal GridData.mGridSize (${internalGridSize}) — the file's metadata is inconsistent with its ` +\n `grid data (truncated or corrupted); refusing to load a possibly-wrong grid image.`,\n );\n }\n}\n\nexport function readMagic(buffer: ArrayBuffer, offset: number): string {\n const bytes = new Uint8Array(buffer, offset, 8);\n return String.fromCharCode(...bytes);\n}\n\nexport function decodeCString(bytes: Uint8Array): string {\n let end = bytes.indexOf(0);\n if (end < 0) end = bytes.length;\n return new TextDecoder().decode(bytes.subarray(0, end));\n}\n\n/** Packed NanoVDB `Version`: major<<21 | minor<<10 | patch. */\ninterface ParsedVersion {\n major: number;\n minor: number;\n patch: number;\n}\n\nfunction parseVersion(raw: number): ParsedVersion {\n return {\n major: (raw >>> 21) & 0x7ff,\n minor: (raw >>> 10) & 0x7ff,\n patch: raw & 0x3ff,\n };\n}\n\nfunction formatVersion(v: ParsedVersion): string {\n return `${v.major}.${v.minor}.${v.patch}`;\n}\n\n/** ABI major version this loader targets (vendor/stride-tables.json `$meta.abi` = \"32.9.1\"). */\nconst NANOVDB_MAJOR_VERSION = 32;\n\nexport function checkVersion(raw: number): ParsedVersion {\n const v = parseVersion(raw);\n if (v.major !== NANOVDB_MAJOR_VERSION) {\n throw new NvdbFormatError(\n `NvdbFile: incompatible NanoVDB version ${formatVersion(v)} ` +\n `(this loader targets NanoVDB ${NANOVDB_MAJOR_VERSION}.x). ` +\n `Re-export the file with a matching major version of NanoVDB.`,\n );\n }\n return v;\n}\n\n// GridType enum names (NanoVDB.h `enum class GridType`), indexed by id.\n// 21/22 are retired (IndexMask/OnIndexMask) and kept only as placeholders.\nconst GRID_TYPE_NAMES: readonly string[] = [\n \"Unknown\",\n \"Float\",\n \"Double\",\n \"Int16\",\n \"Int32\",\n \"Int64\",\n \"Vec3f\",\n \"Vec3d\",\n \"Mask\",\n \"Half\",\n \"UInt32\",\n \"Boolean\",\n \"RGBA8\",\n \"Fp4\",\n \"Fp8\",\n \"Fp16\",\n \"FpN\",\n \"Vec4f\",\n \"Vec4d\",\n \"Index\",\n \"OnIndex\",\n \"Retired21\",\n \"Retired22\",\n \"PointIndex\",\n \"Vec3u8\",\n \"Vec3u16\",\n \"UInt8\",\n \"End\",\n];\n\n// GridClass enum names (NanoVDB.h `enum class GridClass`), indexed by id.\nconst GRID_CLASS_NAMES: readonly string[] = [\n \"Unknown\",\n \"LevelSet\",\n \"FogVolume\",\n \"Staggered\",\n \"PointIndex\",\n \"PointData\",\n \"Topology\",\n \"VoxelVolume\",\n \"IndexGrid\",\n \"TensorGrid\",\n \"VoxelBVH\",\n \"End\",\n];\n\nexport function gridTypeName(id: number): string {\n return GRID_TYPE_NAMES[id] ?? `Unknown(${id})`;\n}\n\nexport function gridClassName(id: number): string {\n return GRID_CLASS_NAMES[id] ?? `Unknown(${id})`;\n}\n\nconst SUPPORTED_GRID_TYPES_SET: readonly string[] = NVDB_SUPPORTED_GRID_TYPES;\n\nexport function validateGridType(gridType: string, gridName: string): void {\n if (!SUPPORTED_GRID_TYPES_SET.includes(gridType)) {\n throw new VDBUnsupportedError(\n `NvdbFile: grid \"${gridName}\" is a ${gridType} grid, which this loader does not ` +\n `support — v1 only handles FogVolume grids of type ${NVDB_SUPPORTED_GRID_TYPES.join(\"/\")}. ` +\n `Re-export as float/fp4/fp8/fp16 (or fpn), e.g. \\`nanovdb_convert --fp8 in.vdb out.nvdb\\`.`,\n );\n }\n}\n\n/** Zero-copy u32 view when the input is already 4-byte aligned; a copy otherwise. */\nfunction u32View(bytes: Uint8Array): Uint32Array {\n if (bytes.byteOffset % 4 === 0 && bytes.byteLength % 4 === 0) {\n return new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);\n }\n const copy = bytes.slice(); // fresh ArrayBuffer, byteOffset 0\n return new Uint32Array(copy.buffer, copy.byteOffset, copy.byteLength / 4);\n}\n\nexport interface ParsedFileMetaData {\n gridSize: number;\n /** On-disk bytes of the grid's data including codec framing (FileMetaData.fileSize). */\n fileSize: number;\n voxelCount: number;\n gridTypeId: number;\n gridClassId: number;\n worldBBox: NvdbGridMetadata[\"worldBBox\"];\n indexBBox: NvdbGridMetadata[\"indexBBox\"];\n voxelSize: [number, number, number];\n nameSize: number;\n}\n\nexport function readFileMetaData(view: DataView, offset: number): ParsedFileMetaData {\n const gridSize = Number(view.getBigUint64(offset + META_OFF_GRID_SIZE, true));\n const fileSize = Number(view.getBigUint64(offset + META_OFF_FILE_SIZE, true));\n const voxelCount = Number(view.getBigUint64(offset + META_OFF_VOXEL_COUNT, true));\n const gridTypeId = view.getUint32(offset + META_OFF_GRID_TYPE, true);\n const gridClassId = view.getUint32(offset + META_OFF_GRID_CLASS, true);\n const worldBBox = {\n min: [\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN, true),\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN + 8, true),\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN + 16, true),\n ] as [number, number, number],\n max: [\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX, true),\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX + 8, true),\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX + 16, true),\n ] as [number, number, number],\n };\n const indexBBox = {\n min: [\n view.getInt32(offset + META_OFF_INDEX_BBOX_MIN, true),\n view.getInt32(offset + META_OFF_INDEX_BBOX_MIN + 4, true),\n view.getInt32(offset + META_OFF_INDEX_BBOX_MIN + 8, true),\n ] as [number, number, number],\n max: [\n view.getInt32(offset + META_OFF_INDEX_BBOX_MAX, true),\n view.getInt32(offset + META_OFF_INDEX_BBOX_MAX + 4, true),\n view.getInt32(offset + META_OFF_INDEX_BBOX_MAX + 8, true),\n ] as [number, number, number],\n };\n const voxelSize: [number, number, number] = [\n view.getFloat64(offset + META_OFF_VOXEL_SIZE, true),\n view.getFloat64(offset + META_OFF_VOXEL_SIZE + 8, true),\n view.getFloat64(offset + META_OFF_VOXEL_SIZE + 16, true),\n ];\n const nameSize = view.getUint32(offset + META_OFF_NAME_SIZE, true);\n return { gridSize, fileSize, voxelCount, gridTypeId, gridClassId, worldBBox, indexBBox, voxelSize, nameSize };\n}\n\nexport interface GridRecord {\n metadata: NvdbGridMetadata;\n image: Uint32Array;\n}\n\n// ---------------------------------------------------------------------------\n// Segment format: FileHeader + [FileMetaData, gridName] x N + [grid data] x N,\n// one or more segments per file (io::Segment, IO.h)\n// ---------------------------------------------------------------------------\n\n/** Native file magics a segment's FileHeader may carry. */\nexport function isFileHeaderMagic(magic: string): boolean {\n return magic === \"NanoVDB2\" || magic === \"NanoVDB0\";\n}\n\n/** Checks a FileHeader's version and codec; returns its grid count and codec. */\nexport function readFileHeader(view: DataView, offset: number): { gridCount: number; codec: NvdbCodec } {\n checkVersion(view.getUint32(offset + FILE_HEADER_OFF_VERSION, true));\n const gridCount = view.getUint16(offset + FILE_HEADER_OFF_GRID_COUNT, true);\n const codec = view.getUint16(offset + FILE_HEADER_OFF_CODEC, true);\n if (codec === NvdbCodec.BLOSC) {\n throw new VDBUnsupportedError(\n \"NvdbFile: this file uses the BLOSC codec, which is not supported in the browser. \" +\n \"Re-export it with codec NONE or ZIP (e.g. `nanovdb_convert --codec=zip`).\",\n );\n }\n if (codec !== NvdbCodec.NONE && codec !== NvdbCodec.ZIP) {\n throw new NvdbFormatError(`NvdbFile: unknown codec value ${codec} in FileHeader`);\n }\n return { gridCount, codec: codec as NvdbCodec };\n}\n\n/**\n * Inflates one ZIP grid payload into exactly `gridSize` bytes, bounded\n * (Finding 2): a zip-bomb would otherwise inflate fully in memory before any\n * size check runs. fflate's `out` option makes inflate() write into a fixed\n * buffer and *truncate* rather than grow past it, so the output is\n * allocated at gridSize + 1 bytes: a well-formed payload lands at exactly\n * `gridSize` bytes, an oversized one is clamped to gridSize + 1 and rejected.\n */\nexport function inflateZipGrid(compressed: Uint8Array, gridSize: number, i: number, name: string): Uint8Array {\n // Cap the declared size before allocating: deflate cannot expand more than 1032:1, so a gridSize beyond\n // that bound for this payload is a lie (a tiny file declaring a huge grid would otherwise allocate it).\n if (gridSize > compressed.byteLength * 1032 + 64) {\n throw new NvdbFormatError(\n `NvdbFile: ZIP grid #${i} (\"${name}\") declares ${gridSize} bytes but its ${compressed.byteLength}-byte payload ` +\n `cannot inflate to more than ${compressed.byteLength * 1032 + 64} (deflate expands at most 1032:1) — the file's metadata is untrustworthy.`,\n );\n }\n const outBound = new Uint8Array(gridSize + 1);\n let decompressed: Uint8Array;\n try {\n decompressed = unzlibSync(compressed, { out: outBound });\n } catch (err) {\n throw new NvdbFormatError(`NvdbFile: failed to inflate ZIP-compressed grid #${i} (\"${name}\"): ${(err as Error).message}`);\n }\n if (decompressed.byteLength === outBound.length) {\n throw new NvdbFormatError(\n `NvdbFile: ZIP-decompressed grid #${i} (\"${name}\") exceeds its declared gridSize of ` +\n `${gridSize} bytes (decompression is bounded to gridSize + 1 bytes to avoid unbounded memory ` +\n `use on a corrupt or malicious file) — the file's metadata is untrustworthy.`,\n );\n }\n if (decompressed.byteLength !== gridSize) {\n throw new NvdbFormatError(\n `NvdbFile: ZIP-decompressed grid #${i} (\"${name}\") is ${decompressed.byteLength} ` +\n `bytes, expected ${gridSize}`,\n );\n }\n return decompressed;\n}\n\n/** Runs the shared checks on a decoded grid image and builds its record. */\nexport function finishGridRecord(meta: ParsedFileMetaData, name: string, i: number, gridBytes: Uint8Array): GridRecord {\n checkInternalGridSize(gridBytes, meta.gridSize, i, name);\n const gridType = gridTypeName(meta.gridTypeId);\n const gridClass = gridClassName(meta.gridClassId);\n validateGridType(gridType, name);\n return {\n metadata: {\n name,\n gridType,\n gridClass,\n worldBBox: meta.worldBBox,\n indexBBox: meta.indexBBox,\n voxelSize: meta.voxelSize,\n voxelCount: meta.voxelCount,\n gridByteSize: meta.gridSize,\n },\n image: u32View(gridBytes),\n };\n}\n\n/**\n * A segment is a FileHeader, then every grid's FileMetaData + name, then every\n * grid's data in the same order (`Segment::write` writes the header and all\n * metadata, then `Internal::write` writes each grid). A file is one or more\n * segments back to back (`writeGrids` writes one per GridHandle); grids are\n * numbered across segments. With one grid per segment the layout is\n * FileHeader, FileMetaData, name, grid data.\n */\nfunction parseSegments(buffer: ArrayBuffer): GridRecord[] {\n const view = new DataView(buffer);\n const records: GridRecord[] = [];\n let offset = 0;\n\n do {\n requireBytes(buffer, offset + FILE_HEADER_SIZE, \"FileHeader\");\n if (offset > 0 && !isFileHeaderMagic(readMagic(buffer, offset))) {\n throw new NvdbFormatError(\n `NvdbFile: the ${buffer.byteLength - offset} bytes after byte ${offset} are not another segment ` +\n `(magic \"${readMagic(buffer, offset)}\"); the file is corrupt.`,\n );\n }\n const { gridCount, codec } = readFileHeader(view, offset);\n offset += FILE_HEADER_SIZE;\n\n const first = records.length;\n const metas: { meta: ParsedFileMetaData; name: string }[] = [];\n for (let k = 0; k < gridCount; k++) {\n const i = first + k;\n requireBytes(buffer, offset + FILE_METADATA_SIZE, `FileMetaData for grid #${i}`);\n const meta = readFileMetaData(view, offset);\n offset += FILE_METADATA_SIZE;\n requireBytes(buffer, offset + meta.nameSize, `grid name for grid #${i}`);\n const name = decodeCString(new Uint8Array(buffer, offset, meta.nameSize));\n offset += meta.nameSize;\n assertSafeGridSize(meta.gridSize, `grid #${i} (\"${name}\")'s FileMetaData.gridSize`);\n metas.push({ meta, name });\n }\n\n for (let k = 0; k < gridCount; k++) {\n const i = first + k;\n const { meta, name } = metas[k]!;\n let gridBytes: Uint8Array;\n if (codec === NvdbCodec.NONE) {\n requireBytes(buffer, offset + meta.gridSize, `grid data for grid #${i} (\"${name}\")`);\n gridBytes = new Uint8Array(buffer, offset, meta.gridSize);\n offset += meta.gridSize;\n } else {\n // Codec.ZIP: 8-byte LE compressed-size prefix, then that many bytes of\n // zlib (RFC 1950) compressed data (io::Internal::write/read, IO.h).\n requireBytes(buffer, offset + 8, `ZIP size prefix for grid #${i} (\"${name}\")`);\n const compressedSize = Number(view.getBigUint64(offset, true));\n offset += 8;\n requireBytes(buffer, offset + compressedSize, `ZIP payload for grid #${i} (\"${name}\")`);\n gridBytes = inflateZipGrid(new Uint8Array(buffer, offset, compressedSize), meta.gridSize, i, name);\n offset += compressedSize;\n }\n records.push(finishGridRecord(meta, name, i, gridBytes));\n }\n } while (offset < buffer.byteLength);\n\n return records;\n}\n\n// ---------------------------------------------------------------------------\n// Raw grid buffer format: GridData [+ TreeData + ...] x N, no FileHeader\n// ---------------------------------------------------------------------------\n\nfunction parseRawGridBuffer(buffer: ArrayBuffer): GridRecord[] {\n const view = new DataView(buffer);\n const records: GridRecord[] = [];\n\n let offset = 0;\n let index = 0;\n let expectedCount: number | undefined;\n\n while (offset < buffer.byteLength) {\n requireBytes(buffer, offset + GRID_DATA_SIZE, `GridData for grid #${index}`);\n const magic = readMagic(buffer, offset);\n if (magic !== \"NanoVDB1\" && magic !== \"NanoVDB0\") {\n throw new NvdbFormatError(`NvdbFile: expected a grid magic at byte ${offset}, found \"${magic}\"`);\n }\n checkVersion(view.getUint32(offset + GRID_OFF_VERSION, true));\n\n const gridCount = view.getUint32(offset + GRID_OFF_GRID_COUNT, true);\n expectedCount ??= gridCount;\n void view.getUint32(offset + GRID_OFF_GRID_INDEX, true); // mGridIndex, unused\n\n const gridSize = Number(view.getBigUint64(offset + GRID_OFF_GRID_SIZE, true));\n requireBytes(buffer, offset + gridSize, `grid image for grid #${index}`);\n\n const name = decodeCString(new Uint8Array(buffer, offset + GRID_OFF_GRID_NAME, GRID_NAME_MAX));\n\n const gridTypeId = view.getUint32(offset + GRID_OFF_GRID_TYPE, true);\n const gridClassId = view.getUint32(offset + GRID_OFF_GRID_CLASS, true);\n const worldBBox = {\n min: [\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX, true),\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 8, true),\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 16, true),\n ] as [number, number, number],\n max: [\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 24, true),\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 32, true),\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 40, true),\n ] as [number, number, number],\n };\n const voxelSize: [number, number, number] = [\n view.getFloat64(offset + GRID_OFF_VOXEL_SIZE, true),\n view.getFloat64(offset + GRID_OFF_VOXEL_SIZE + 8, true),\n view.getFloat64(offset + GRID_OFF_VOXEL_SIZE + 16, true),\n ];\n\n const treeOffset = offset + GRID_DATA_SIZE;\n requireBytes(buffer, treeOffset + TREE_SIZE, `TreeData for grid #${index}`);\n const voxelCount = Number(view.getBigUint64(treeOffset + TREE_OFF_VOXEL_COUNT, true));\n const nodeOffsetRoot = Number(view.getBigUint64(treeOffset + TREE_OFF_NODE_OFFSET_ROOT, true));\n const rootOffset = treeOffset + nodeOffsetRoot;\n requireBytes(buffer, rootOffset + ROOT_BASE_SIZE, `RootData bbox for grid #${index}`);\n const indexBBox = {\n min: [\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN, true),\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN + 4, true),\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN + 8, true),\n ] as [number, number, number],\n max: [\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX, true),\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX + 4, true),\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX + 8, true),\n ] as [number, number, number],\n };\n\n const gridType = gridTypeName(gridTypeId);\n const gridClass = gridClassName(gridClassId);\n validateGridType(gridType, name);\n\n const gridBytes = new Uint8Array(buffer, offset, gridSize);\n records.push({\n metadata: {\n name,\n gridType,\n gridClass,\n worldBBox,\n indexBBox,\n voxelSize,\n voxelCount,\n gridByteSize: gridSize,\n },\n image: u32View(gridBytes),\n });\n\n offset += gridSize;\n index += 1;\n if (expectedCount !== undefined && index >= expectedCount) break;\n }\n\n return records;\n}\n\n// ---------------------------------------------------------------------------\n// Top-level format sniff + public API\n// ---------------------------------------------------------------------------\n\nfunction sniffFormat(buffer: ArrayBuffer): \"segment\" | \"raw\" {\n requireBytes(buffer, 8, \"the NanoVDB magic\");\n const magic = readMagic(buffer, 0);\n // \"NanoVDB0\" is genuinely ambiguous pre-v32.6 (used for both FileHeader and\n // raw GridData); we treat it as a (legacy) FileHeader, matching the plain\n // reading \"legacy files use NanoVDB0\" — none of our fixtures exercise this.\n if (magic === \"NanoVDB2\" || magic === \"NanoVDB0\") return \"segment\";\n if (magic === \"NanoVDB1\") return \"raw\";\n throw new NvdbFormatError(\n `NvdbFile: unrecognized magic \"${magic}\" at byte 0 (expected one of ` +\n `${MAGIC_ASCII.join(\", \")}) — this does not look like a NanoVDB file.`,\n );\n}\n\n/**\n * Parses a `.nvdb` file (or raw grid buffer) and exposes GPU-ready grid\n * images as flat u32 views — \"a valid NanoVDB grid image in a flat u32\n * buffer\" is the single contract between the CPU and GPU halves (SPEC §1).\n */\nexport class NvdbFile {\n private readonly records: readonly GridRecord[];\n private readonly sourceBuffer: ArrayBuffer;\n\n private constructor(sourceBuffer: ArrayBuffer, records: readonly GridRecord[]) {\n this.sourceBuffer = sourceBuffer;\n this.records = records;\n }\n\n static async fromURL(url: string | URL): Promise<NvdbFile> {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(\n `NvdbFile.fromURL: failed to fetch ${String(url)} (${response.status} ${response.statusText})`,\n );\n }\n const buffer = await response.arrayBuffer();\n return NvdbFile.fromArrayBuffer(buffer);\n }\n\n static fromArrayBuffer(buffer: ArrayBuffer): NvdbFile {\n const format = sniffFormat(buffer);\n const records = format === \"segment\" ? parseSegments(buffer) : parseRawGridBuffer(buffer);\n return new NvdbFile(buffer, records);\n }\n\n get grids(): readonly NvdbGridMetadata[] {\n return this.records.map((r) => r.metadata);\n }\n\n /** Zero-copy u32 view of grid `i`'s image where the codec/alignment allows it. */\n gridImage(i: number): Uint32Array {\n return this.getRecord(i, \"gridImage\").image;\n }\n\n /**\n * True when `gridImage(i)` is a zero-copy view into the buffer originally\n * passed to `fromArrayBuffer`/`fromURL`. False when a copy was required —\n * either ZIP decompression, or a codec-NONE grid segment that landed on a\n * non-4-byte-aligned offset (grid data follows a variable-length name, so\n * alignment isn't guaranteed).\n */\n isGridImageZeroCopy(i: number): boolean {\n return this.getRecord(i, \"isGridImageZeroCopy\").image.buffer === this.sourceBuffer;\n }\n\n private getRecord(i: number, caller: string): GridRecord {\n const record = this.records[i];\n if (!record) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `NvdbFile.${caller}: index ${i} out of range (file has ${this.records.length} grid(s))`);\n }\n return record;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"nvdb-file.js","sourceRoot":"","sources":["../../src/tools/nvdb-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkFG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAEtC,wEAAwE;AACxE,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAU,CAAC;AAEzE,kGAAkG;AAClG,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,KAAK,EAAE,CAAC;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;IAClF,SAAS,CAAC,CAAS;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,KAAK,CAAC;IAC9C,CAAC;IAED;;;;;;OAMG;IACH,mBAAmB,CAAC,CAAS;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,YAAY,CAAC;IACrF,CAAC;IAEO,SAAS,CAAC,CAAS,EAAE,MAAc;QACzC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,aAAa,CAAC,gBAAgB,EAAE,YAAY,MAAM,WAAW,CAAC,2BAA2B,IAAI,CAAC,OAAO,CAAC,MAAM,WAAW,CAAC,CAAC;QACrI,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["/**\n * `.nvdb` loader — Phase 1 (docs/archive/v1/PLAN.md), implementing the `NvdbFile`\n * contract from docs/archive/v1/SPEC.md §2.2: parse a `.nvdb` file (or a raw NanoVDB\n * grid buffer) into GPU-ready grid images — \"a valid NanoVDB grid image in\n * a flat u32 buffer\" (SPEC §1).\n *\n * Ground truth for every byte offset below is the C++ that wrote the test\n * fixtures:\n * - fixtures/downloads/openvdb-sparse/nanovdb/nanovdb/io/IO.h\n * (FileHeader/FileMetaData layout, Segment/Codec framing)\n * - fixtures/downloads/openvdb-sparse/nanovdb/nanovdb/NanoVDB.h\n * (magic numbers, Version packing, GridType/GridClass enums, GridData)\n * - vendor/stride-tables.json (extracted PNanoVDB.h defines: GridData,\n * TreeData and RootData offsets, ABI 32.11.0; unchanged since 32.9.1)\n *\n * ## `.nvdb` \"segment\" format (FileHeader magic `NanoVDB0`/`NanoVDB2`)\n *\n * FileHeader (16B), [FileMetaData (176B), gridName (nameSize B)] x gridCount,\n * [grid data (compressed per codec)] x gridCount\n *\n * A file is one or more such segments back to back (`io::Segment::write`\n * writes the header and every grid's metadata before the grids;\n * `writeGrids` writes one segment per GridHandle). With one grid per segment\n * the layout is FileHeader, FileMetaData, name, grid data.\n *\n * FileHeader (`struct FileHeader`, IO.h/NanoVDB.h, 16 bytes):\n *\n * field | offset | size | type\n * -----------|--------|------|------\n * magic | 0 | 8 | u64 (ASCII \"NanoVDB0\"/\"NanoVDB2\")\n * version | 8 | 4 | u32 (major<<21 | minor<<10 | patch)\n * gridCount | 12 | 2 | u16\n * codec | 14 | 2 | u16 (0=NONE, 1=ZIP, 2=BLOSC)\n *\n * FileMetaData (`struct FileMetaData`, NanoVDB.h, 176 bytes):\n *\n * field | offset | size | type\n * ----------------|--------|------|------\n * gridSize | 0 | 8 | u64 (decompressed grid image bytes)\n * fileSize | 8 | 8 | u64 (on-disk bytes incl. codec framing)\n * nameKey | 16 | 8 | u64 (io::stringHash(gridName))\n * voxelCount | 24 | 8 | u64 (active voxel count)\n * gridType | 32 | 4 | u32 (GridType enum)\n * gridClass | 36 | 4 | u32 (GridClass enum)\n * worldBBox.min | 40 | 24 | f64 x3\n * worldBBox.max | 64 | 24 | f64 x3\n * indexBBox.min | 88 | 12 | i32 x3\n * indexBBox.max | 100 | 12 | i32 x3\n * voxelSize | 112 | 24 | f64 x3\n * nameSize | 136 | 4 | u32 (grid name bytes, incl. NUL)\n * nodeCount[4] | 140 | 16 | u32 x4 (unused by this loader)\n * tileCount[3] | 156 | 12 | u32 x3 (unused by this loader)\n * codec | 168 | 2 | u16 (mirrors FileHeader.codec)\n * blindDataCount | 170 | 2 | u16 (unused by this loader)\n * version | 172 | 4 | u32\n * total: 176 bytes\n *\n * ## ZIP on-disk framing (`io::Internal::write`/`read`, IO.h)\n *\n * Per grid: an 8-byte little-endian u64 giving the *compressed* byte count,\n * followed by that many bytes of zlib-format (RFC 1950) compressed data —\n * i.e. exactly what C's `compress()`/`uncompress()` (and fflate's\n * `zlibSync`/`unzlibSync`) produce/consume. The decompressed length must\n * equal the grid's `gridSize` field.\n *\n * ## BLOSC on-disk framing (K7.C; `io::Internal::write`/`read`, IO.h @ v14.0.0)\n *\n * Per grid: one or more chunks, each an 8-byte LE u64 compressed size and one\n * Blosc1 frame, until the frames' uncompressed bytes add up to `gridSize`.\n * NanoVDB splits at 1 GiB (`MAX_SIZE`) and writes LZ4 frames (byte shuffle,\n * typesize 4, 256 KiB blocks); NVIDIA Warp writes one BloscLZ frame per grid\n * (python-blosc defaults), which NanoVDB 14 reads too. We accept any chunking\n * whose sizes add up (DIVERGES V69). Frames decode with `tools/vdb/blosc.ts`.\n *\n * ## Raw grid buffer format (magic `NanoVDB1`, no FileHeader)\n *\n * The buffer starts directly with `GridData` (672 bytes, layout below, from\n * vendor/stride-tables.json), immediately followed by `TreeData` (64 bytes)\n * and then the rest of the tree. Multiple grids may be concatenated\n * (`GridData.mGridCount` grids total); each grid's byte length is its own\n * `mGridSize` field, so grids are found by walking `mGridSize` forward.\n * Raw buffers are always uncompressed.\n */\n\nimport { unzlibSync } from \"fflate\";\nimport { NvdbFormatError, VDBToolsError, VDBUnsupportedError } from \"./errors.js\";\nimport { BLOSC_HEADER_SIZE, decompressBloscInto } from \"./vdb/blosc.js\";\n\nexport { NvdbFormatError } from \"./errors.js\";\n\n/** `.nvdb` FileHeader size in bytes (magic + version + grid count + codec). */\nexport const FILE_HEADER_SIZE = 16;\n\n/** Per-grid FileMetaData size in bytes (excluding the trailing grid name). */\nexport const FILE_METADATA_SIZE = 176;\n\n/** GridData block size in bytes (start of every NanoVDB grid image). */\nexport const GRID_DATA_SIZE = 672;\n\n/**\n * NanoVDB 8-byte magic strings: `NanoVDB0` = legacy file header / grid,\n * `NanoVDB1` = raw grid buffer, `NanoVDB2` = current file header. Sniffed\n * by `NvdbFile.fromArrayBuffer`.\n */\nexport const MAGIC_ASCII = [\"NanoVDB0\", \"NanoVDB1\", \"NanoVDB2\"] as const;\n\n/** `.nvdb` file codecs: all three are read (ZIP through fflate, BLOSC LZ4/BloscLZ since K7.C). */\nexport const NvdbCodec = {\n NONE: 0,\n ZIP: 1,\n BLOSC: 2,\n} as const;\nexport type NvdbCodec = (typeof NvdbCodec)[keyof typeof NvdbCodec];\n\n/** Grid types targeted for v1 (FogVolume rendering); Half (NanoVDB 13.2 raw binary16) since K7.H. */\nexport const NVDB_SUPPORTED_GRID_TYPES = [\"Float\", \"Fp4\", \"Fp8\", \"Fp16\", \"FpN\", \"Half\"] as const;\n\n/**\n * The pool / WGSL module type name of a `.nvdb` grid type (P1.17): the file's metadata spells NanoVDB's\n * `GridType` names (`'Float'`, `'Fp8'`, `'FpN'`, `'Half'`), a `VDBGridPool`, `vdbModuleWgsl({ types })` and\n * `vdbQuantize` take them in lower case (`'float'`, `'fp8'`, `'fpn'`, `'half'`).\n *\n * @param gridType A grid's metadata, or its `gridType` string.\n * @returns The lower-case name, or `null` for a type the pool does not hold (`'Vec3f'`, `'Double'`, ...).\n */\nexport function nvdbPoolType(gridType: string | { gridType: string }): \"float\" | \"fp4\" | \"fp8\" | \"fp16\" | \"fpn\" | \"half\" | null {\n const name = typeof gridType === \"string\" ? gridType : gridType.gridType;\n return SUPPORTED_GRID_TYPES_SET.includes(name) ? (name.toLowerCase() as \"float\" | \"fp4\" | \"fp8\" | \"fp16\" | \"fpn\" | \"half\") : null;\n}\n\n/** What a `.nvdb` file's metadata says about one grid. */\nexport interface NvdbGridMetadata {\n /** The grid's name: what the builders call `gridName` (`vdbBuildFromDense({ gridName })`, `VDBBuiltGrid.gridName`). */\n name: string;\n /**\n * Grid value type, spelled as NanoVDB's `GridType` (`'Float'`, `'Fp8'`, `'FpN'`, `'Half'`, ...). Pools and WGSL\n * modules take the lower-case names (`'float'`, `'fp8'`, ...): {@link nvdbPoolType} converts.\n */\n gridType: string;\n /** Grid class name (`'FogVolume'`, `'LevelSet'`, ...). */\n gridClass: string;\n /** World-space box (its max is one voxel beyond the max voxel's centre). */\n worldBBox: { min: [number, number, number]; max: [number, number, number] };\n /** Inclusive index-space box of the active voxels. */\n indexBBox: { min: [number, number, number]; max: [number, number, number] };\n /** Voxel size per axis, in world units. */\n voxelSize: [number, number, number];\n /** Active voxel count. */\n voxelCount: number;\n /** Size of the decoded grid image in bytes. */\n gridByteSize: number;\n}\n\n// ---------------------------------------------------------------------------\n// FileHeader / FileMetaData byte offsets (see module doc comment for the\n// full field table; these are the raw numbers used below).\n// ---------------------------------------------------------------------------\n\nconst FILE_HEADER_OFF_VERSION = 8;\nconst FILE_HEADER_OFF_GRID_COUNT = 12;\nconst FILE_HEADER_OFF_CODEC = 14;\n\nconst META_OFF_GRID_SIZE = 0;\nconst META_OFF_FILE_SIZE = 8;\nconst META_OFF_VOXEL_COUNT = 24;\nconst META_OFF_GRID_TYPE = 32;\nconst META_OFF_GRID_CLASS = 36;\nconst META_OFF_WORLD_BBOX_MIN = 40;\nconst META_OFF_WORLD_BBOX_MAX = 64;\nconst META_OFF_INDEX_BBOX_MIN = 88;\nconst META_OFF_INDEX_BBOX_MAX = 100;\nconst META_OFF_VOXEL_SIZE = 112;\nconst META_OFF_NAME_SIZE = 136;\n\n// ---------------------------------------------------------------------------\n// GridData / TreeData / RootData byte offsets, for the raw-grid-buffer path\n// (magic `NanoVDB1`). Values are the PNanoVDB.h defines baked into\n// vendor/stride-tables.json.\n// ---------------------------------------------------------------------------\n\nconst GRID_OFF_VERSION = 16;\nconst GRID_OFF_GRID_INDEX = 24;\nconst GRID_OFF_GRID_COUNT = 28;\nconst GRID_OFF_GRID_SIZE = 32;\nconst GRID_OFF_GRID_NAME = 40;\nconst GRID_NAME_MAX = 256; // GridData::MaxNameSize\nconst GRID_OFF_WORLD_BBOX = 560;\nconst GRID_OFF_VOXEL_SIZE = 608;\nconst GRID_OFF_GRID_CLASS = 632;\nconst GRID_OFF_GRID_TYPE = 636;\n\nconst TREE_SIZE = 64;\nconst TREE_OFF_NODE_OFFSET_ROOT = 24;\nconst TREE_OFF_VOXEL_COUNT = 56;\n\nconst ROOT_OFF_BBOX_MIN = 0;\nconst ROOT_OFF_BBOX_MAX = 12;\nconst ROOT_BASE_SIZE = 28;\n\n// ---------------------------------------------------------------------------\n// Small helpers\n// ---------------------------------------------------------------------------\n\nexport function requireBytes(buffer: ArrayBuffer, minLength: number, what: string): void {\n if (buffer.byteLength < minLength) {\n throw new NvdbFormatError(\n `NvdbFile: truncated buffer while reading ${what} ` +\n `(need ${minLength} bytes, buffer has ${buffer.byteLength})`,\n );\n }\n}\n\n/**\n * `gridSize` is read off a u64 (FileMetaData.gridSize / mGridSize); most of\n * the u64 range does not fit in a JS `number` without loss of precision. A\n * corrupt or malicious file can set that u64 to something outside\n * `Number.isSafeInteger` range, which would otherwise silently corrupt the\n * arithmetic used to slice/allocate the grid image (Finding 2). Guard it\n * before it's used for anything.\n */\nexport function assertSafeGridSize(gridSize: number, context: string): void {\n if (!Number.isSafeInteger(gridSize) || gridSize < 0) {\n throw new NvdbFormatError(\n `NvdbFile: ${context} has an unrepresentable gridSize (${gridSize}) — the on-disk u64 does not fit ` +\n `in a safe JS integer, so the file is corrupt or malicious.`,\n );\n }\n}\n\n/**\n * Cross-checks FileMetaData's declared `gridSize` (what the loader used to\n * slice/decompress the grid image) against the grid image's own internal\n * `GridData.mGridSize` (u64 at byte offset 32 of every grid image, see\n * NanoVDB.h). A file whose metadata lies (truncation, corruption, or a\n * malicious re-encode) would otherwise yield a silently short/long image and\n * silently wrong voxels downstream — Finding 1 from the T2 verification\n * pass. `gridBytes` must be at least `GRID_OFF_GRID_SIZE + 8` bytes for the\n * field to be readable; anything shorter is itself proof of a mismatch.\n */\nfunction checkInternalGridSize(gridBytes: Uint8Array, expectedGridSize: number, i: number, name: string): void {\n if (gridBytes.byteLength < GRID_OFF_GRID_SIZE + 8) {\n throw new NvdbFormatError(\n `NvdbFile: grid #${i} (\"${name}\") image is only ${gridBytes.byteLength} bytes — too short to contain ` +\n `a GridData header, so its internal mGridSize can't be verified against FileMetaData.gridSize ` +\n `(${expectedGridSize}). The file is corrupt or truncated.`,\n );\n }\n const view = new DataView(gridBytes.buffer, gridBytes.byteOffset, gridBytes.byteLength);\n const internalGridSize = Number(view.getBigUint64(GRID_OFF_GRID_SIZE, true));\n if (internalGridSize !== expectedGridSize) {\n throw new NvdbFormatError(\n `NvdbFile: grid #${i} (\"${name}\")'s FileMetaData.gridSize (${expectedGridSize}) does not match its ` +\n `own internal GridData.mGridSize (${internalGridSize}) — the file's metadata is inconsistent with its ` +\n `grid data (truncated or corrupted); refusing to load a possibly-wrong grid image.`,\n );\n }\n}\n\nexport function readMagic(buffer: ArrayBuffer, offset: number): string {\n const bytes = new Uint8Array(buffer, offset, 8);\n return String.fromCharCode(...bytes);\n}\n\nexport function decodeCString(bytes: Uint8Array): string {\n let end = bytes.indexOf(0);\n if (end < 0) end = bytes.length;\n return new TextDecoder().decode(bytes.subarray(0, end));\n}\n\n/** Packed NanoVDB `Version`: major<<21 | minor<<10 | patch. */\ninterface ParsedVersion {\n major: number;\n minor: number;\n patch: number;\n}\n\nfunction parseVersion(raw: number): ParsedVersion {\n return {\n major: (raw >>> 21) & 0x7ff,\n minor: (raw >>> 10) & 0x7ff,\n patch: raw & 0x3ff,\n };\n}\n\nfunction formatVersion(v: ParsedVersion): string {\n return `${v.major}.${v.minor}.${v.patch}`;\n}\n\n/** ABI major version this loader targets (vendor/stride-tables.json `$meta.abi` = \"32.11.0\"). */\nconst NANOVDB_MAJOR_VERSION = 32;\n\n/**\n * NanoVDB's own rule (`Version::isCompatible`): only the major version must match; a minor\n * version bump keeps the grid layout (NanoVDB 32.11 of OpenVDB v14 included). A different\n * major is a layout this loader can't read, so it fails before any field is trusted (K7.C).\n */\nexport function checkVersion(raw: number): ParsedVersion {\n const v = parseVersion(raw);\n if (v.major !== NANOVDB_MAJOR_VERSION) {\n const when = v.major > NANOVDB_MAJOR_VERSION ? \"a newer\" : \"an older\";\n throw new VDBUnsupportedError(\n `NvdbFile: incompatible NanoVDB version ${formatVersion(v)}, written by ${when} NanoVDB ` +\n `(this loader reads NanoVDB ${NANOVDB_MAJOR_VERSION}.x, the grid ABI of OpenVDB 10 to 14). ` +\n `Re-export the file with a NanoVDB whose major version is ${NANOVDB_MAJOR_VERSION}.`,\n );\n }\n return v;\n}\n\n// GridType enum names (NanoVDB.h `enum class GridType`), indexed by id.\n// 21/22 are retired (IndexMask/OnIndexMask) and kept only as placeholders.\nconst GRID_TYPE_NAMES: readonly string[] = [\n \"Unknown\",\n \"Float\",\n \"Double\",\n \"Int16\",\n \"Int32\",\n \"Int64\",\n \"Vec3f\",\n \"Vec3d\",\n \"Mask\",\n \"Half\",\n \"UInt32\",\n \"Boolean\",\n \"RGBA8\",\n \"Fp4\",\n \"Fp8\",\n \"Fp16\",\n \"FpN\",\n \"Vec4f\",\n \"Vec4d\",\n \"Index\",\n \"OnIndex\",\n \"Retired21\",\n \"Retired22\",\n \"PointIndex\",\n \"Vec3u8\",\n \"Vec3u16\",\n \"UInt8\",\n \"End\",\n];\n\n// GridClass enum names (NanoVDB.h `enum class GridClass`), indexed by id.\nconst GRID_CLASS_NAMES: readonly string[] = [\n \"Unknown\",\n \"LevelSet\",\n \"FogVolume\",\n \"Staggered\",\n \"PointIndex\",\n \"PointData\",\n \"Topology\",\n \"VoxelVolume\",\n \"IndexGrid\",\n \"TensorGrid\",\n \"VoxelBVH\",\n \"End\",\n];\n\nexport function gridTypeName(id: number): string {\n return GRID_TYPE_NAMES[id] ?? `Unknown(${id})`;\n}\n\nexport function gridClassName(id: number): string {\n return GRID_CLASS_NAMES[id] ?? `Unknown(${id})`;\n}\n\nconst SUPPORTED_GRID_TYPES_SET: readonly string[] = NVDB_SUPPORTED_GRID_TYPES;\n\nexport function validateGridType(gridType: string, gridName: string): void {\n if (!SUPPORTED_GRID_TYPES_SET.includes(gridType)) {\n throw new VDBUnsupportedError(\n `NvdbFile: grid \"${gridName}\" is a ${gridType} grid, which this loader does not ` +\n `support — v1 only handles FogVolume grids of type ${NVDB_SUPPORTED_GRID_TYPES.join(\"/\")}. ` +\n `Re-export as float/fp4/fp8/fp16/fpn/half, e.g. \\`nanovdb_convert --fp8 in.vdb out.nvdb\\`.`,\n );\n }\n}\n\n/** Zero-copy u32 view when the input is already 4-byte aligned; a copy otherwise. */\nfunction u32View(bytes: Uint8Array): Uint32Array {\n if (bytes.byteOffset % 4 === 0 && bytes.byteLength % 4 === 0) {\n return new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);\n }\n const copy = bytes.slice(); // fresh ArrayBuffer, byteOffset 0\n return new Uint32Array(copy.buffer, copy.byteOffset, copy.byteLength / 4);\n}\n\nexport interface ParsedFileMetaData {\n gridSize: number;\n /** On-disk bytes of the grid's data including codec framing (FileMetaData.fileSize). */\n fileSize: number;\n voxelCount: number;\n gridTypeId: number;\n gridClassId: number;\n worldBBox: NvdbGridMetadata[\"worldBBox\"];\n indexBBox: NvdbGridMetadata[\"indexBBox\"];\n voxelSize: [number, number, number];\n nameSize: number;\n}\n\nexport function readFileMetaData(view: DataView, offset: number): ParsedFileMetaData {\n const gridSize = Number(view.getBigUint64(offset + META_OFF_GRID_SIZE, true));\n const fileSize = Number(view.getBigUint64(offset + META_OFF_FILE_SIZE, true));\n const voxelCount = Number(view.getBigUint64(offset + META_OFF_VOXEL_COUNT, true));\n const gridTypeId = view.getUint32(offset + META_OFF_GRID_TYPE, true);\n const gridClassId = view.getUint32(offset + META_OFF_GRID_CLASS, true);\n const worldBBox = {\n min: [\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN, true),\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN + 8, true),\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN + 16, true),\n ] as [number, number, number],\n max: [\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX, true),\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX + 8, true),\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX + 16, true),\n ] as [number, number, number],\n };\n const indexBBox = {\n min: [\n view.getInt32(offset + META_OFF_INDEX_BBOX_MIN, true),\n view.getInt32(offset + META_OFF_INDEX_BBOX_MIN + 4, true),\n view.getInt32(offset + META_OFF_INDEX_BBOX_MIN + 8, true),\n ] as [number, number, number],\n max: [\n view.getInt32(offset + META_OFF_INDEX_BBOX_MAX, true),\n view.getInt32(offset + META_OFF_INDEX_BBOX_MAX + 4, true),\n view.getInt32(offset + META_OFF_INDEX_BBOX_MAX + 8, true),\n ] as [number, number, number],\n };\n const voxelSize: [number, number, number] = [\n view.getFloat64(offset + META_OFF_VOXEL_SIZE, true),\n view.getFloat64(offset + META_OFF_VOXEL_SIZE + 8, true),\n view.getFloat64(offset + META_OFF_VOXEL_SIZE + 16, true),\n ];\n const nameSize = view.getUint32(offset + META_OFF_NAME_SIZE, true);\n return { gridSize, fileSize, voxelCount, gridTypeId, gridClassId, worldBBox, indexBBox, voxelSize, nameSize };\n}\n\nexport interface GridRecord {\n metadata: NvdbGridMetadata;\n image: Uint32Array;\n}\n\n// ---------------------------------------------------------------------------\n// Segment format: FileHeader + [FileMetaData, gridName] x N + [grid data] x N,\n// one or more segments per file (io::Segment, IO.h)\n// ---------------------------------------------------------------------------\n\n/** Native file magics a segment's FileHeader may carry. */\nexport function isFileHeaderMagic(magic: string): boolean {\n return magic === \"NanoVDB2\" || magic === \"NanoVDB0\";\n}\n\n/** Checks a FileHeader's version and codec; returns its grid count and codec. */\nexport function readFileHeader(view: DataView, offset: number): { gridCount: number; codec: NvdbCodec } {\n checkVersion(view.getUint32(offset + FILE_HEADER_OFF_VERSION, true));\n const gridCount = view.getUint16(offset + FILE_HEADER_OFF_GRID_COUNT, true);\n const codec = view.getUint16(offset + FILE_HEADER_OFF_CODEC, true);\n if (codec !== NvdbCodec.NONE && codec !== NvdbCodec.ZIP && codec !== NvdbCodec.BLOSC) {\n throw new NvdbFormatError(\n `NvdbFile: unknown codec value ${codec} in FileHeader (NanoVDB writes 0 NONE, 1 ZIP or 2 BLOSC; ` +\n \"`nanovdb_convert -z/--zip` or `-b/--blosc`).\",\n );\n }\n return { gridCount, codec: codec as NvdbCodec };\n}\n\n/**\n * The most a Blosc1 frame from a NanoVDB or Warp writer can expand: LZ4 and BloscLZ add at most\n * 255 output bytes per input byte (a run-length byte), so a grid larger than this many times the\n * bytes left in the file can't be in it. Checked before the grid is allocated.\n */\nexport const BLOSC_MAX_EXPANSION = 256;\n\n/**\n * Largest stored size of a BLOSC chunk that decodes to at most `remaining` bytes: c-blosc stores a\n * frame raw (memcpy'd, `nbytes` + 16 header bytes) when compressing would not fit in that, and\n * every writer (`nanovdb_blosc_compress_ctx`, python-blosc) sizes the output so.\n */\nexport function bloscChunkBound(remaining: number): number {\n return remaining + BLOSC_HEADER_SIZE;\n}\n\n/** Checks a BLOSC chunk's u64 size prefix against what the grid still needs. */\nexport function checkBloscChunkSize(size: number, remaining: number, i: number, name: string): void {\n if (!Number.isSafeInteger(size) || size < BLOSC_HEADER_SIZE || size > bloscChunkBound(remaining)) {\n throw new NvdbFormatError(\n `NvdbFile: BLOSC grid #${i} (\"${name}\") has a ${size}-byte chunk, but a chunk holds a ${BLOSC_HEADER_SIZE}-byte ` +\n `Blosc header and at most ${bloscChunkBound(remaining)} bytes for the ${remaining} bytes the grid still needs.`,\n );\n }\n}\n\n/** Strips the class prefix from an inner tools error's message, to rethrow it in `.nvdb` terms. */\nfunction innerMessage(err: Error): string {\n return err.message.replace(/^@pmndrs\\/vdb\\/tools \\[[A-Z_]+\\]: (malformed \\.vdb: |not supported: )?/, \"\");\n}\n\n/**\n * Decodes one BLOSC chunk (a whole Blosc1 frame) into the start of `dest` (the grid bytes still\n * missing) and returns how many bytes it wrote. As NanoVDB (`count < 1` is a read error), an empty\n * chunk is rejected; a frame claiming more than `dest` holds fails before decoding.\n */\nexport function decodeBloscChunk(frame: Uint8Array, dest: Uint8Array, i: number, name: string): number {\n let n: number;\n try {\n n = decompressBloscInto(frame, dest, frame.length);\n } catch (err) {\n if (err instanceof VDBUnsupportedError) {\n throw new VDBUnsupportedError(`NvdbFile: BLOSC grid #${i} (\"${name}\"): ${innerMessage(err)}`);\n }\n if (err instanceof VDBToolsError || err instanceof RangeError) {\n throw new NvdbFormatError(`NvdbFile: BLOSC grid #${i} (\"${name}\"): ${innerMessage(err)}`);\n }\n throw err;\n }\n if (n < 1) {\n throw new NvdbFormatError(`NvdbFile: BLOSC grid #${i} (\"${name}\") has a chunk that decodes to 0 bytes.`);\n }\n return n;\n}\n\n/**\n * Reads a BLOSC grid's chunks from `src` at `offset` until they hold `gridSize` bytes; returns the\n * image and the offset after its last chunk.\n */\nfunction readBloscGrid(\n src: Uint8Array,\n offset: number,\n gridSize: number,\n i: number,\n name: string,\n): { bytes: Uint8Array; end: number } {\n const available = src.length - offset;\n if (gridSize > available * BLOSC_MAX_EXPANSION + 1024) {\n throw new NvdbFormatError(\n `NvdbFile: BLOSC grid #${i} (\"${name}\") declares ${gridSize} bytes, but the ${available} bytes left in the file ` +\n `can't decode to more than ${available * BLOSC_MAX_EXPANSION + 1024} (Blosc expands at most ${BLOSC_MAX_EXPANSION}:1).`,\n );\n }\n const view = new DataView(src.buffer, src.byteOffset, src.byteLength);\n const out = new Uint8Array(gridSize);\n let filled = 0;\n while (filled < gridSize) {\n if (offset + 8 > src.length) {\n throw new NvdbFormatError(`NvdbFile: truncated buffer while reading a BLOSC chunk size for grid #${i} (\"${name}\")`);\n }\n const size = Number(view.getBigUint64(offset, true));\n offset += 8;\n checkBloscChunkSize(size, gridSize - filled, i, name);\n if (offset + size > src.length) {\n throw new NvdbFormatError(\n `NvdbFile: truncated buffer while reading a ${size}-byte BLOSC chunk of grid #${i} (\"${name}\") ` +\n `(${src.length - offset} bytes left)`,\n );\n }\n filled += decodeBloscChunk(src.subarray(offset, offset + size), out.subarray(filled), i, name);\n offset += size;\n }\n return { bytes: out, end: offset };\n}\n\n/**\n * Inflates one ZIP grid payload into exactly `gridSize` bytes, bounded\n * (Finding 2): a zip-bomb would otherwise inflate fully in memory before any\n * size check runs. fflate's `out` option makes inflate() write into a fixed\n * buffer and *truncate* rather than grow past it, so the output is\n * allocated at gridSize + 1 bytes: a well-formed payload lands at exactly\n * `gridSize` bytes, an oversized one is clamped to gridSize + 1 and rejected.\n */\nexport function inflateZipGrid(compressed: Uint8Array, gridSize: number, i: number, name: string): Uint8Array {\n // Cap the declared size before allocating: deflate cannot expand more than 1032:1, so a gridSize beyond\n // that bound for this payload is a lie (a tiny file declaring a huge grid would otherwise allocate it).\n if (gridSize > compressed.byteLength * 1032 + 64) {\n throw new NvdbFormatError(\n `NvdbFile: ZIP grid #${i} (\"${name}\") declares ${gridSize} bytes but its ${compressed.byteLength}-byte payload ` +\n `cannot inflate to more than ${compressed.byteLength * 1032 + 64} (deflate expands at most 1032:1) — the file's metadata is untrustworthy.`,\n );\n }\n const outBound = new Uint8Array(gridSize + 1);\n let decompressed: Uint8Array;\n try {\n decompressed = unzlibSync(compressed, { out: outBound });\n } catch (err) {\n throw new NvdbFormatError(`NvdbFile: failed to inflate ZIP-compressed grid #${i} (\"${name}\"): ${(err as Error).message}`);\n }\n if (decompressed.byteLength === outBound.length) {\n throw new NvdbFormatError(\n `NvdbFile: ZIP-decompressed grid #${i} (\"${name}\") exceeds its declared gridSize of ` +\n `${gridSize} bytes (decompression is bounded to gridSize + 1 bytes to avoid unbounded memory ` +\n `use on a corrupt or malicious file) — the file's metadata is untrustworthy.`,\n );\n }\n if (decompressed.byteLength !== gridSize) {\n throw new NvdbFormatError(\n `NvdbFile: ZIP-decompressed grid #${i} (\"${name}\") is ${decompressed.byteLength} ` +\n `bytes, expected ${gridSize}`,\n );\n }\n return decompressed;\n}\n\n/**\n * NVIDIA Warp's `Volume.save_to_nvdb` leaves FileMetaData's `indexBBox` and `voxelCount` zero\n * (and its `fileSize` excludes the codec's 8-byte size prefix). When both are zero, the image's\n * own RootData bbox and TreeData voxel count stand in for them (K7.C; DIVERGES V69).\n */\nfunction metadataFromImage(meta: ParsedFileMetaData, gridBytes: Uint8Array): Pick<ParsedFileMetaData, \"indexBBox\" | \"voxelCount\"> {\n const zeroBox = [...meta.indexBBox.min, ...meta.indexBBox.max].every((c) => c === 0);\n if (!zeroBox || meta.voxelCount !== 0) return meta;\n const view = new DataView(gridBytes.buffer, gridBytes.byteOffset, gridBytes.byteLength);\n const treeOffset = GRID_DATA_SIZE;\n if (treeOffset + TREE_SIZE > gridBytes.byteLength) return meta;\n const rootOffset = treeOffset + Number(view.getBigUint64(treeOffset + TREE_OFF_NODE_OFFSET_ROOT, true));\n if (!Number.isSafeInteger(rootOffset) || rootOffset + ROOT_BASE_SIZE > gridBytes.byteLength) return meta;\n const vec = (at: number): [number, number, number] => [\n view.getInt32(at, true),\n view.getInt32(at + 4, true),\n view.getInt32(at + 8, true),\n ];\n return {\n indexBBox: { min: vec(rootOffset + ROOT_OFF_BBOX_MIN), max: vec(rootOffset + ROOT_OFF_BBOX_MAX) },\n voxelCount: Number(view.getBigUint64(treeOffset + TREE_OFF_VOXEL_COUNT, true)),\n };\n}\n\n/** Runs the shared checks on a decoded grid image and builds its record. */\nexport function finishGridRecord(meta: ParsedFileMetaData, name: string, i: number, gridBytes: Uint8Array): GridRecord {\n checkInternalGridSize(gridBytes, meta.gridSize, i, name);\n const gridType = gridTypeName(meta.gridTypeId);\n const gridClass = gridClassName(meta.gridClassId);\n validateGridType(gridType, name);\n const { indexBBox, voxelCount } = metadataFromImage(meta, gridBytes);\n return {\n metadata: {\n name,\n gridType,\n gridClass,\n worldBBox: meta.worldBBox,\n indexBBox,\n voxelSize: meta.voxelSize,\n voxelCount,\n gridByteSize: meta.gridSize,\n },\n image: u32View(gridBytes),\n };\n}\n\n/**\n * A segment is a FileHeader, then every grid's FileMetaData + name, then every\n * grid's data in the same order (`Segment::write` writes the header and all\n * metadata, then `Internal::write` writes each grid). A file is one or more\n * segments back to back (`writeGrids` writes one per GridHandle); grids are\n * numbered across segments. With one grid per segment the layout is\n * FileHeader, FileMetaData, name, grid data.\n */\nfunction parseSegments(buffer: ArrayBuffer): GridRecord[] {\n const view = new DataView(buffer);\n const records: GridRecord[] = [];\n let offset = 0;\n\n do {\n requireBytes(buffer, offset + FILE_HEADER_SIZE, \"FileHeader\");\n if (offset > 0 && !isFileHeaderMagic(readMagic(buffer, offset))) {\n throw new NvdbFormatError(\n `NvdbFile: the ${buffer.byteLength - offset} bytes after byte ${offset} are not another segment ` +\n `(magic \"${readMagic(buffer, offset)}\"); the file is corrupt.`,\n );\n }\n const { gridCount, codec } = readFileHeader(view, offset);\n offset += FILE_HEADER_SIZE;\n\n const first = records.length;\n const metas: { meta: ParsedFileMetaData; name: string }[] = [];\n for (let k = 0; k < gridCount; k++) {\n const i = first + k;\n requireBytes(buffer, offset + FILE_METADATA_SIZE, `FileMetaData for grid #${i}`);\n const meta = readFileMetaData(view, offset);\n offset += FILE_METADATA_SIZE;\n requireBytes(buffer, offset + meta.nameSize, `grid name for grid #${i}`);\n const name = decodeCString(new Uint8Array(buffer, offset, meta.nameSize));\n offset += meta.nameSize;\n assertSafeGridSize(meta.gridSize, `grid #${i} (\"${name}\")'s FileMetaData.gridSize`);\n metas.push({ meta, name });\n }\n\n for (let k = 0; k < gridCount; k++) {\n const i = first + k;\n const { meta, name } = metas[k]!;\n let gridBytes: Uint8Array;\n if (codec === NvdbCodec.NONE) {\n requireBytes(buffer, offset + meta.gridSize, `grid data for grid #${i} (\"${name}\")`);\n gridBytes = new Uint8Array(buffer, offset, meta.gridSize);\n offset += meta.gridSize;\n } else if (codec === NvdbCodec.BLOSC) {\n const { bytes, end } = readBloscGrid(new Uint8Array(buffer), offset, meta.gridSize, i, name);\n gridBytes = bytes;\n offset = end;\n } else {\n // Codec.ZIP: 8-byte LE compressed-size prefix, then that many bytes of\n // zlib (RFC 1950) compressed data (io::Internal::write/read, IO.h).\n requireBytes(buffer, offset + 8, `ZIP size prefix for grid #${i} (\"${name}\")`);\n const compressedSize = Number(view.getBigUint64(offset, true));\n offset += 8;\n requireBytes(buffer, offset + compressedSize, `ZIP payload for grid #${i} (\"${name}\")`);\n gridBytes = inflateZipGrid(new Uint8Array(buffer, offset, compressedSize), meta.gridSize, i, name);\n offset += compressedSize;\n }\n records.push(finishGridRecord(meta, name, i, gridBytes));\n }\n } while (offset < buffer.byteLength);\n\n return records;\n}\n\n// ---------------------------------------------------------------------------\n// Raw grid buffer format: GridData [+ TreeData + ...] x N, no FileHeader\n// ---------------------------------------------------------------------------\n\nfunction parseRawGridBuffer(buffer: ArrayBuffer): GridRecord[] {\n const view = new DataView(buffer);\n const records: GridRecord[] = [];\n\n let offset = 0;\n let index = 0;\n let expectedCount: number | undefined;\n\n while (offset < buffer.byteLength) {\n requireBytes(buffer, offset + GRID_DATA_SIZE, `GridData for grid #${index}`);\n const magic = readMagic(buffer, offset);\n if (magic !== \"NanoVDB1\" && magic !== \"NanoVDB0\") {\n throw new NvdbFormatError(`NvdbFile: expected a grid magic at byte ${offset}, found \"${magic}\"`);\n }\n checkVersion(view.getUint32(offset + GRID_OFF_VERSION, true));\n\n const gridCount = view.getUint32(offset + GRID_OFF_GRID_COUNT, true);\n expectedCount ??= gridCount;\n void view.getUint32(offset + GRID_OFF_GRID_INDEX, true); // mGridIndex, unused\n\n // K7.C: the grid-size walk is NanoVDB's own (`GridHandle::read`), which sums and skips by\n // mGridSize unchecked (the overflow class OpenVDB 13.2 fixed for segments). Each size must\n // be a safe integer that holds at least GridData + TreeData and fits in the buffer, so the\n // walk always moves forward and ends within the buffer.\n const gridSize = Number(view.getBigUint64(offset + GRID_OFF_GRID_SIZE, true));\n assertSafeGridSize(gridSize, `raw grid #${index}'s GridData.mGridSize`);\n if (gridSize < GRID_DATA_SIZE + TREE_SIZE) {\n throw new NvdbFormatError(\n `NvdbFile: raw grid #${index} declares mGridSize ${gridSize}, smaller than its ${GRID_DATA_SIZE + TREE_SIZE}-byte ` +\n `GridData + TreeData headers; the buffer is corrupt.`,\n );\n }\n requireBytes(buffer, offset + gridSize, `grid image for grid #${index}`);\n\n const name = decodeCString(new Uint8Array(buffer, offset + GRID_OFF_GRID_NAME, GRID_NAME_MAX));\n\n const gridTypeId = view.getUint32(offset + GRID_OFF_GRID_TYPE, true);\n const gridClassId = view.getUint32(offset + GRID_OFF_GRID_CLASS, true);\n const worldBBox = {\n min: [\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX, true),\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 8, true),\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 16, true),\n ] as [number, number, number],\n max: [\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 24, true),\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 32, true),\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 40, true),\n ] as [number, number, number],\n };\n const voxelSize: [number, number, number] = [\n view.getFloat64(offset + GRID_OFF_VOXEL_SIZE, true),\n view.getFloat64(offset + GRID_OFF_VOXEL_SIZE + 8, true),\n view.getFloat64(offset + GRID_OFF_VOXEL_SIZE + 16, true),\n ];\n\n const treeOffset = offset + GRID_DATA_SIZE;\n requireBytes(buffer, treeOffset + TREE_SIZE, `TreeData for grid #${index}`);\n const voxelCount = Number(view.getBigUint64(treeOffset + TREE_OFF_VOXEL_COUNT, true));\n const nodeOffsetRoot = Number(view.getBigUint64(treeOffset + TREE_OFF_NODE_OFFSET_ROOT, true));\n const rootOffset = treeOffset + nodeOffsetRoot;\n requireBytes(buffer, rootOffset + ROOT_BASE_SIZE, `RootData bbox for grid #${index}`);\n const indexBBox = {\n min: [\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN, true),\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN + 4, true),\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN + 8, true),\n ] as [number, number, number],\n max: [\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX, true),\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX + 4, true),\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX + 8, true),\n ] as [number, number, number],\n };\n\n const gridType = gridTypeName(gridTypeId);\n const gridClass = gridClassName(gridClassId);\n validateGridType(gridType, name);\n\n const gridBytes = new Uint8Array(buffer, offset, gridSize);\n records.push({\n metadata: {\n name,\n gridType,\n gridClass,\n worldBBox,\n indexBBox,\n voxelSize,\n voxelCount,\n gridByteSize: gridSize,\n },\n image: u32View(gridBytes),\n });\n\n offset += gridSize;\n index += 1;\n if (expectedCount !== undefined && index >= expectedCount) break;\n }\n\n return records;\n}\n\n// ---------------------------------------------------------------------------\n// Top-level format sniff + public API\n// ---------------------------------------------------------------------------\n\nfunction sniffFormat(buffer: ArrayBuffer): \"segment\" | \"raw\" {\n requireBytes(buffer, 8, \"the NanoVDB magic\");\n const magic = readMagic(buffer, 0);\n // \"NanoVDB0\" is genuinely ambiguous pre-v32.6 (used for both FileHeader and\n // raw GridData); we treat it as a (legacy) FileHeader, matching the plain\n // reading \"legacy files use NanoVDB0\" — none of our fixtures exercise this.\n if (magic === \"NanoVDB2\" || magic === \"NanoVDB0\") return \"segment\";\n if (magic === \"NanoVDB1\") return \"raw\";\n throw new NvdbFormatError(\n `NvdbFile: unrecognized magic \"${magic}\" at byte 0 (expected one of ` +\n `${MAGIC_ASCII.join(\", \")}) — this does not look like a NanoVDB file.`,\n );\n}\n\n/**\n * Parses a `.nvdb` file (or raw grid buffer) and exposes GPU-ready grid\n * images as flat u32 views — \"a valid NanoVDB grid image in a flat u32\n * buffer\" is the single contract between the CPU and GPU halves (SPEC §1).\n */\nexport class NvdbFile {\n private readonly records: readonly GridRecord[];\n private readonly sourceBuffer: ArrayBuffer;\n\n /**\n * @param sourceBuffer The parsed file's bytes.\n * @param records The parsed grid records.\n */\n private constructor(sourceBuffer: ArrayBuffer, records: readonly GridRecord[]) {\n this.sourceBuffer = sourceBuffer;\n this.records = records;\n }\n\n /**\n * Fetches and parses a `.nvdb` file.\n *\n * @param url The file's URL; a non-OK response throws.\n */\n static async fromURL(url: string | URL): Promise<NvdbFile> {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(\n `NvdbFile.fromURL: failed to fetch ${String(url)} (${response.status} ${response.statusText})`,\n );\n }\n const buffer = await response.arrayBuffer();\n return NvdbFile.fromArrayBuffer(buffer);\n }\n\n /**\n * Parses a `.nvdb` file (or raw grid buffer) already in memory.\n *\n * @param buffer The file's bytes; throws `NvdbFormatError` when malformed.\n */\n static fromArrayBuffer(buffer: ArrayBuffer): NvdbFile {\n const format = sniffFormat(buffer);\n const records = format === \"segment\" ? parseSegments(buffer) : parseRawGridBuffer(buffer);\n return new NvdbFile(buffer, records);\n }\n\n /** The metadata of every grid in the file, in file order. */\n get grids(): readonly NvdbGridMetadata[] {\n return this.records.map((r) => r.metadata);\n }\n\n /** Zero-copy u32 view of grid `i`'s image where the codec/alignment allows it. */\n gridImage(i: number): Uint32Array {\n return this.getRecord(i, \"gridImage\").image;\n }\n\n /**\n * True when `gridImage(i)` is a zero-copy view into the buffer originally\n * passed to `fromArrayBuffer`/`fromURL`. False when a copy was required —\n * either ZIP decompression, or a codec-NONE grid segment that landed on a\n * non-4-byte-aligned offset (grid data follows a variable-length name, so\n * alignment isn't guaranteed).\n */\n isGridImageZeroCopy(i: number): boolean {\n return this.getRecord(i, \"isGridImageZeroCopy\").image.buffer === this.sourceBuffer;\n }\n\n private getRecord(i: number, caller: string): GridRecord {\n const record = this.records[i];\n if (!record) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `NvdbFile.${caller}: index ${i} out of range (file has ${this.records.length} grid(s))`);\n }\n return record;\n }\n}\n"]}
|