@pmndrs/vdb 0.0.0-stage → 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 +727 -0
- package/LICENSE +21 -0
- package/README.md +496 -2
- package/THIRD_PARTY_NOTICES.md +315 -0
- package/dist/core/compute/atlas.d.ts +102 -0
- package/dist/core/compute/atlas.js +103 -0
- package/dist/core/compute/atlas.js.map +1 -0
- package/dist/core/compute/index.d.ts +13 -0
- package/dist/core/compute/index.js +9 -0
- package/dist/core/compute/index.js.map +1 -0
- 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 +120 -0
- package/dist/core/compute/pyramid.js +468 -0
- package/dist/core/compute/pyramid.js.map +1 -0
- package/dist/core/compute/shared.d.ts +116 -0
- package/dist/core/compute/shared.js +211 -0
- package/dist/core/compute/shared.js.map +1 -0
- package/dist/core/compute/stats.d.ts +78 -0
- package/dist/core/compute/stats.js +193 -0
- package/dist/core/compute/stats.js.map +1 -0
- package/dist/core/compute/value-transform.d.ts +30 -0
- package/dist/core/compute/value-transform.js +64 -0
- package/dist/core/compute/value-transform.js.map +1 -0
- package/dist/core/errors.d.ts +21 -0
- package/dist/core/errors.js +17 -0
- package/dist/core/errors.js.map +1 -0
- 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 +52 -0
- package/dist/core/index.js +46 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/internal.d.ts +31 -0
- package/dist/core/internal.js +32 -0
- package/dist/core/internal.js.map +1 -0
- package/dist/core/pool/affine.d.ts +34 -0
- package/dist/core/pool/affine.js +100 -0
- package/dist/core/pool/affine.js.map +1 -0
- package/dist/core/pool/allocator.d.ts +32 -0
- package/dist/core/pool/allocator.js +81 -0
- package/dist/core/pool/allocator.js.map +1 -0
- package/dist/core/pool/image-header.d.ts +93 -0
- package/dist/core/pool/image-header.js +194 -0
- package/dist/core/pool/image-header.js.map +1 -0
- package/dist/core/pool/layout.d.ts +198 -0
- package/dist/core/pool/layout.js +316 -0
- package/dist/core/pool/layout.js.map +1 -0
- package/dist/core/pool/limits.d.ts +41 -0
- package/dist/core/pool/limits.js +80 -0
- package/dist/core/pool/limits.js.map +1 -0
- package/dist/core/pool/pool.d.ts +384 -0
- package/dist/core/pool/pool.js +1184 -0
- package/dist/core/pool/pool.js.map +1 -0
- 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/core/sequence.d.ts +347 -0
- package/dist/core/sequence.js +548 -0
- 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 +50 -0
- package/dist/core/source/dense.js +384 -0
- package/dist/core/source/dense.js.map +1 -0
- 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 +120 -0
- package/dist/core/source/types.js +9 -0
- package/dist/core/source/types.js.map +1 -0
- 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 +37 -0
- package/dist/core/types.js +32 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/wgsl/api.d.ts +65 -0
- package/dist/core/wgsl/api.js +546 -0
- package/dist/core/wgsl/api.js.map +1 -0
- package/dist/core/wgsl/generate.d.ts +90 -0
- package/dist/core/wgsl/generate.js +678 -0
- package/dist/core/wgsl/generate.js.map +1 -0
- 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 +58 -0
- package/dist/core/wgsl/level-set.js +200 -0
- package/dist/core/wgsl/level-set.js.map +1 -0
- 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 +14 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
- package/dist/core/wgsl/reserved.d.ts +9 -0
- package/dist/core/wgsl/reserved.js +26 -0
- package/dist/core/wgsl/reserved.js.map +1 -0
- package/dist/core/wgsl/types.d.ts +198 -0
- package/dist/core/wgsl/types.js +2 -0
- package/dist/core/wgsl/types.js.map +1 -0
- package/dist/three/coarse-first.d.ts +207 -0
- package/dist/three/coarse-first.js +205 -0
- package/dist/three/coarse-first.js.map +1 -0
- package/dist/three/compute.d.ts +73 -0
- package/dist/three/compute.js +66 -0
- package/dist/three/compute.js.map +1 -0
- package/dist/three/device.d.ts +66 -0
- package/dist/three/device.js +62 -0
- package/dist/three/device.js.map +1 -0
- 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 +117 -0
- package/dist/three/frame/emission-light.js +276 -0
- package/dist/three/frame/emission-light.js.map +1 -0
- package/dist/three/frame/index.d.ts +19 -0
- package/dist/three/frame/index.js +15 -0
- package/dist/three/frame/index.js.map +1 -0
- package/dist/three/frame/medium.d.ts +33 -0
- package/dist/three/frame/medium.js +29 -0
- package/dist/three/frame/medium.js.map +1 -0
- package/dist/three/frame/renderer.d.ts +97 -0
- package/dist/three/frame/renderer.js +480 -0
- package/dist/three/frame/renderer.js.map +1 -0
- package/dist/three/frame/spectrum.d.ts +4 -0
- package/dist/three/frame/spectrum.js +15 -0
- package/dist/three/frame/spectrum.js.map +1 -0
- package/dist/three/frame/three-internals.d.ts +60 -0
- package/dist/three/frame/three-internals.js +152 -0
- package/dist/three/frame/three-internals.js.map +1 -0
- package/dist/three/frame/volume-shadows.d.ts +139 -0
- package/dist/three/frame/volume-shadows.js +403 -0
- package/dist/three/frame/volume-shadows.js.map +1 -0
- package/dist/three/frame/volume.d.ts +230 -0
- package/dist/three/frame/volume.js +268 -0
- package/dist/three/frame/volume.js.map +1 -0
- package/dist/three/grid-node.d.ts +229 -0
- package/dist/three/grid-node.js +545 -0
- package/dist/three/grid-node.js.map +1 -0
- package/dist/three/index.d.ts +52 -0
- package/dist/three/index.js +58 -0
- package/dist/three/index.js.map +1 -0
- package/dist/three/internal.d.ts +20 -0
- package/dist/three/internal.js +18 -0
- package/dist/three/internal.js.map +1 -0
- package/dist/three/level-set-material.d.ts +185 -0
- package/dist/three/level-set-material.js +241 -0
- package/dist/three/level-set-material.js.map +1 -0
- 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 +324 -0
- package/dist/three/material.js +502 -0
- package/dist/three/material.js.map +1 -0
- package/dist/three/points.d.ts +140 -0
- package/dist/three/points.js +261 -0
- package/dist/three/points.js.map +1 -0
- package/dist/three/sparse-source.d.ts +165 -0
- package/dist/three/sparse-source.js +405 -0
- package/dist/three/sparse-source.js.map +1 -0
- package/dist/three/volume-source.d.ts +22 -0
- package/dist/three/volume-source.js +110 -0
- package/dist/three/volume-source.js.map +1 -0
- 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 +116 -0
- package/dist/tools/cpu/compute.js +239 -0
- package/dist/tools/cpu/compute.js.map +1 -0
- 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 +111 -0
- package/dist/tools/cpu/level-set.js +313 -0
- package/dist/tools/cpu/level-set.js.map +1 -0
- 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 +297 -0
- package/dist/tools/cpu/march.js +726 -0
- package/dist/tools/cpu/march.js.map +1 -0
- 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/probe-coords.d.ts +70 -0
- package/dist/tools/cpu/probe-coords.js +116 -0
- package/dist/tools/cpu/probe-coords.js.map +1 -0
- package/dist/tools/cpu/read-value.d.ts +44 -0
- package/dist/tools/cpu/read-value.js +351 -0
- package/dist/tools/cpu/read-value.js.map +1 -0
- package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
- package/dist/tools/cpu/sample-trilinear.js +168 -0
- package/dist/tools/cpu/sample-trilinear.js.map +1 -0
- package/dist/tools/cpu/stride-tables.d.ts +56 -0
- package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
- package/dist/tools/cpu/stride-tables.generated.js +1267 -0
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
- package/dist/tools/cpu/stride-tables.js +78 -0
- package/dist/tools/cpu/stride-tables.js.map +1 -0
- 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 +66 -0
- package/dist/tools/errors.js +67 -0
- package/dist/tools/errors.js.map +1 -0
- 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 +57 -0
- package/dist/tools/frame/blackbody.js +151 -0
- package/dist/tools/frame/blackbody.js.map +1 -0
- 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 +137 -0
- package/dist/tools/frame/emission.js +290 -0
- package/dist/tools/frame/emission.js.map +1 -0
- 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 +106 -0
- package/dist/tools/frame/environment.js +272 -0
- package/dist/tools/frame/environment.js.map +1 -0
- 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 +392 -0
- package/dist/tools/frame/grid.js +802 -0
- package/dist/tools/frame/grid.js.map +1 -0
- package/dist/tools/frame/index.d.ts +150 -0
- package/dist/tools/frame/index.js +389 -0
- package/dist/tools/frame/index.js.map +1 -0
- package/dist/tools/frame/medium.d.ts +77 -0
- package/dist/tools/frame/medium.js +101 -0
- package/dist/tools/frame/medium.js.map +1 -0
- package/dist/tools/frame/mie-table.d.ts +6 -0
- package/dist/tools/frame/mie-table.js +16 -0
- package/dist/tools/frame/mie-table.js.map +1 -0
- package/dist/tools/frame/mie.d.ts +63 -0
- package/dist/tools/frame/mie.js +194 -0
- package/dist/tools/frame/mie.js.map +1 -0
- 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 +10 -0
- package/dist/tools/frame/neural-weights.js +244 -0
- package/dist/tools/frame/neural-weights.js.map +1 -0
- package/dist/tools/frame/neural.d.ts +80 -0
- package/dist/tools/frame/neural.js +150 -0
- package/dist/tools/frame/neural.js.map +1 -0
- 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 +55 -0
- package/dist/tools/frame/pyramid-layout.js +100 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -0
- package/dist/tools/frame/shadows.d.ts +190 -0
- package/dist/tools/frame/shadows.js +468 -0
- package/dist/tools/frame/shadows.js.map +1 -0
- package/dist/tools/frame/sparse.d.ts +147 -0
- package/dist/tools/frame/sparse.js +432 -0
- package/dist/tools/frame/sparse.js.map +1 -0
- 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 +222 -0
- package/dist/tools/frame/spectral.js +572 -0
- package/dist/tools/frame/spectral.js.map +1 -0
- 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 +157 -0
- package/dist/tools/index.js +132 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internal.d.ts +87 -0
- package/dist/tools/internal.js +85 -0
- package/dist/tools/internal.js.map +1 -0
- package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
- package/dist/tools/nanovdb/build-from-vdb.js +100 -0
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
- package/dist/tools/nanovdb/bytes.d.ts +233 -0
- package/dist/tools/nanovdb/bytes.js +388 -0
- package/dist/tools/nanovdb/bytes.js.map +1 -0
- package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
- package/dist/tools/nanovdb/coarse-first.js +92 -0
- package/dist/tools/nanovdb/coarse-first.js.map +1 -0
- 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 +34 -0
- package/dist/tools/nanovdb/index.js +25 -0
- package/dist/tools/nanovdb/index.js.map +1 -0
- package/dist/tools/nanovdb/inspect.d.ts +33 -0
- package/dist/tools/nanovdb/inspect.js +70 -0
- package/dist/tools/nanovdb/inspect.js.map +1 -0
- package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
- package/dist/tools/nanovdb/leaf-codec.js +356 -0
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
- package/dist/tools/nanovdb/quantize.d.ts +72 -0
- package/dist/tools/nanovdb/quantize.js +329 -0
- package/dist/tools/nanovdb/quantize.js.map +1 -0
- package/dist/tools/nanovdb/resample.d.ts +177 -0
- package/dist/tools/nanovdb/resample.js +692 -0
- package/dist/tools/nanovdb/resample.js.map +1 -0
- package/dist/tools/nanovdb/serialize.d.ts +176 -0
- package/dist/tools/nanovdb/serialize.js +439 -0
- package/dist/tools/nanovdb/serialize.js.map +1 -0
- package/dist/tools/nanovdb/stats.d.ts +87 -0
- package/dist/tools/nanovdb/stats.js +225 -0
- package/dist/tools/nanovdb/stats.js.map +1 -0
- package/dist/tools/nanovdb/transform.d.ts +30 -0
- package/dist/tools/nanovdb/transform.js +94 -0
- package/dist/tools/nanovdb/transform.js.map +1 -0
- package/dist/tools/nanovdb/tree.d.ts +186 -0
- package/dist/tools/nanovdb/tree.js +530 -0
- package/dist/tools/nanovdb/tree.js.map +1 -0
- package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
- package/dist/tools/nanovdb/write-nvdb.js +290 -0
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
- package/dist/tools/nvdb-file.d.ts +265 -0
- package/dist/tools/nvdb-file.js +763 -0
- package/dist/tools/nvdb-file.js.map +1 -0
- package/dist/tools/nvdb-stream.d.ts +154 -0
- package/dist/tools/nvdb-stream.js +409 -0
- package/dist/tools/nvdb-stream.js.map +1 -0
- 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/bit-utils.d.ts +20 -0
- package/dist/tools/vdb/bit-utils.js +42 -0
- package/dist/tools/vdb/bit-utils.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 +86 -0
- package/dist/tools/vdb/blosc.js +287 -0
- package/dist/tools/vdb/blosc.js.map +1 -0
- 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 +50 -0
- package/dist/tools/vdb/byte-reader.js +161 -0
- package/dist/tools/vdb/byte-reader.js.map +1 -0
- package/dist/tools/vdb/compression.d.ts +81 -0
- package/dist/tools/vdb/compression.js +260 -0
- package/dist/tools/vdb/compression.js.map +1 -0
- package/dist/tools/vdb/errors.d.ts +10 -0
- package/dist/tools/vdb/errors.js +11 -0
- package/dist/tools/vdb/errors.js.map +1 -0
- package/dist/tools/vdb/grid.d.ts +37 -0
- package/dist/tools/vdb/grid.js +153 -0
- package/dist/tools/vdb/grid.js.map +1 -0
- package/dist/tools/vdb/half-float.d.ts +9 -0
- package/dist/tools/vdb/half-float.js +24 -0
- package/dist/tools/vdb/half-float.js.map +1 -0
- package/dist/tools/vdb/index.d.ts +4 -0
- package/dist/tools/vdb/index.js +3 -0
- package/dist/tools/vdb/index.js.map +1 -0
- package/dist/tools/vdb/inflate.d.ts +24 -0
- package/dist/tools/vdb/inflate.js +334 -0
- package/dist/tools/vdb/inflate.js.map +1 -0
- 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.d.ts +17 -0
- package/dist/tools/vdb/metadata.js +72 -0
- package/dist/tools/vdb/metadata.js.map +1 -0
- package/dist/tools/vdb/parse.d.ts +47 -0
- package/dist/tools/vdb/parse.js +241 -0
- package/dist/tools/vdb/parse.js.map +1 -0
- package/dist/tools/vdb/point-render-data.d.ts +79 -0
- package/dist/tools/vdb/point-render-data.js +137 -0
- package/dist/tools/vdb/point-render-data.js.map +1 -0
- package/dist/tools/vdb/points.d.ts +186 -0
- package/dist/tools/vdb/points.js +835 -0
- package/dist/tools/vdb/points.js.map +1 -0
- package/dist/tools/vdb/transform.d.ts +23 -0
- package/dist/tools/vdb/transform.js +54 -0
- package/dist/tools/vdb/transform.js.map +1 -0
- package/dist/tools/vdb/tree.d.ts +111 -0
- package/dist/tools/vdb/tree.js +228 -0
- package/dist/tools/vdb/tree.js.map +1 -0
- package/dist/tools/vdb/types.d.ts +195 -0
- package/dist/tools/vdb/types.js +3 -0
- package/dist/tools/vdb/types.js.map +1 -0
- package/dist/tools/wvdb/bake.d.ts +145 -0
- package/dist/tools/wvdb/bake.js +361 -0
- package/dist/tools/wvdb/bake.js.map +1 -0
- package/dist/tools/wvdb/dense.d.ts +191 -0
- package/dist/tools/wvdb/dense.js +368 -0
- package/dist/tools/wvdb/dense.js.map +1 -0
- package/dist/tools/wvdb/format.d.ts +220 -0
- package/dist/tools/wvdb/format.js +306 -0
- package/dist/tools/wvdb/format.js.map +1 -0
- package/dist/tools/wvdb/index.d.ts +14 -0
- package/dist/tools/wvdb/index.js +15 -0
- package/dist/tools/wvdb/index.js.map +1 -0
- package/dist/tools/wvdb/level-set.d.ts +56 -0
- package/dist/tools/wvdb/level-set.js +153 -0
- package/dist/tools/wvdb/level-set.js.map +1 -0
- package/dist/tools/wvdb/nanovdb.d.ts +59 -0
- package/dist/tools/wvdb/nanovdb.js +64 -0
- package/dist/tools/wvdb/nanovdb.js.map +1 -0
- 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 +336 -0
- package/dist/tools/wvdb/read.js +766 -0
- package/dist/tools/wvdb/read.js.map +1 -0
- package/dist/tools/wvdb/sha256.d.ts +7 -0
- package/dist/tools/wvdb/sha256.js +76 -0
- package/dist/tools/wvdb/sha256.js.map +1 -0
- package/dist/tools/wvdb/write.d.ts +149 -0
- package/dist/tools/wvdb/write.js +403 -0
- package/dist/tools/wvdb/write.js.map +1 -0
- package/package.json +83 -4
- package/vendor/LICENSE +201 -0
- package/vendor/NOTICE +19 -0
- package/vendor/VENDOR.md +100 -0
- package/vendor/pnanovdb.wgsl +1577 -0
|
@@ -0,0 +1,763 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `.nvdb` loader — Phase 1 (docs/archive/v1/PLAN.md), implementing the `NvdbFile`
|
|
3
|
+
* contract from docs/archive/v1/SPEC.md §2.2: parse a `.nvdb` file (or a raw NanoVDB
|
|
4
|
+
* grid buffer) into GPU-ready grid images — "a valid NanoVDB grid image in
|
|
5
|
+
* a flat u32 buffer" (SPEC §1).
|
|
6
|
+
*
|
|
7
|
+
* Ground truth for every byte offset below is the C++ that wrote the test
|
|
8
|
+
* fixtures:
|
|
9
|
+
* - fixtures/downloads/openvdb-sparse/nanovdb/nanovdb/io/IO.h
|
|
10
|
+
* (FileHeader/FileMetaData layout, Segment/Codec framing)
|
|
11
|
+
* - fixtures/downloads/openvdb-sparse/nanovdb/nanovdb/NanoVDB.h
|
|
12
|
+
* (magic numbers, Version packing, GridType/GridClass enums, GridData)
|
|
13
|
+
* - vendor/stride-tables.json (extracted PNanoVDB.h defines: GridData,
|
|
14
|
+
* TreeData and RootData offsets, ABI 32.11.0; unchanged since 32.9.1)
|
|
15
|
+
*
|
|
16
|
+
* ## `.nvdb` "segment" format (FileHeader magic `NanoVDB0`/`NanoVDB2`)
|
|
17
|
+
*
|
|
18
|
+
* FileHeader (16B), [FileMetaData (176B), gridName (nameSize B)] x gridCount,
|
|
19
|
+
* [grid data (compressed per codec)] x gridCount
|
|
20
|
+
*
|
|
21
|
+
* A file is one or more such segments back to back (`io::Segment::write`
|
|
22
|
+
* writes the header and every grid's metadata before the grids;
|
|
23
|
+
* `writeGrids` writes one segment per GridHandle). With one grid per segment
|
|
24
|
+
* the layout is FileHeader, FileMetaData, name, grid data.
|
|
25
|
+
*
|
|
26
|
+
* FileHeader (`struct FileHeader`, IO.h/NanoVDB.h, 16 bytes):
|
|
27
|
+
*
|
|
28
|
+
* field | offset | size | type
|
|
29
|
+
* -----------|--------|------|------
|
|
30
|
+
* magic | 0 | 8 | u64 (ASCII "NanoVDB0"/"NanoVDB2")
|
|
31
|
+
* version | 8 | 4 | u32 (major<<21 | minor<<10 | patch)
|
|
32
|
+
* gridCount | 12 | 2 | u16
|
|
33
|
+
* codec | 14 | 2 | u16 (0=NONE, 1=ZIP, 2=BLOSC)
|
|
34
|
+
*
|
|
35
|
+
* FileMetaData (`struct FileMetaData`, NanoVDB.h, 176 bytes):
|
|
36
|
+
*
|
|
37
|
+
* field | offset | size | type
|
|
38
|
+
* ----------------|--------|------|------
|
|
39
|
+
* gridSize | 0 | 8 | u64 (decompressed grid image bytes)
|
|
40
|
+
* fileSize | 8 | 8 | u64 (on-disk bytes incl. codec framing)
|
|
41
|
+
* nameKey | 16 | 8 | u64 (io::stringHash(gridName))
|
|
42
|
+
* voxelCount | 24 | 8 | u64 (active voxel count)
|
|
43
|
+
* gridType | 32 | 4 | u32 (GridType enum)
|
|
44
|
+
* gridClass | 36 | 4 | u32 (GridClass enum)
|
|
45
|
+
* worldBBox.min | 40 | 24 | f64 x3
|
|
46
|
+
* worldBBox.max | 64 | 24 | f64 x3
|
|
47
|
+
* indexBBox.min | 88 | 12 | i32 x3
|
|
48
|
+
* indexBBox.max | 100 | 12 | i32 x3
|
|
49
|
+
* voxelSize | 112 | 24 | f64 x3
|
|
50
|
+
* nameSize | 136 | 4 | u32 (grid name bytes, incl. NUL)
|
|
51
|
+
* nodeCount[4] | 140 | 16 | u32 x4 (unused by this loader)
|
|
52
|
+
* tileCount[3] | 156 | 12 | u32 x3 (unused by this loader)
|
|
53
|
+
* codec | 168 | 2 | u16 (mirrors FileHeader.codec)
|
|
54
|
+
* blindDataCount | 170 | 2 | u16 (unused by this loader)
|
|
55
|
+
* version | 172 | 4 | u32
|
|
56
|
+
* total: 176 bytes
|
|
57
|
+
*
|
|
58
|
+
* ## ZIP on-disk framing (`io::Internal::write`/`read`, IO.h)
|
|
59
|
+
*
|
|
60
|
+
* Per grid: an 8-byte little-endian u64 giving the *compressed* byte count,
|
|
61
|
+
* followed by that many bytes of zlib-format (RFC 1950) compressed data —
|
|
62
|
+
* i.e. exactly what C's `compress()`/`uncompress()` (and fflate's
|
|
63
|
+
* `zlibSync`/`unzlibSync`) produce/consume. The decompressed length must
|
|
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`.
|
|
74
|
+
*
|
|
75
|
+
* ## Raw grid buffer format (magic `NanoVDB1`, no FileHeader)
|
|
76
|
+
*
|
|
77
|
+
* The buffer starts directly with `GridData` (672 bytes, layout below, from
|
|
78
|
+
* vendor/stride-tables.json), immediately followed by `TreeData` (64 bytes)
|
|
79
|
+
* and then the rest of the tree. Multiple grids may be concatenated
|
|
80
|
+
* (`GridData.mGridCount` grids total); each grid's byte length is its own
|
|
81
|
+
* `mGridSize` field, so grids are found by walking `mGridSize` forward.
|
|
82
|
+
* Raw buffers are always uncompressed.
|
|
83
|
+
*/
|
|
84
|
+
import { unzlibSync } from "fflate";
|
|
85
|
+
import { NvdbFormatError, VDBToolsError, VDBUnsupportedError } from "./errors.js";
|
|
86
|
+
import { BLOSC_HEADER_SIZE, decompressBloscInto } from "./vdb/blosc.js";
|
|
87
|
+
export { NvdbFormatError } from "./errors.js";
|
|
88
|
+
/** `.nvdb` FileHeader size in bytes (magic + version + grid count + codec). */
|
|
89
|
+
export const FILE_HEADER_SIZE = 16;
|
|
90
|
+
/** Per-grid FileMetaData size in bytes (excluding the trailing grid name). */
|
|
91
|
+
export const FILE_METADATA_SIZE = 176;
|
|
92
|
+
/** GridData block size in bytes (start of every NanoVDB grid image). */
|
|
93
|
+
export const GRID_DATA_SIZE = 672;
|
|
94
|
+
/**
|
|
95
|
+
* NanoVDB 8-byte magic strings: `NanoVDB0` = legacy file header / grid,
|
|
96
|
+
* `NanoVDB1` = raw grid buffer, `NanoVDB2` = current file header. Sniffed
|
|
97
|
+
* by `NvdbFile.fromArrayBuffer`.
|
|
98
|
+
*/
|
|
99
|
+
export const MAGIC_ASCII = ["NanoVDB0", "NanoVDB1", "NanoVDB2"];
|
|
100
|
+
/** `.nvdb` file codecs: all three are read (ZIP through fflate, BLOSC LZ4/BloscLZ since K7.C). */
|
|
101
|
+
export const NvdbCodec = {
|
|
102
|
+
NONE: 0,
|
|
103
|
+
ZIP: 1,
|
|
104
|
+
BLOSC: 2,
|
|
105
|
+
};
|
|
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
|
+
}
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
// FileHeader / FileMetaData byte offsets (see module doc comment for the
|
|
122
|
+
// full field table; these are the raw numbers used below).
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
const FILE_HEADER_OFF_VERSION = 8;
|
|
125
|
+
const FILE_HEADER_OFF_GRID_COUNT = 12;
|
|
126
|
+
const FILE_HEADER_OFF_CODEC = 14;
|
|
127
|
+
const META_OFF_GRID_SIZE = 0;
|
|
128
|
+
const META_OFF_FILE_SIZE = 8;
|
|
129
|
+
const META_OFF_VOXEL_COUNT = 24;
|
|
130
|
+
const META_OFF_GRID_TYPE = 32;
|
|
131
|
+
const META_OFF_GRID_CLASS = 36;
|
|
132
|
+
const META_OFF_WORLD_BBOX_MIN = 40;
|
|
133
|
+
const META_OFF_WORLD_BBOX_MAX = 64;
|
|
134
|
+
const META_OFF_INDEX_BBOX_MIN = 88;
|
|
135
|
+
const META_OFF_INDEX_BBOX_MAX = 100;
|
|
136
|
+
const META_OFF_VOXEL_SIZE = 112;
|
|
137
|
+
const META_OFF_NAME_SIZE = 136;
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
// GridData / TreeData / RootData byte offsets, for the raw-grid-buffer path
|
|
140
|
+
// (magic `NanoVDB1`). Values are the PNanoVDB.h defines baked into
|
|
141
|
+
// vendor/stride-tables.json.
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
const GRID_OFF_VERSION = 16;
|
|
144
|
+
const GRID_OFF_GRID_INDEX = 24;
|
|
145
|
+
const GRID_OFF_GRID_COUNT = 28;
|
|
146
|
+
const GRID_OFF_GRID_SIZE = 32;
|
|
147
|
+
const GRID_OFF_GRID_NAME = 40;
|
|
148
|
+
const GRID_NAME_MAX = 256; // GridData::MaxNameSize
|
|
149
|
+
const GRID_OFF_WORLD_BBOX = 560;
|
|
150
|
+
const GRID_OFF_VOXEL_SIZE = 608;
|
|
151
|
+
const GRID_OFF_GRID_CLASS = 632;
|
|
152
|
+
const GRID_OFF_GRID_TYPE = 636;
|
|
153
|
+
const TREE_SIZE = 64;
|
|
154
|
+
const TREE_OFF_NODE_OFFSET_ROOT = 24;
|
|
155
|
+
const TREE_OFF_VOXEL_COUNT = 56;
|
|
156
|
+
const ROOT_OFF_BBOX_MIN = 0;
|
|
157
|
+
const ROOT_OFF_BBOX_MAX = 12;
|
|
158
|
+
const ROOT_BASE_SIZE = 28;
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
// Small helpers
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
export function requireBytes(buffer, minLength, what) {
|
|
163
|
+
if (buffer.byteLength < minLength) {
|
|
164
|
+
throw new NvdbFormatError(`NvdbFile: truncated buffer while reading ${what} ` +
|
|
165
|
+
`(need ${minLength} bytes, buffer has ${buffer.byteLength})`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* `gridSize` is read off a u64 (FileMetaData.gridSize / mGridSize); most of
|
|
170
|
+
* the u64 range does not fit in a JS `number` without loss of precision. A
|
|
171
|
+
* corrupt or malicious file can set that u64 to something outside
|
|
172
|
+
* `Number.isSafeInteger` range, which would otherwise silently corrupt the
|
|
173
|
+
* arithmetic used to slice/allocate the grid image (Finding 2). Guard it
|
|
174
|
+
* before it's used for anything.
|
|
175
|
+
*/
|
|
176
|
+
export function assertSafeGridSize(gridSize, context) {
|
|
177
|
+
if (!Number.isSafeInteger(gridSize) || gridSize < 0) {
|
|
178
|
+
throw new NvdbFormatError(`NvdbFile: ${context} has an unrepresentable gridSize (${gridSize}) — the on-disk u64 does not fit ` +
|
|
179
|
+
`in a safe JS integer, so the file is corrupt or malicious.`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Cross-checks FileMetaData's declared `gridSize` (what the loader used to
|
|
184
|
+
* slice/decompress the grid image) against the grid image's own internal
|
|
185
|
+
* `GridData.mGridSize` (u64 at byte offset 32 of every grid image, see
|
|
186
|
+
* NanoVDB.h). A file whose metadata lies (truncation, corruption, or a
|
|
187
|
+
* malicious re-encode) would otherwise yield a silently short/long image and
|
|
188
|
+
* silently wrong voxels downstream — Finding 1 from the T2 verification
|
|
189
|
+
* pass. `gridBytes` must be at least `GRID_OFF_GRID_SIZE + 8` bytes for the
|
|
190
|
+
* field to be readable; anything shorter is itself proof of a mismatch.
|
|
191
|
+
*/
|
|
192
|
+
function checkInternalGridSize(gridBytes, expectedGridSize, i, name) {
|
|
193
|
+
if (gridBytes.byteLength < GRID_OFF_GRID_SIZE + 8) {
|
|
194
|
+
throw new NvdbFormatError(`NvdbFile: grid #${i} ("${name}") image is only ${gridBytes.byteLength} bytes — too short to contain ` +
|
|
195
|
+
`a GridData header, so its internal mGridSize can't be verified against FileMetaData.gridSize ` +
|
|
196
|
+
`(${expectedGridSize}). The file is corrupt or truncated.`);
|
|
197
|
+
}
|
|
198
|
+
const view = new DataView(gridBytes.buffer, gridBytes.byteOffset, gridBytes.byteLength);
|
|
199
|
+
const internalGridSize = Number(view.getBigUint64(GRID_OFF_GRID_SIZE, true));
|
|
200
|
+
if (internalGridSize !== expectedGridSize) {
|
|
201
|
+
throw new NvdbFormatError(`NvdbFile: grid #${i} ("${name}")'s FileMetaData.gridSize (${expectedGridSize}) does not match its ` +
|
|
202
|
+
`own internal GridData.mGridSize (${internalGridSize}) — the file's metadata is inconsistent with its ` +
|
|
203
|
+
`grid data (truncated or corrupted); refusing to load a possibly-wrong grid image.`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export function readMagic(buffer, offset) {
|
|
207
|
+
const bytes = new Uint8Array(buffer, offset, 8);
|
|
208
|
+
return String.fromCharCode(...bytes);
|
|
209
|
+
}
|
|
210
|
+
export function decodeCString(bytes) {
|
|
211
|
+
let end = bytes.indexOf(0);
|
|
212
|
+
if (end < 0)
|
|
213
|
+
end = bytes.length;
|
|
214
|
+
return new TextDecoder().decode(bytes.subarray(0, end));
|
|
215
|
+
}
|
|
216
|
+
function parseVersion(raw) {
|
|
217
|
+
return {
|
|
218
|
+
major: (raw >>> 21) & 0x7ff,
|
|
219
|
+
minor: (raw >>> 10) & 0x7ff,
|
|
220
|
+
patch: raw & 0x3ff,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function formatVersion(v) {
|
|
224
|
+
return `${v.major}.${v.minor}.${v.patch}`;
|
|
225
|
+
}
|
|
226
|
+
/** ABI major version this loader targets (vendor/stride-tables.json `$meta.abi` = "32.11.0"). */
|
|
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
|
+
*/
|
|
233
|
+
export function checkVersion(raw) {
|
|
234
|
+
const v = parseVersion(raw);
|
|
235
|
+
if (v.major !== NANOVDB_MAJOR_VERSION) {
|
|
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}.`);
|
|
240
|
+
}
|
|
241
|
+
return v;
|
|
242
|
+
}
|
|
243
|
+
// GridType enum names (NanoVDB.h `enum class GridType`), indexed by id.
|
|
244
|
+
// 21/22 are retired (IndexMask/OnIndexMask) and kept only as placeholders.
|
|
245
|
+
const GRID_TYPE_NAMES = [
|
|
246
|
+
"Unknown",
|
|
247
|
+
"Float",
|
|
248
|
+
"Double",
|
|
249
|
+
"Int16",
|
|
250
|
+
"Int32",
|
|
251
|
+
"Int64",
|
|
252
|
+
"Vec3f",
|
|
253
|
+
"Vec3d",
|
|
254
|
+
"Mask",
|
|
255
|
+
"Half",
|
|
256
|
+
"UInt32",
|
|
257
|
+
"Boolean",
|
|
258
|
+
"RGBA8",
|
|
259
|
+
"Fp4",
|
|
260
|
+
"Fp8",
|
|
261
|
+
"Fp16",
|
|
262
|
+
"FpN",
|
|
263
|
+
"Vec4f",
|
|
264
|
+
"Vec4d",
|
|
265
|
+
"Index",
|
|
266
|
+
"OnIndex",
|
|
267
|
+
"Retired21",
|
|
268
|
+
"Retired22",
|
|
269
|
+
"PointIndex",
|
|
270
|
+
"Vec3u8",
|
|
271
|
+
"Vec3u16",
|
|
272
|
+
"UInt8",
|
|
273
|
+
"End",
|
|
274
|
+
];
|
|
275
|
+
// GridClass enum names (NanoVDB.h `enum class GridClass`), indexed by id.
|
|
276
|
+
const GRID_CLASS_NAMES = [
|
|
277
|
+
"Unknown",
|
|
278
|
+
"LevelSet",
|
|
279
|
+
"FogVolume",
|
|
280
|
+
"Staggered",
|
|
281
|
+
"PointIndex",
|
|
282
|
+
"PointData",
|
|
283
|
+
"Topology",
|
|
284
|
+
"VoxelVolume",
|
|
285
|
+
"IndexGrid",
|
|
286
|
+
"TensorGrid",
|
|
287
|
+
"VoxelBVH",
|
|
288
|
+
"End",
|
|
289
|
+
];
|
|
290
|
+
export function gridTypeName(id) {
|
|
291
|
+
return GRID_TYPE_NAMES[id] ?? `Unknown(${id})`;
|
|
292
|
+
}
|
|
293
|
+
export function gridClassName(id) {
|
|
294
|
+
return GRID_CLASS_NAMES[id] ?? `Unknown(${id})`;
|
|
295
|
+
}
|
|
296
|
+
const SUPPORTED_GRID_TYPES_SET = NVDB_SUPPORTED_GRID_TYPES;
|
|
297
|
+
export function validateGridType(gridType, gridName) {
|
|
298
|
+
if (!SUPPORTED_GRID_TYPES_SET.includes(gridType)) {
|
|
299
|
+
throw new VDBUnsupportedError(`NvdbFile: grid "${gridName}" is a ${gridType} grid, which this loader does not ` +
|
|
300
|
+
`support — v1 only handles FogVolume grids of type ${NVDB_SUPPORTED_GRID_TYPES.join("/")}. ` +
|
|
301
|
+
`Re-export as float/fp4/fp8/fp16/fpn/half, e.g. \`nanovdb_convert --fp8 in.vdb out.nvdb\`.`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/** Zero-copy u32 view when the input is already 4-byte aligned; a copy otherwise. */
|
|
305
|
+
function u32View(bytes) {
|
|
306
|
+
if (bytes.byteOffset % 4 === 0 && bytes.byteLength % 4 === 0) {
|
|
307
|
+
return new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
|
|
308
|
+
}
|
|
309
|
+
const copy = bytes.slice(); // fresh ArrayBuffer, byteOffset 0
|
|
310
|
+
return new Uint32Array(copy.buffer, copy.byteOffset, copy.byteLength / 4);
|
|
311
|
+
}
|
|
312
|
+
export function readFileMetaData(view, offset) {
|
|
313
|
+
const gridSize = Number(view.getBigUint64(offset + META_OFF_GRID_SIZE, true));
|
|
314
|
+
const fileSize = Number(view.getBigUint64(offset + META_OFF_FILE_SIZE, true));
|
|
315
|
+
const voxelCount = Number(view.getBigUint64(offset + META_OFF_VOXEL_COUNT, true));
|
|
316
|
+
const gridTypeId = view.getUint32(offset + META_OFF_GRID_TYPE, true);
|
|
317
|
+
const gridClassId = view.getUint32(offset + META_OFF_GRID_CLASS, true);
|
|
318
|
+
const worldBBox = {
|
|
319
|
+
min: [
|
|
320
|
+
view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN, true),
|
|
321
|
+
view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN + 8, true),
|
|
322
|
+
view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN + 16, true),
|
|
323
|
+
],
|
|
324
|
+
max: [
|
|
325
|
+
view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX, true),
|
|
326
|
+
view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX + 8, true),
|
|
327
|
+
view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX + 16, true),
|
|
328
|
+
],
|
|
329
|
+
};
|
|
330
|
+
const indexBBox = {
|
|
331
|
+
min: [
|
|
332
|
+
view.getInt32(offset + META_OFF_INDEX_BBOX_MIN, true),
|
|
333
|
+
view.getInt32(offset + META_OFF_INDEX_BBOX_MIN + 4, true),
|
|
334
|
+
view.getInt32(offset + META_OFF_INDEX_BBOX_MIN + 8, true),
|
|
335
|
+
],
|
|
336
|
+
max: [
|
|
337
|
+
view.getInt32(offset + META_OFF_INDEX_BBOX_MAX, true),
|
|
338
|
+
view.getInt32(offset + META_OFF_INDEX_BBOX_MAX + 4, true),
|
|
339
|
+
view.getInt32(offset + META_OFF_INDEX_BBOX_MAX + 8, true),
|
|
340
|
+
],
|
|
341
|
+
};
|
|
342
|
+
const voxelSize = [
|
|
343
|
+
view.getFloat64(offset + META_OFF_VOXEL_SIZE, true),
|
|
344
|
+
view.getFloat64(offset + META_OFF_VOXEL_SIZE + 8, true),
|
|
345
|
+
view.getFloat64(offset + META_OFF_VOXEL_SIZE + 16, true),
|
|
346
|
+
];
|
|
347
|
+
const nameSize = view.getUint32(offset + META_OFF_NAME_SIZE, true);
|
|
348
|
+
return { gridSize, fileSize, voxelCount, gridTypeId, gridClassId, worldBBox, indexBBox, voxelSize, nameSize };
|
|
349
|
+
}
|
|
350
|
+
// ---------------------------------------------------------------------------
|
|
351
|
+
// Segment format: FileHeader + [FileMetaData, gridName] x N + [grid data] x N,
|
|
352
|
+
// one or more segments per file (io::Segment, IO.h)
|
|
353
|
+
// ---------------------------------------------------------------------------
|
|
354
|
+
/** Native file magics a segment's FileHeader may carry. */
|
|
355
|
+
export function isFileHeaderMagic(magic) {
|
|
356
|
+
return magic === "NanoVDB2" || magic === "NanoVDB0";
|
|
357
|
+
}
|
|
358
|
+
/** Checks a FileHeader's version and codec; returns its grid count and codec. */
|
|
359
|
+
export function readFileHeader(view, offset) {
|
|
360
|
+
checkVersion(view.getUint32(offset + FILE_HEADER_OFF_VERSION, true));
|
|
361
|
+
const gridCount = view.getUint16(offset + FILE_HEADER_OFF_GRID_COUNT, true);
|
|
362
|
+
const codec = view.getUint16(offset + FILE_HEADER_OFF_CODEC, true);
|
|
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`).");
|
|
366
|
+
}
|
|
367
|
+
return { gridCount, codec: codec };
|
|
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
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Inflates one ZIP grid payload into exactly `gridSize` bytes, bounded
|
|
449
|
+
* (Finding 2): a zip-bomb would otherwise inflate fully in memory before any
|
|
450
|
+
* size check runs. fflate's `out` option makes inflate() write into a fixed
|
|
451
|
+
* buffer and *truncate* rather than grow past it, so the output is
|
|
452
|
+
* allocated at gridSize + 1 bytes: a well-formed payload lands at exactly
|
|
453
|
+
* `gridSize` bytes, an oversized one is clamped to gridSize + 1 and rejected.
|
|
454
|
+
*/
|
|
455
|
+
export function inflateZipGrid(compressed, gridSize, i, name) {
|
|
456
|
+
// Cap the declared size before allocating: deflate cannot expand more than 1032:1, so a gridSize beyond
|
|
457
|
+
// that bound for this payload is a lie (a tiny file declaring a huge grid would otherwise allocate it).
|
|
458
|
+
if (gridSize > compressed.byteLength * 1032 + 64) {
|
|
459
|
+
throw new NvdbFormatError(`NvdbFile: ZIP grid #${i} ("${name}") declares ${gridSize} bytes but its ${compressed.byteLength}-byte payload ` +
|
|
460
|
+
`cannot inflate to more than ${compressed.byteLength * 1032 + 64} (deflate expands at most 1032:1) — the file's metadata is untrustworthy.`);
|
|
461
|
+
}
|
|
462
|
+
const outBound = new Uint8Array(gridSize + 1);
|
|
463
|
+
let decompressed;
|
|
464
|
+
try {
|
|
465
|
+
decompressed = unzlibSync(compressed, { out: outBound });
|
|
466
|
+
}
|
|
467
|
+
catch (err) {
|
|
468
|
+
throw new NvdbFormatError(`NvdbFile: failed to inflate ZIP-compressed grid #${i} ("${name}"): ${err.message}`);
|
|
469
|
+
}
|
|
470
|
+
if (decompressed.byteLength === outBound.length) {
|
|
471
|
+
throw new NvdbFormatError(`NvdbFile: ZIP-decompressed grid #${i} ("${name}") exceeds its declared gridSize of ` +
|
|
472
|
+
`${gridSize} bytes (decompression is bounded to gridSize + 1 bytes to avoid unbounded memory ` +
|
|
473
|
+
`use on a corrupt or malicious file) — the file's metadata is untrustworthy.`);
|
|
474
|
+
}
|
|
475
|
+
if (decompressed.byteLength !== gridSize) {
|
|
476
|
+
throw new NvdbFormatError(`NvdbFile: ZIP-decompressed grid #${i} ("${name}") is ${decompressed.byteLength} ` +
|
|
477
|
+
`bytes, expected ${gridSize}`);
|
|
478
|
+
}
|
|
479
|
+
return decompressed;
|
|
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
|
+
}
|
|
507
|
+
/** Runs the shared checks on a decoded grid image and builds its record. */
|
|
508
|
+
export function finishGridRecord(meta, name, i, gridBytes) {
|
|
509
|
+
checkInternalGridSize(gridBytes, meta.gridSize, i, name);
|
|
510
|
+
const gridType = gridTypeName(meta.gridTypeId);
|
|
511
|
+
const gridClass = gridClassName(meta.gridClassId);
|
|
512
|
+
validateGridType(gridType, name);
|
|
513
|
+
const { indexBBox, voxelCount } = metadataFromImage(meta, gridBytes);
|
|
514
|
+
return {
|
|
515
|
+
metadata: {
|
|
516
|
+
name,
|
|
517
|
+
gridType,
|
|
518
|
+
gridClass,
|
|
519
|
+
worldBBox: meta.worldBBox,
|
|
520
|
+
indexBBox,
|
|
521
|
+
voxelSize: meta.voxelSize,
|
|
522
|
+
voxelCount,
|
|
523
|
+
gridByteSize: meta.gridSize,
|
|
524
|
+
},
|
|
525
|
+
image: u32View(gridBytes),
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* A segment is a FileHeader, then every grid's FileMetaData + name, then every
|
|
530
|
+
* grid's data in the same order (`Segment::write` writes the header and all
|
|
531
|
+
* metadata, then `Internal::write` writes each grid). A file is one or more
|
|
532
|
+
* segments back to back (`writeGrids` writes one per GridHandle); grids are
|
|
533
|
+
* numbered across segments. With one grid per segment the layout is
|
|
534
|
+
* FileHeader, FileMetaData, name, grid data.
|
|
535
|
+
*/
|
|
536
|
+
function parseSegments(buffer) {
|
|
537
|
+
const view = new DataView(buffer);
|
|
538
|
+
const records = [];
|
|
539
|
+
let offset = 0;
|
|
540
|
+
do {
|
|
541
|
+
requireBytes(buffer, offset + FILE_HEADER_SIZE, "FileHeader");
|
|
542
|
+
if (offset > 0 && !isFileHeaderMagic(readMagic(buffer, offset))) {
|
|
543
|
+
throw new NvdbFormatError(`NvdbFile: the ${buffer.byteLength - offset} bytes after byte ${offset} are not another segment ` +
|
|
544
|
+
`(magic "${readMagic(buffer, offset)}"); the file is corrupt.`);
|
|
545
|
+
}
|
|
546
|
+
const { gridCount, codec } = readFileHeader(view, offset);
|
|
547
|
+
offset += FILE_HEADER_SIZE;
|
|
548
|
+
const first = records.length;
|
|
549
|
+
const metas = [];
|
|
550
|
+
for (let k = 0; k < gridCount; k++) {
|
|
551
|
+
const i = first + k;
|
|
552
|
+
requireBytes(buffer, offset + FILE_METADATA_SIZE, `FileMetaData for grid #${i}`);
|
|
553
|
+
const meta = readFileMetaData(view, offset);
|
|
554
|
+
offset += FILE_METADATA_SIZE;
|
|
555
|
+
requireBytes(buffer, offset + meta.nameSize, `grid name for grid #${i}`);
|
|
556
|
+
const name = decodeCString(new Uint8Array(buffer, offset, meta.nameSize));
|
|
557
|
+
offset += meta.nameSize;
|
|
558
|
+
assertSafeGridSize(meta.gridSize, `grid #${i} ("${name}")'s FileMetaData.gridSize`);
|
|
559
|
+
metas.push({ meta, name });
|
|
560
|
+
}
|
|
561
|
+
for (let k = 0; k < gridCount; k++) {
|
|
562
|
+
const i = first + k;
|
|
563
|
+
const { meta, name } = metas[k];
|
|
564
|
+
let gridBytes;
|
|
565
|
+
if (codec === NvdbCodec.NONE) {
|
|
566
|
+
requireBytes(buffer, offset + meta.gridSize, `grid data for grid #${i} ("${name}")`);
|
|
567
|
+
gridBytes = new Uint8Array(buffer, offset, meta.gridSize);
|
|
568
|
+
offset += meta.gridSize;
|
|
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
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
// Codec.ZIP: 8-byte LE compressed-size prefix, then that many bytes of
|
|
577
|
+
// zlib (RFC 1950) compressed data (io::Internal::write/read, IO.h).
|
|
578
|
+
requireBytes(buffer, offset + 8, `ZIP size prefix for grid #${i} ("${name}")`);
|
|
579
|
+
const compressedSize = Number(view.getBigUint64(offset, true));
|
|
580
|
+
offset += 8;
|
|
581
|
+
requireBytes(buffer, offset + compressedSize, `ZIP payload for grid #${i} ("${name}")`);
|
|
582
|
+
gridBytes = inflateZipGrid(new Uint8Array(buffer, offset, compressedSize), meta.gridSize, i, name);
|
|
583
|
+
offset += compressedSize;
|
|
584
|
+
}
|
|
585
|
+
records.push(finishGridRecord(meta, name, i, gridBytes));
|
|
586
|
+
}
|
|
587
|
+
} while (offset < buffer.byteLength);
|
|
588
|
+
return records;
|
|
589
|
+
}
|
|
590
|
+
// ---------------------------------------------------------------------------
|
|
591
|
+
// Raw grid buffer format: GridData [+ TreeData + ...] x N, no FileHeader
|
|
592
|
+
// ---------------------------------------------------------------------------
|
|
593
|
+
function parseRawGridBuffer(buffer) {
|
|
594
|
+
const view = new DataView(buffer);
|
|
595
|
+
const records = [];
|
|
596
|
+
let offset = 0;
|
|
597
|
+
let index = 0;
|
|
598
|
+
let expectedCount;
|
|
599
|
+
while (offset < buffer.byteLength) {
|
|
600
|
+
requireBytes(buffer, offset + GRID_DATA_SIZE, `GridData for grid #${index}`);
|
|
601
|
+
const magic = readMagic(buffer, offset);
|
|
602
|
+
if (magic !== "NanoVDB1" && magic !== "NanoVDB0") {
|
|
603
|
+
throw new NvdbFormatError(`NvdbFile: expected a grid magic at byte ${offset}, found "${magic}"`);
|
|
604
|
+
}
|
|
605
|
+
checkVersion(view.getUint32(offset + GRID_OFF_VERSION, true));
|
|
606
|
+
const gridCount = view.getUint32(offset + GRID_OFF_GRID_COUNT, true);
|
|
607
|
+
expectedCount ??= gridCount;
|
|
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.
|
|
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
|
+
}
|
|
619
|
+
requireBytes(buffer, offset + gridSize, `grid image for grid #${index}`);
|
|
620
|
+
const name = decodeCString(new Uint8Array(buffer, offset + GRID_OFF_GRID_NAME, GRID_NAME_MAX));
|
|
621
|
+
const gridTypeId = view.getUint32(offset + GRID_OFF_GRID_TYPE, true);
|
|
622
|
+
const gridClassId = view.getUint32(offset + GRID_OFF_GRID_CLASS, true);
|
|
623
|
+
const worldBBox = {
|
|
624
|
+
min: [
|
|
625
|
+
view.getFloat64(offset + GRID_OFF_WORLD_BBOX, true),
|
|
626
|
+
view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 8, true),
|
|
627
|
+
view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 16, true),
|
|
628
|
+
],
|
|
629
|
+
max: [
|
|
630
|
+
view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 24, true),
|
|
631
|
+
view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 32, true),
|
|
632
|
+
view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 40, true),
|
|
633
|
+
],
|
|
634
|
+
};
|
|
635
|
+
const voxelSize = [
|
|
636
|
+
view.getFloat64(offset + GRID_OFF_VOXEL_SIZE, true),
|
|
637
|
+
view.getFloat64(offset + GRID_OFF_VOXEL_SIZE + 8, true),
|
|
638
|
+
view.getFloat64(offset + GRID_OFF_VOXEL_SIZE + 16, true),
|
|
639
|
+
];
|
|
640
|
+
const treeOffset = offset + GRID_DATA_SIZE;
|
|
641
|
+
requireBytes(buffer, treeOffset + TREE_SIZE, `TreeData for grid #${index}`);
|
|
642
|
+
const voxelCount = Number(view.getBigUint64(treeOffset + TREE_OFF_VOXEL_COUNT, true));
|
|
643
|
+
const nodeOffsetRoot = Number(view.getBigUint64(treeOffset + TREE_OFF_NODE_OFFSET_ROOT, true));
|
|
644
|
+
const rootOffset = treeOffset + nodeOffsetRoot;
|
|
645
|
+
requireBytes(buffer, rootOffset + ROOT_BASE_SIZE, `RootData bbox for grid #${index}`);
|
|
646
|
+
const indexBBox = {
|
|
647
|
+
min: [
|
|
648
|
+
view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN, true),
|
|
649
|
+
view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN + 4, true),
|
|
650
|
+
view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN + 8, true),
|
|
651
|
+
],
|
|
652
|
+
max: [
|
|
653
|
+
view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX, true),
|
|
654
|
+
view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX + 4, true),
|
|
655
|
+
view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX + 8, true),
|
|
656
|
+
],
|
|
657
|
+
};
|
|
658
|
+
const gridType = gridTypeName(gridTypeId);
|
|
659
|
+
const gridClass = gridClassName(gridClassId);
|
|
660
|
+
validateGridType(gridType, name);
|
|
661
|
+
const gridBytes = new Uint8Array(buffer, offset, gridSize);
|
|
662
|
+
records.push({
|
|
663
|
+
metadata: {
|
|
664
|
+
name,
|
|
665
|
+
gridType,
|
|
666
|
+
gridClass,
|
|
667
|
+
worldBBox,
|
|
668
|
+
indexBBox,
|
|
669
|
+
voxelSize,
|
|
670
|
+
voxelCount,
|
|
671
|
+
gridByteSize: gridSize,
|
|
672
|
+
},
|
|
673
|
+
image: u32View(gridBytes),
|
|
674
|
+
});
|
|
675
|
+
offset += gridSize;
|
|
676
|
+
index += 1;
|
|
677
|
+
if (expectedCount !== undefined && index >= expectedCount)
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
return records;
|
|
681
|
+
}
|
|
682
|
+
// ---------------------------------------------------------------------------
|
|
683
|
+
// Top-level format sniff + public API
|
|
684
|
+
// ---------------------------------------------------------------------------
|
|
685
|
+
function sniffFormat(buffer) {
|
|
686
|
+
requireBytes(buffer, 8, "the NanoVDB magic");
|
|
687
|
+
const magic = readMagic(buffer, 0);
|
|
688
|
+
// "NanoVDB0" is genuinely ambiguous pre-v32.6 (used for both FileHeader and
|
|
689
|
+
// raw GridData); we treat it as a (legacy) FileHeader, matching the plain
|
|
690
|
+
// reading "legacy files use NanoVDB0" — none of our fixtures exercise this.
|
|
691
|
+
if (magic === "NanoVDB2" || magic === "NanoVDB0")
|
|
692
|
+
return "segment";
|
|
693
|
+
if (magic === "NanoVDB1")
|
|
694
|
+
return "raw";
|
|
695
|
+
throw new NvdbFormatError(`NvdbFile: unrecognized magic "${magic}" at byte 0 (expected one of ` +
|
|
696
|
+
`${MAGIC_ASCII.join(", ")}) — this does not look like a NanoVDB file.`);
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Parses a `.nvdb` file (or raw grid buffer) and exposes GPU-ready grid
|
|
700
|
+
* images as flat u32 views — "a valid NanoVDB grid image in a flat u32
|
|
701
|
+
* buffer" is the single contract between the CPU and GPU halves (SPEC §1).
|
|
702
|
+
*/
|
|
703
|
+
export class NvdbFile {
|
|
704
|
+
records;
|
|
705
|
+
sourceBuffer;
|
|
706
|
+
/**
|
|
707
|
+
* @param sourceBuffer The parsed file's bytes.
|
|
708
|
+
* @param records The parsed grid records.
|
|
709
|
+
*/
|
|
710
|
+
constructor(sourceBuffer, records) {
|
|
711
|
+
this.sourceBuffer = sourceBuffer;
|
|
712
|
+
this.records = records;
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Fetches and parses a `.nvdb` file.
|
|
716
|
+
*
|
|
717
|
+
* @param url The file's URL; a non-OK response throws.
|
|
718
|
+
*/
|
|
719
|
+
static async fromURL(url) {
|
|
720
|
+
const response = await fetch(url);
|
|
721
|
+
if (!response.ok) {
|
|
722
|
+
throw new Error(`NvdbFile.fromURL: failed to fetch ${String(url)} (${response.status} ${response.statusText})`);
|
|
723
|
+
}
|
|
724
|
+
const buffer = await response.arrayBuffer();
|
|
725
|
+
return NvdbFile.fromArrayBuffer(buffer);
|
|
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
|
+
*/
|
|
732
|
+
static fromArrayBuffer(buffer) {
|
|
733
|
+
const format = sniffFormat(buffer);
|
|
734
|
+
const records = format === "segment" ? parseSegments(buffer) : parseRawGridBuffer(buffer);
|
|
735
|
+
return new NvdbFile(buffer, records);
|
|
736
|
+
}
|
|
737
|
+
/** The metadata of every grid in the file, in file order. */
|
|
738
|
+
get grids() {
|
|
739
|
+
return this.records.map((r) => r.metadata);
|
|
740
|
+
}
|
|
741
|
+
/** Zero-copy u32 view of grid `i`'s image where the codec/alignment allows it. */
|
|
742
|
+
gridImage(i) {
|
|
743
|
+
return this.getRecord(i, "gridImage").image;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* True when `gridImage(i)` is a zero-copy view into the buffer originally
|
|
747
|
+
* passed to `fromArrayBuffer`/`fromURL`. False when a copy was required —
|
|
748
|
+
* either ZIP decompression, or a codec-NONE grid segment that landed on a
|
|
749
|
+
* non-4-byte-aligned offset (grid data follows a variable-length name, so
|
|
750
|
+
* alignment isn't guaranteed).
|
|
751
|
+
*/
|
|
752
|
+
isGridImageZeroCopy(i) {
|
|
753
|
+
return this.getRecord(i, "isGridImageZeroCopy").image.buffer === this.sourceBuffer;
|
|
754
|
+
}
|
|
755
|
+
getRecord(i, caller) {
|
|
756
|
+
const record = this.records[i];
|
|
757
|
+
if (!record) {
|
|
758
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `NvdbFile.${caller}: index ${i} out of range (file has ${this.records.length} grid(s))`);
|
|
759
|
+
}
|
|
760
|
+
return record;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
//# sourceMappingURL=nvdb-file.js.map
|