@pmndrs/vdb 0.0.0-stage → 0.1.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 +137 -0
- package/LICENSE +21 -0
- package/README.md +448 -2
- package/THIRD_PARTY_NOTICES.md +147 -0
- package/dist/core/compute/atlas.d.ts +94 -0
- package/dist/core/compute/atlas.js +98 -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/pyramid.d.ts +105 -0
- package/dist/core/compute/pyramid.js +455 -0
- package/dist/core/compute/pyramid.js.map +1 -0
- package/dist/core/compute/shared.d.ts +115 -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 +71 -0
- package/dist/core/compute/stats.js +188 -0
- package/dist/core/compute/stats.js.map +1 -0
- package/dist/core/compute/value-transform.d.ts +23 -0
- package/dist/core/compute/value-transform.js +58 -0
- package/dist/core/compute/value-transform.js.map +1 -0
- package/dist/core/errors.d.ts +11 -0
- package/dist/core/errors.js +9 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +30 -0
- package/dist/core/index.js +27 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/internal.d.ts +15 -0
- package/dist/core/internal.js +15 -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 +82 -0
- package/dist/core/pool/image-header.js +175 -0
- package/dist/core/pool/image-header.js.map +1 -0
- package/dist/core/pool/layout.d.ts +164 -0
- package/dist/core/pool/layout.js +267 -0
- package/dist/core/pool/layout.js.map +1 -0
- package/dist/core/pool/limits.d.ts +40 -0
- package/dist/core/pool/limits.js +79 -0
- package/dist/core/pool/limits.js.map +1 -0
- package/dist/core/pool/pool.d.ts +279 -0
- package/dist/core/pool/pool.js +953 -0
- package/dist/core/pool/pool.js.map +1 -0
- package/dist/core/source/dense.d.ts +19 -0
- package/dist/core/source/dense.js +287 -0
- package/dist/core/source/dense.js.map +1 -0
- package/dist/core/source/types.d.ts +63 -0
- package/dist/core/source/types.js +9 -0
- package/dist/core/source/types.js.map +1 -0
- package/dist/core/types.d.ts +28 -0
- package/dist/core/types.js +28 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/wgsl/api.d.ts +41 -0
- package/dist/core/wgsl/api.js +463 -0
- package/dist/core/wgsl/api.js.map +1 -0
- package/dist/core/wgsl/generate.d.ts +82 -0
- package/dist/core/wgsl/generate.js +505 -0
- package/dist/core/wgsl/generate.js.map +1 -0
- package/dist/core/wgsl/level-set.d.ts +54 -0
- package/dist/core/wgsl/level-set.js +194 -0
- package/dist/core/wgsl/level-set.js.map +1 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +330 -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 +104 -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 +162 -0
- package/dist/three/coarse-first.js +187 -0
- package/dist/three/coarse-first.js.map +1 -0
- package/dist/three/compute.d.ts +63 -0
- package/dist/three/compute.js +56 -0
- package/dist/three/compute.js.map +1 -0
- package/dist/three/device.d.ts +59 -0
- package/dist/three/device.js +59 -0
- package/dist/three/device.js.map +1 -0
- package/dist/three/frame/blackbody.d.ts +42 -0
- package/dist/three/frame/blackbody.js +74 -0
- package/dist/three/frame/blackbody.js.map +1 -0
- package/dist/three/frame/chunks.d.ts +157 -0
- package/dist/three/frame/chunks.js +559 -0
- package/dist/three/frame/chunks.js.map +1 -0
- package/dist/three/frame/density-material.d.ts +53 -0
- package/dist/three/frame/density-material.js +353 -0
- package/dist/three/frame/density-material.js.map +1 -0
- package/dist/three/frame/emission-light.d.ts +167 -0
- package/dist/three/frame/emission-light.js +655 -0
- package/dist/three/frame/emission-light.js.map +1 -0
- package/dist/three/frame/environment-grid-material.d.ts +21 -0
- package/dist/three/frame/environment-grid-material.js +184 -0
- package/dist/three/frame/environment-grid-material.js.map +1 -0
- package/dist/three/frame/environment-material.d.ts +22 -0
- package/dist/three/frame/environment-material.js +87 -0
- package/dist/three/frame/environment-material.js.map +1 -0
- package/dist/three/frame/grid-mip-material.d.ts +12 -0
- package/dist/three/frame/grid-mip-material.js +61 -0
- package/dist/three/frame/grid-mip-material.js.map +1 -0
- package/dist/three/frame/index.d.ts +39 -0
- package/dist/three/frame/index.js +35 -0
- package/dist/three/frame/index.js.map +1 -0
- package/dist/three/frame/inject-material.d.ts +56 -0
- package/dist/three/frame/inject-material.js +424 -0
- package/dist/three/frame/inject-material.js.map +1 -0
- package/dist/three/frame/integrate-material.d.ts +26 -0
- package/dist/three/frame/integrate-material.js +198 -0
- package/dist/three/frame/integrate-material.js.map +1 -0
- package/dist/three/frame/layout.d.ts +34 -0
- package/dist/three/frame/layout.js +48 -0
- package/dist/three/frame/layout.js.map +1 -0
- package/dist/three/frame/lighting-material.d.ts +41 -0
- package/dist/three/frame/lighting-material.js +257 -0
- package/dist/three/frame/lighting-material.js.map +1 -0
- package/dist/three/frame/lights.d.ts +11 -0
- package/dist/three/frame/lights.js +16 -0
- package/dist/three/frame/lights.js.map +1 -0
- package/dist/three/frame/medium.d.ts +21 -0
- package/dist/three/frame/medium.js +29 -0
- package/dist/three/frame/medium.js.map +1 -0
- package/dist/three/frame/neural.d.ts +14 -0
- package/dist/three/frame/neural.js +105 -0
- package/dist/three/frame/neural.js.map +1 -0
- package/dist/three/frame/phase.d.ts +44 -0
- package/dist/three/frame/phase.js +80 -0
- package/dist/three/frame/phase.js.map +1 -0
- package/dist/three/frame/renderer.d.ts +493 -0
- package/dist/three/frame/renderer.js +1498 -0
- package/dist/three/frame/renderer.js.map +1 -0
- package/dist/three/frame/shadow-density-material.d.ts +30 -0
- package/dist/three/frame/shadow-density-material.js +123 -0
- package/dist/three/frame/shadow-density-material.js.map +1 -0
- package/dist/three/frame/spectrum.d.ts +18 -0
- package/dist/three/frame/spectrum.js +36 -0
- package/dist/three/frame/spectrum.js.map +1 -0
- package/dist/three/frame/temporal-material.d.ts +29 -0
- package/dist/three/frame/temporal-material.js +152 -0
- package/dist/three/frame/temporal-material.js.map +1 -0
- package/dist/three/frame/three-internals.d.ts +65 -0
- package/dist/three/frame/three-internals.js +150 -0
- package/dist/three/frame/three-internals.js.map +1 -0
- package/dist/three/frame/transmittance-material.d.ts +31 -0
- package/dist/three/frame/transmittance-material.js +315 -0
- package/dist/three/frame/transmittance-material.js.map +1 -0
- package/dist/three/frame/view.d.ts +103 -0
- package/dist/three/frame/view.js +296 -0
- package/dist/three/frame/view.js.map +1 -0
- package/dist/three/frame/volume-shadow-material.d.ts +36 -0
- package/dist/three/frame/volume-shadow-material.js +128 -0
- package/dist/three/frame/volume-shadow-material.js.map +1 -0
- package/dist/three/frame/volume-shadows.d.ts +153 -0
- package/dist/three/frame/volume-shadows.js +756 -0
- package/dist/three/frame/volume-shadows.js.map +1 -0
- package/dist/three/frame/volume.d.ts +172 -0
- package/dist/three/frame/volume.js +256 -0
- package/dist/three/frame/volume.js.map +1 -0
- package/dist/three/grid-node.d.ts +196 -0
- package/dist/three/grid-node.js +510 -0
- package/dist/three/grid-node.js.map +1 -0
- package/dist/three/index.d.ts +43 -0
- package/dist/three/index.js +49 -0
- package/dist/three/index.js.map +1 -0
- package/dist/three/internal.d.ts +14 -0
- package/dist/three/internal.js +14 -0
- package/dist/three/internal.js.map +1 -0
- package/dist/three/level-set-material.d.ts +112 -0
- package/dist/three/level-set-material.js +204 -0
- package/dist/three/level-set-material.js.map +1 -0
- package/dist/three/material.d.ts +194 -0
- package/dist/three/material.js +359 -0
- package/dist/three/material.js.map +1 -0
- package/dist/three/points.d.ts +84 -0
- package/dist/three/points.js +130 -0
- package/dist/three/points.js.map +1 -0
- package/dist/three/sequence.d.ts +317 -0
- package/dist/three/sequence.js +526 -0
- package/dist/three/sequence.js.map +1 -0
- package/dist/three/sparse-source.d.ts +233 -0
- package/dist/three/sparse-source.js +876 -0
- package/dist/three/sparse-source.js.map +1 -0
- package/dist/three/volume-source.d.ts +167 -0
- package/dist/three/volume-source.js +353 -0
- package/dist/three/volume-source.js.map +1 -0
- package/dist/tools/cpu/compute.d.ts +97 -0
- package/dist/tools/cpu/compute.js +218 -0
- package/dist/tools/cpu/compute.js.map +1 -0
- package/dist/tools/cpu/level-set.d.ts +72 -0
- package/dist/tools/cpu/level-set.js +261 -0
- package/dist/tools/cpu/level-set.js.map +1 -0
- package/dist/tools/cpu/march.d.ts +206 -0
- package/dist/tools/cpu/march.js +575 -0
- package/dist/tools/cpu/march.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 +31 -0
- package/dist/tools/cpu/read-value.js +336 -0
- package/dist/tools/cpu/read-value.js.map +1 -0
- package/dist/tools/cpu/sample-trilinear.d.ts +30 -0
- package/dist/tools/cpu/sample-trilinear.js +156 -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 +1058 -0
- package/dist/tools/cpu/stride-tables.generated.js +1266 -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/errors.d.ts +57 -0
- package/dist/tools/errors.js +58 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/frame/blackbody.d.ts +42 -0
- package/dist/tools/frame/blackbody.js +116 -0
- package/dist/tools/frame/blackbody.js.map +1 -0
- package/dist/tools/frame/emission.d.ts +128 -0
- package/dist/tools/frame/emission.js +282 -0
- package/dist/tools/frame/emission.js.map +1 -0
- package/dist/tools/frame/environment.d.ts +105 -0
- package/dist/tools/frame/environment.js +268 -0
- package/dist/tools/frame/environment.js.map +1 -0
- package/dist/tools/frame/grid.d.ts +302 -0
- package/dist/tools/frame/grid.js +703 -0
- package/dist/tools/frame/grid.js.map +1 -0
- package/dist/tools/frame/index.d.ts +136 -0
- package/dist/tools/frame/index.js +348 -0
- package/dist/tools/frame/index.js.map +1 -0
- package/dist/tools/frame/medium.d.ts +61 -0
- package/dist/tools/frame/medium.js +99 -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 +54 -0
- package/dist/tools/frame/mie.js +176 -0
- package/dist/tools/frame/mie.js.map +1 -0
- package/dist/tools/frame/neural-weights.d.ts +9 -0
- package/dist/tools/frame/neural-weights.js +245 -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/pyramid-layout.d.ts +38 -0
- package/dist/tools/frame/pyramid-layout.js +53 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -0
- package/dist/tools/frame/shadows.d.ts +80 -0
- package/dist/tools/frame/shadows.js +182 -0
- package/dist/tools/frame/shadows.js.map +1 -0
- package/dist/tools/frame/sparse.d.ts +65 -0
- package/dist/tools/frame/sparse.js +191 -0
- package/dist/tools/frame/sparse.js.map +1 -0
- package/dist/tools/frame/spectral.d.ts +203 -0
- package/dist/tools/frame/spectral.js +550 -0
- package/dist/tools/frame/spectral.js.map +1 -0
- package/dist/tools/index.d.ts +106 -0
- package/dist/tools/index.js +88 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internal.d.ts +46 -0
- package/dist/tools/internal.js +31 -0
- package/dist/tools/internal.js.map +1 -0
- package/dist/tools/nanovdb/build-from-vdb.d.ts +50 -0
- package/dist/tools/nanovdb/build-from-vdb.js +92 -0
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
- package/dist/tools/nanovdb/bytes.d.ts +220 -0
- package/dist/tools/nanovdb/bytes.js +345 -0
- package/dist/tools/nanovdb/bytes.js.map +1 -0
- package/dist/tools/nanovdb/coarse-first.d.ts +62 -0
- package/dist/tools/nanovdb/coarse-first.js +86 -0
- package/dist/tools/nanovdb/coarse-first.js.map +1 -0
- package/dist/tools/nanovdb/index.d.ts +32 -0
- package/dist/tools/nanovdb/index.js +24 -0
- package/dist/tools/nanovdb/index.js.map +1 -0
- package/dist/tools/nanovdb/inspect.d.ts +24 -0
- package/dist/tools/nanovdb/inspect.js +63 -0
- package/dist/tools/nanovdb/inspect.js.map +1 -0
- package/dist/tools/nanovdb/leaf-codec.d.ts +85 -0
- package/dist/tools/nanovdb/leaf-codec.js +320 -0
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
- package/dist/tools/nanovdb/quantize.d.ts +43 -0
- package/dist/tools/nanovdb/quantize.js +277 -0
- package/dist/tools/nanovdb/quantize.js.map +1 -0
- package/dist/tools/nanovdb/resample.d.ts +160 -0
- package/dist/tools/nanovdb/resample.js +679 -0
- package/dist/tools/nanovdb/resample.js.map +1 -0
- package/dist/tools/nanovdb/serialize.d.ts +145 -0
- package/dist/tools/nanovdb/serialize.js +395 -0
- package/dist/tools/nanovdb/serialize.js.map +1 -0
- package/dist/tools/nanovdb/stats.d.ts +58 -0
- package/dist/tools/nanovdb/stats.js +149 -0
- package/dist/tools/nanovdb/stats.js.map +1 -0
- package/dist/tools/nanovdb/transform.d.ts +26 -0
- package/dist/tools/nanovdb/transform.js +91 -0
- package/dist/tools/nanovdb/transform.js.map +1 -0
- package/dist/tools/nanovdb/tree.d.ts +175 -0
- package/dist/tools/nanovdb/tree.js +518 -0
- package/dist/tools/nanovdb/tree.js.map +1 -0
- package/dist/tools/nanovdb/write-nvdb.d.ts +39 -0
- package/dist/tools/nanovdb/write-nvdb.js +210 -0
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
- package/dist/tools/nvdb-file.d.ts +195 -0
- package/dist/tools/nvdb-file.js +606 -0
- package/dist/tools/nvdb-file.js.map +1 -0
- package/dist/tools/nvdb-stream.d.ts +138 -0
- package/dist/tools/nvdb-stream.js +365 -0
- package/dist/tools/nvdb-stream.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.d.ts +56 -0
- package/dist/tools/vdb/blosc.js +231 -0
- package/dist/tools/vdb/blosc.js.map +1 -0
- package/dist/tools/vdb/byte-reader.d.ts +40 -0
- package/dist/tools/vdb/byte-reader.js +139 -0
- package/dist/tools/vdb/byte-reader.js.map +1 -0
- package/dist/tools/vdb/compression.d.ts +73 -0
- package/dist/tools/vdb/compression.js +249 -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 +147 -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 +3 -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/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 +25 -0
- package/dist/tools/vdb/parse.js +171 -0
- package/dist/tools/vdb/parse.js.map +1 -0
- package/dist/tools/vdb/point-render-data.d.ts +31 -0
- package/dist/tools/vdb/point-render-data.js +57 -0
- package/dist/tools/vdb/point-render-data.js.map +1 -0
- package/dist/tools/vdb/points.d.ts +160 -0
- package/dist/tools/vdb/points.js +794 -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 +138 -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 +116 -0
- package/dist/tools/wvdb/bake.js +311 -0
- package/dist/tools/wvdb/bake.js.map +1 -0
- package/dist/tools/wvdb/dense.d.ts +112 -0
- package/dist/tools/wvdb/dense.js +309 -0
- package/dist/tools/wvdb/dense.js.map +1 -0
- package/dist/tools/wvdb/format.d.ts +161 -0
- package/dist/tools/wvdb/format.js +303 -0
- package/dist/tools/wvdb/format.js.map +1 -0
- package/dist/tools/wvdb/index.d.ts +13 -0
- package/dist/tools/wvdb/index.js +14 -0
- package/dist/tools/wvdb/index.js.map +1 -0
- package/dist/tools/wvdb/level-set.d.ts +48 -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 +54 -0
- package/dist/tools/wvdb/nanovdb.js +60 -0
- package/dist/tools/wvdb/nanovdb.js.map +1 -0
- package/dist/tools/wvdb/read.d.ts +260 -0
- package/dist/tools/wvdb/read.js +743 -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 +127 -0
- package/dist/tools/wvdb/write.js +396 -0
- package/dist/tools/wvdb/write.js.map +1 -0
- package/package.json +82 -4
- package/vendor/LICENSE +201 -0
- package/vendor/NOTICE +19 -0
- package/vendor/VENDOR.md +85 -0
- package/vendor/pnanovdb.wgsl +1539 -0
|
@@ -0,0 +1,606 @@
|
|
|
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.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. BLOSC uses the same 8-byte-prefixed
|
|
65
|
+
* chunk framing but with blosc-compressed chunks; it is not implemented
|
|
66
|
+
* (SPEC §7 non-goal) — callers get an actionable error instead.
|
|
67
|
+
*
|
|
68
|
+
* ## Raw grid buffer format (magic `NanoVDB1`, no FileHeader)
|
|
69
|
+
*
|
|
70
|
+
* The buffer starts directly with `GridData` (672 bytes, layout below, from
|
|
71
|
+
* vendor/stride-tables.json), immediately followed by `TreeData` (64 bytes)
|
|
72
|
+
* and then the rest of the tree. Multiple grids may be concatenated
|
|
73
|
+
* (`GridData.mGridCount` grids total); each grid's byte length is its own
|
|
74
|
+
* `mGridSize` field, so grids are found by walking `mGridSize` forward.
|
|
75
|
+
* Raw buffers are always uncompressed.
|
|
76
|
+
*/
|
|
77
|
+
import { unzlibSync } from "fflate";
|
|
78
|
+
import { NvdbFormatError, VDBToolsError, VDBUnsupportedError } from "./errors.js";
|
|
79
|
+
export { NvdbFormatError } from "./errors.js";
|
|
80
|
+
/** `.nvdb` FileHeader size in bytes (magic + version + grid count + codec). */
|
|
81
|
+
export const FILE_HEADER_SIZE = 16;
|
|
82
|
+
/** Per-grid FileMetaData size in bytes (excluding the trailing grid name). */
|
|
83
|
+
export const FILE_METADATA_SIZE = 176;
|
|
84
|
+
/** GridData block size in bytes (start of every NanoVDB grid image). */
|
|
85
|
+
export const GRID_DATA_SIZE = 672;
|
|
86
|
+
/**
|
|
87
|
+
* NanoVDB 8-byte magic strings: `NanoVDB0` = legacy file header / grid,
|
|
88
|
+
* `NanoVDB1` = raw grid buffer, `NanoVDB2` = current file header. Sniffed
|
|
89
|
+
* by `NvdbFile.fromArrayBuffer`.
|
|
90
|
+
*/
|
|
91
|
+
export const MAGIC_ASCII = ["NanoVDB0", "NanoVDB1", "NanoVDB2"];
|
|
92
|
+
/** File codecs we know about; v1 supports NONE and ZIP (fflate). */
|
|
93
|
+
export const NvdbCodec = {
|
|
94
|
+
NONE: 0,
|
|
95
|
+
ZIP: 1,
|
|
96
|
+
BLOSC: 2,
|
|
97
|
+
};
|
|
98
|
+
/** Grid types targeted for v1 (FogVolume rendering). */
|
|
99
|
+
export const NVDB_SUPPORTED_GRID_TYPES = ["Float", "Fp4", "Fp8", "Fp16", "FpN"];
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
// FileHeader / FileMetaData byte offsets (see module doc comment for the
|
|
102
|
+
// full field table; these are the raw numbers used below).
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
const FILE_HEADER_OFF_VERSION = 8;
|
|
105
|
+
const FILE_HEADER_OFF_GRID_COUNT = 12;
|
|
106
|
+
const FILE_HEADER_OFF_CODEC = 14;
|
|
107
|
+
const META_OFF_GRID_SIZE = 0;
|
|
108
|
+
const META_OFF_FILE_SIZE = 8;
|
|
109
|
+
const META_OFF_VOXEL_COUNT = 24;
|
|
110
|
+
const META_OFF_GRID_TYPE = 32;
|
|
111
|
+
const META_OFF_GRID_CLASS = 36;
|
|
112
|
+
const META_OFF_WORLD_BBOX_MIN = 40;
|
|
113
|
+
const META_OFF_WORLD_BBOX_MAX = 64;
|
|
114
|
+
const META_OFF_INDEX_BBOX_MIN = 88;
|
|
115
|
+
const META_OFF_INDEX_BBOX_MAX = 100;
|
|
116
|
+
const META_OFF_VOXEL_SIZE = 112;
|
|
117
|
+
const META_OFF_NAME_SIZE = 136;
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
// GridData / TreeData / RootData byte offsets, for the raw-grid-buffer path
|
|
120
|
+
// (magic `NanoVDB1`). Values are the PNanoVDB.h defines baked into
|
|
121
|
+
// vendor/stride-tables.json.
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
const GRID_OFF_VERSION = 16;
|
|
124
|
+
const GRID_OFF_GRID_INDEX = 24;
|
|
125
|
+
const GRID_OFF_GRID_COUNT = 28;
|
|
126
|
+
const GRID_OFF_GRID_SIZE = 32;
|
|
127
|
+
const GRID_OFF_GRID_NAME = 40;
|
|
128
|
+
const GRID_NAME_MAX = 256; // GridData::MaxNameSize
|
|
129
|
+
const GRID_OFF_WORLD_BBOX = 560;
|
|
130
|
+
const GRID_OFF_VOXEL_SIZE = 608;
|
|
131
|
+
const GRID_OFF_GRID_CLASS = 632;
|
|
132
|
+
const GRID_OFF_GRID_TYPE = 636;
|
|
133
|
+
const TREE_SIZE = 64;
|
|
134
|
+
const TREE_OFF_NODE_OFFSET_ROOT = 24;
|
|
135
|
+
const TREE_OFF_VOXEL_COUNT = 56;
|
|
136
|
+
const ROOT_OFF_BBOX_MIN = 0;
|
|
137
|
+
const ROOT_OFF_BBOX_MAX = 12;
|
|
138
|
+
const ROOT_BASE_SIZE = 28;
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
// Small helpers
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
export function requireBytes(buffer, minLength, what) {
|
|
143
|
+
if (buffer.byteLength < minLength) {
|
|
144
|
+
throw new NvdbFormatError(`NvdbFile: truncated buffer while reading ${what} ` +
|
|
145
|
+
`(need ${minLength} bytes, buffer has ${buffer.byteLength})`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* `gridSize` is read off a u64 (FileMetaData.gridSize / mGridSize); most of
|
|
150
|
+
* the u64 range does not fit in a JS `number` without loss of precision. A
|
|
151
|
+
* corrupt or malicious file can set that u64 to something outside
|
|
152
|
+
* `Number.isSafeInteger` range, which would otherwise silently corrupt the
|
|
153
|
+
* arithmetic used to slice/allocate the grid image (Finding 2). Guard it
|
|
154
|
+
* before it's used for anything.
|
|
155
|
+
*/
|
|
156
|
+
export function assertSafeGridSize(gridSize, context) {
|
|
157
|
+
if (!Number.isSafeInteger(gridSize) || gridSize < 0) {
|
|
158
|
+
throw new NvdbFormatError(`NvdbFile: ${context} has an unrepresentable gridSize (${gridSize}) — the on-disk u64 does not fit ` +
|
|
159
|
+
`in a safe JS integer, so the file is corrupt or malicious.`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Cross-checks FileMetaData's declared `gridSize` (what the loader used to
|
|
164
|
+
* slice/decompress the grid image) against the grid image's own internal
|
|
165
|
+
* `GridData.mGridSize` (u64 at byte offset 32 of every grid image, see
|
|
166
|
+
* NanoVDB.h). A file whose metadata lies (truncation, corruption, or a
|
|
167
|
+
* malicious re-encode) would otherwise yield a silently short/long image and
|
|
168
|
+
* silently wrong voxels downstream — Finding 1 from the T2 verification
|
|
169
|
+
* pass. `gridBytes` must be at least `GRID_OFF_GRID_SIZE + 8` bytes for the
|
|
170
|
+
* field to be readable; anything shorter is itself proof of a mismatch.
|
|
171
|
+
*/
|
|
172
|
+
function checkInternalGridSize(gridBytes, expectedGridSize, i, name) {
|
|
173
|
+
if (gridBytes.byteLength < GRID_OFF_GRID_SIZE + 8) {
|
|
174
|
+
throw new NvdbFormatError(`NvdbFile: grid #${i} ("${name}") image is only ${gridBytes.byteLength} bytes — too short to contain ` +
|
|
175
|
+
`a GridData header, so its internal mGridSize can't be verified against FileMetaData.gridSize ` +
|
|
176
|
+
`(${expectedGridSize}). The file is corrupt or truncated.`);
|
|
177
|
+
}
|
|
178
|
+
const view = new DataView(gridBytes.buffer, gridBytes.byteOffset, gridBytes.byteLength);
|
|
179
|
+
const internalGridSize = Number(view.getBigUint64(GRID_OFF_GRID_SIZE, true));
|
|
180
|
+
if (internalGridSize !== expectedGridSize) {
|
|
181
|
+
throw new NvdbFormatError(`NvdbFile: grid #${i} ("${name}")'s FileMetaData.gridSize (${expectedGridSize}) does not match its ` +
|
|
182
|
+
`own internal GridData.mGridSize (${internalGridSize}) — the file's metadata is inconsistent with its ` +
|
|
183
|
+
`grid data (truncated or corrupted); refusing to load a possibly-wrong grid image.`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
export function readMagic(buffer, offset) {
|
|
187
|
+
const bytes = new Uint8Array(buffer, offset, 8);
|
|
188
|
+
return String.fromCharCode(...bytes);
|
|
189
|
+
}
|
|
190
|
+
export function decodeCString(bytes) {
|
|
191
|
+
let end = bytes.indexOf(0);
|
|
192
|
+
if (end < 0)
|
|
193
|
+
end = bytes.length;
|
|
194
|
+
return new TextDecoder().decode(bytes.subarray(0, end));
|
|
195
|
+
}
|
|
196
|
+
function parseVersion(raw) {
|
|
197
|
+
return {
|
|
198
|
+
major: (raw >>> 21) & 0x7ff,
|
|
199
|
+
minor: (raw >>> 10) & 0x7ff,
|
|
200
|
+
patch: raw & 0x3ff,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function formatVersion(v) {
|
|
204
|
+
return `${v.major}.${v.minor}.${v.patch}`;
|
|
205
|
+
}
|
|
206
|
+
/** ABI major version this loader targets (vendor/stride-tables.json `$meta.abi` = "32.9.1"). */
|
|
207
|
+
const NANOVDB_MAJOR_VERSION = 32;
|
|
208
|
+
export function checkVersion(raw) {
|
|
209
|
+
const v = parseVersion(raw);
|
|
210
|
+
if (v.major !== NANOVDB_MAJOR_VERSION) {
|
|
211
|
+
throw new NvdbFormatError(`NvdbFile: incompatible NanoVDB version ${formatVersion(v)} ` +
|
|
212
|
+
`(this loader targets NanoVDB ${NANOVDB_MAJOR_VERSION}.x). ` +
|
|
213
|
+
`Re-export the file with a matching major version of NanoVDB.`);
|
|
214
|
+
}
|
|
215
|
+
return v;
|
|
216
|
+
}
|
|
217
|
+
// GridType enum names (NanoVDB.h `enum class GridType`), indexed by id.
|
|
218
|
+
// 21/22 are retired (IndexMask/OnIndexMask) and kept only as placeholders.
|
|
219
|
+
const GRID_TYPE_NAMES = [
|
|
220
|
+
"Unknown",
|
|
221
|
+
"Float",
|
|
222
|
+
"Double",
|
|
223
|
+
"Int16",
|
|
224
|
+
"Int32",
|
|
225
|
+
"Int64",
|
|
226
|
+
"Vec3f",
|
|
227
|
+
"Vec3d",
|
|
228
|
+
"Mask",
|
|
229
|
+
"Half",
|
|
230
|
+
"UInt32",
|
|
231
|
+
"Boolean",
|
|
232
|
+
"RGBA8",
|
|
233
|
+
"Fp4",
|
|
234
|
+
"Fp8",
|
|
235
|
+
"Fp16",
|
|
236
|
+
"FpN",
|
|
237
|
+
"Vec4f",
|
|
238
|
+
"Vec4d",
|
|
239
|
+
"Index",
|
|
240
|
+
"OnIndex",
|
|
241
|
+
"Retired21",
|
|
242
|
+
"Retired22",
|
|
243
|
+
"PointIndex",
|
|
244
|
+
"Vec3u8",
|
|
245
|
+
"Vec3u16",
|
|
246
|
+
"UInt8",
|
|
247
|
+
"End",
|
|
248
|
+
];
|
|
249
|
+
// GridClass enum names (NanoVDB.h `enum class GridClass`), indexed by id.
|
|
250
|
+
const GRID_CLASS_NAMES = [
|
|
251
|
+
"Unknown",
|
|
252
|
+
"LevelSet",
|
|
253
|
+
"FogVolume",
|
|
254
|
+
"Staggered",
|
|
255
|
+
"PointIndex",
|
|
256
|
+
"PointData",
|
|
257
|
+
"Topology",
|
|
258
|
+
"VoxelVolume",
|
|
259
|
+
"IndexGrid",
|
|
260
|
+
"TensorGrid",
|
|
261
|
+
"VoxelBVH",
|
|
262
|
+
"End",
|
|
263
|
+
];
|
|
264
|
+
export function gridTypeName(id) {
|
|
265
|
+
return GRID_TYPE_NAMES[id] ?? `Unknown(${id})`;
|
|
266
|
+
}
|
|
267
|
+
export function gridClassName(id) {
|
|
268
|
+
return GRID_CLASS_NAMES[id] ?? `Unknown(${id})`;
|
|
269
|
+
}
|
|
270
|
+
const SUPPORTED_GRID_TYPES_SET = NVDB_SUPPORTED_GRID_TYPES;
|
|
271
|
+
export function validateGridType(gridType, gridName) {
|
|
272
|
+
if (!SUPPORTED_GRID_TYPES_SET.includes(gridType)) {
|
|
273
|
+
throw new VDBUnsupportedError(`NvdbFile: grid "${gridName}" is a ${gridType} grid, which this loader does not ` +
|
|
274
|
+
`support — v1 only handles FogVolume grids of type ${NVDB_SUPPORTED_GRID_TYPES.join("/")}. ` +
|
|
275
|
+
`Re-export as float/fp4/fp8/fp16 (or fpn), e.g. \`nanovdb_convert --fp8 in.vdb out.nvdb\`.`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/** Zero-copy u32 view when the input is already 4-byte aligned; a copy otherwise. */
|
|
279
|
+
function u32View(bytes) {
|
|
280
|
+
if (bytes.byteOffset % 4 === 0 && bytes.byteLength % 4 === 0) {
|
|
281
|
+
return new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
|
|
282
|
+
}
|
|
283
|
+
const copy = bytes.slice(); // fresh ArrayBuffer, byteOffset 0
|
|
284
|
+
return new Uint32Array(copy.buffer, copy.byteOffset, copy.byteLength / 4);
|
|
285
|
+
}
|
|
286
|
+
export function readFileMetaData(view, offset) {
|
|
287
|
+
const gridSize = Number(view.getBigUint64(offset + META_OFF_GRID_SIZE, true));
|
|
288
|
+
const fileSize = Number(view.getBigUint64(offset + META_OFF_FILE_SIZE, true));
|
|
289
|
+
const voxelCount = Number(view.getBigUint64(offset + META_OFF_VOXEL_COUNT, true));
|
|
290
|
+
const gridTypeId = view.getUint32(offset + META_OFF_GRID_TYPE, true);
|
|
291
|
+
const gridClassId = view.getUint32(offset + META_OFF_GRID_CLASS, true);
|
|
292
|
+
const worldBBox = {
|
|
293
|
+
min: [
|
|
294
|
+
view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN, true),
|
|
295
|
+
view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN + 8, true),
|
|
296
|
+
view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN + 16, true),
|
|
297
|
+
],
|
|
298
|
+
max: [
|
|
299
|
+
view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX, true),
|
|
300
|
+
view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX + 8, true),
|
|
301
|
+
view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX + 16, true),
|
|
302
|
+
],
|
|
303
|
+
};
|
|
304
|
+
const indexBBox = {
|
|
305
|
+
min: [
|
|
306
|
+
view.getInt32(offset + META_OFF_INDEX_BBOX_MIN, true),
|
|
307
|
+
view.getInt32(offset + META_OFF_INDEX_BBOX_MIN + 4, true),
|
|
308
|
+
view.getInt32(offset + META_OFF_INDEX_BBOX_MIN + 8, true),
|
|
309
|
+
],
|
|
310
|
+
max: [
|
|
311
|
+
view.getInt32(offset + META_OFF_INDEX_BBOX_MAX, true),
|
|
312
|
+
view.getInt32(offset + META_OFF_INDEX_BBOX_MAX + 4, true),
|
|
313
|
+
view.getInt32(offset + META_OFF_INDEX_BBOX_MAX + 8, true),
|
|
314
|
+
],
|
|
315
|
+
};
|
|
316
|
+
const voxelSize = [
|
|
317
|
+
view.getFloat64(offset + META_OFF_VOXEL_SIZE, true),
|
|
318
|
+
view.getFloat64(offset + META_OFF_VOXEL_SIZE + 8, true),
|
|
319
|
+
view.getFloat64(offset + META_OFF_VOXEL_SIZE + 16, true),
|
|
320
|
+
];
|
|
321
|
+
const nameSize = view.getUint32(offset + META_OFF_NAME_SIZE, true);
|
|
322
|
+
return { gridSize, fileSize, voxelCount, gridTypeId, gridClassId, worldBBox, indexBBox, voxelSize, nameSize };
|
|
323
|
+
}
|
|
324
|
+
// ---------------------------------------------------------------------------
|
|
325
|
+
// Segment format: FileHeader + [FileMetaData, gridName] x N + [grid data] x N,
|
|
326
|
+
// one or more segments per file (io::Segment, IO.h)
|
|
327
|
+
// ---------------------------------------------------------------------------
|
|
328
|
+
/** Native file magics a segment's FileHeader may carry. */
|
|
329
|
+
export function isFileHeaderMagic(magic) {
|
|
330
|
+
return magic === "NanoVDB2" || magic === "NanoVDB0";
|
|
331
|
+
}
|
|
332
|
+
/** Checks a FileHeader's version and codec; returns its grid count and codec. */
|
|
333
|
+
export function readFileHeader(view, offset) {
|
|
334
|
+
checkVersion(view.getUint32(offset + FILE_HEADER_OFF_VERSION, true));
|
|
335
|
+
const gridCount = view.getUint16(offset + FILE_HEADER_OFF_GRID_COUNT, true);
|
|
336
|
+
const codec = view.getUint16(offset + FILE_HEADER_OFF_CODEC, true);
|
|
337
|
+
if (codec === NvdbCodec.BLOSC) {
|
|
338
|
+
throw new VDBUnsupportedError("NvdbFile: this file uses the BLOSC codec, which is not supported in the browser. " +
|
|
339
|
+
"Re-export it with codec NONE or ZIP (e.g. `nanovdb_convert --codec=zip`).");
|
|
340
|
+
}
|
|
341
|
+
if (codec !== NvdbCodec.NONE && codec !== NvdbCodec.ZIP) {
|
|
342
|
+
throw new NvdbFormatError(`NvdbFile: unknown codec value ${codec} in FileHeader`);
|
|
343
|
+
}
|
|
344
|
+
return { gridCount, codec: codec };
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Inflates one ZIP grid payload into exactly `gridSize` bytes, bounded
|
|
348
|
+
* (Finding 2): a zip-bomb would otherwise inflate fully in memory before any
|
|
349
|
+
* size check runs. fflate's `out` option makes inflate() write into a fixed
|
|
350
|
+
* buffer and *truncate* rather than grow past it, so the output is
|
|
351
|
+
* allocated at gridSize + 1 bytes: a well-formed payload lands at exactly
|
|
352
|
+
* `gridSize` bytes, an oversized one is clamped to gridSize + 1 and rejected.
|
|
353
|
+
*/
|
|
354
|
+
export function inflateZipGrid(compressed, gridSize, i, name) {
|
|
355
|
+
// Cap the declared size before allocating: deflate cannot expand more than 1032:1, so a gridSize beyond
|
|
356
|
+
// that bound for this payload is a lie (a tiny file declaring a huge grid would otherwise allocate it).
|
|
357
|
+
if (gridSize > compressed.byteLength * 1032 + 64) {
|
|
358
|
+
throw new NvdbFormatError(`NvdbFile: ZIP grid #${i} ("${name}") declares ${gridSize} bytes but its ${compressed.byteLength}-byte payload ` +
|
|
359
|
+
`cannot inflate to more than ${compressed.byteLength * 1032 + 64} (deflate expands at most 1032:1) — the file's metadata is untrustworthy.`);
|
|
360
|
+
}
|
|
361
|
+
const outBound = new Uint8Array(gridSize + 1);
|
|
362
|
+
let decompressed;
|
|
363
|
+
try {
|
|
364
|
+
decompressed = unzlibSync(compressed, { out: outBound });
|
|
365
|
+
}
|
|
366
|
+
catch (err) {
|
|
367
|
+
throw new NvdbFormatError(`NvdbFile: failed to inflate ZIP-compressed grid #${i} ("${name}"): ${err.message}`);
|
|
368
|
+
}
|
|
369
|
+
if (decompressed.byteLength === outBound.length) {
|
|
370
|
+
throw new NvdbFormatError(`NvdbFile: ZIP-decompressed grid #${i} ("${name}") exceeds its declared gridSize of ` +
|
|
371
|
+
`${gridSize} bytes (decompression is bounded to gridSize + 1 bytes to avoid unbounded memory ` +
|
|
372
|
+
`use on a corrupt or malicious file) — the file's metadata is untrustworthy.`);
|
|
373
|
+
}
|
|
374
|
+
if (decompressed.byteLength !== gridSize) {
|
|
375
|
+
throw new NvdbFormatError(`NvdbFile: ZIP-decompressed grid #${i} ("${name}") is ${decompressed.byteLength} ` +
|
|
376
|
+
`bytes, expected ${gridSize}`);
|
|
377
|
+
}
|
|
378
|
+
return decompressed;
|
|
379
|
+
}
|
|
380
|
+
/** Runs the shared checks on a decoded grid image and builds its record. */
|
|
381
|
+
export function finishGridRecord(meta, name, i, gridBytes) {
|
|
382
|
+
checkInternalGridSize(gridBytes, meta.gridSize, i, name);
|
|
383
|
+
const gridType = gridTypeName(meta.gridTypeId);
|
|
384
|
+
const gridClass = gridClassName(meta.gridClassId);
|
|
385
|
+
validateGridType(gridType, name);
|
|
386
|
+
return {
|
|
387
|
+
metadata: {
|
|
388
|
+
name,
|
|
389
|
+
gridType,
|
|
390
|
+
gridClass,
|
|
391
|
+
worldBBox: meta.worldBBox,
|
|
392
|
+
indexBBox: meta.indexBBox,
|
|
393
|
+
voxelSize: meta.voxelSize,
|
|
394
|
+
voxelCount: meta.voxelCount,
|
|
395
|
+
gridByteSize: meta.gridSize,
|
|
396
|
+
},
|
|
397
|
+
image: u32View(gridBytes),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* A segment is a FileHeader, then every grid's FileMetaData + name, then every
|
|
402
|
+
* grid's data in the same order (`Segment::write` writes the header and all
|
|
403
|
+
* metadata, then `Internal::write` writes each grid). A file is one or more
|
|
404
|
+
* segments back to back (`writeGrids` writes one per GridHandle); grids are
|
|
405
|
+
* numbered across segments. With one grid per segment the layout is
|
|
406
|
+
* FileHeader, FileMetaData, name, grid data.
|
|
407
|
+
*/
|
|
408
|
+
function parseSegments(buffer) {
|
|
409
|
+
const view = new DataView(buffer);
|
|
410
|
+
const records = [];
|
|
411
|
+
let offset = 0;
|
|
412
|
+
do {
|
|
413
|
+
requireBytes(buffer, offset + FILE_HEADER_SIZE, "FileHeader");
|
|
414
|
+
if (offset > 0 && !isFileHeaderMagic(readMagic(buffer, offset))) {
|
|
415
|
+
throw new NvdbFormatError(`NvdbFile: the ${buffer.byteLength - offset} bytes after byte ${offset} are not another segment ` +
|
|
416
|
+
`(magic "${readMagic(buffer, offset)}"); the file is corrupt.`);
|
|
417
|
+
}
|
|
418
|
+
const { gridCount, codec } = readFileHeader(view, offset);
|
|
419
|
+
offset += FILE_HEADER_SIZE;
|
|
420
|
+
const first = records.length;
|
|
421
|
+
const metas = [];
|
|
422
|
+
for (let k = 0; k < gridCount; k++) {
|
|
423
|
+
const i = first + k;
|
|
424
|
+
requireBytes(buffer, offset + FILE_METADATA_SIZE, `FileMetaData for grid #${i}`);
|
|
425
|
+
const meta = readFileMetaData(view, offset);
|
|
426
|
+
offset += FILE_METADATA_SIZE;
|
|
427
|
+
requireBytes(buffer, offset + meta.nameSize, `grid name for grid #${i}`);
|
|
428
|
+
const name = decodeCString(new Uint8Array(buffer, offset, meta.nameSize));
|
|
429
|
+
offset += meta.nameSize;
|
|
430
|
+
assertSafeGridSize(meta.gridSize, `grid #${i} ("${name}")'s FileMetaData.gridSize`);
|
|
431
|
+
metas.push({ meta, name });
|
|
432
|
+
}
|
|
433
|
+
for (let k = 0; k < gridCount; k++) {
|
|
434
|
+
const i = first + k;
|
|
435
|
+
const { meta, name } = metas[k];
|
|
436
|
+
let gridBytes;
|
|
437
|
+
if (codec === NvdbCodec.NONE) {
|
|
438
|
+
requireBytes(buffer, offset + meta.gridSize, `grid data for grid #${i} ("${name}")`);
|
|
439
|
+
gridBytes = new Uint8Array(buffer, offset, meta.gridSize);
|
|
440
|
+
offset += meta.gridSize;
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
// Codec.ZIP: 8-byte LE compressed-size prefix, then that many bytes of
|
|
444
|
+
// zlib (RFC 1950) compressed data (io::Internal::write/read, IO.h).
|
|
445
|
+
requireBytes(buffer, offset + 8, `ZIP size prefix for grid #${i} ("${name}")`);
|
|
446
|
+
const compressedSize = Number(view.getBigUint64(offset, true));
|
|
447
|
+
offset += 8;
|
|
448
|
+
requireBytes(buffer, offset + compressedSize, `ZIP payload for grid #${i} ("${name}")`);
|
|
449
|
+
gridBytes = inflateZipGrid(new Uint8Array(buffer, offset, compressedSize), meta.gridSize, i, name);
|
|
450
|
+
offset += compressedSize;
|
|
451
|
+
}
|
|
452
|
+
records.push(finishGridRecord(meta, name, i, gridBytes));
|
|
453
|
+
}
|
|
454
|
+
} while (offset < buffer.byteLength);
|
|
455
|
+
return records;
|
|
456
|
+
}
|
|
457
|
+
// ---------------------------------------------------------------------------
|
|
458
|
+
// Raw grid buffer format: GridData [+ TreeData + ...] x N, no FileHeader
|
|
459
|
+
// ---------------------------------------------------------------------------
|
|
460
|
+
function parseRawGridBuffer(buffer) {
|
|
461
|
+
const view = new DataView(buffer);
|
|
462
|
+
const records = [];
|
|
463
|
+
let offset = 0;
|
|
464
|
+
let index = 0;
|
|
465
|
+
let expectedCount;
|
|
466
|
+
while (offset < buffer.byteLength) {
|
|
467
|
+
requireBytes(buffer, offset + GRID_DATA_SIZE, `GridData for grid #${index}`);
|
|
468
|
+
const magic = readMagic(buffer, offset);
|
|
469
|
+
if (magic !== "NanoVDB1" && magic !== "NanoVDB0") {
|
|
470
|
+
throw new NvdbFormatError(`NvdbFile: expected a grid magic at byte ${offset}, found "${magic}"`);
|
|
471
|
+
}
|
|
472
|
+
checkVersion(view.getUint32(offset + GRID_OFF_VERSION, true));
|
|
473
|
+
const gridCount = view.getUint32(offset + GRID_OFF_GRID_COUNT, true);
|
|
474
|
+
expectedCount ??= gridCount;
|
|
475
|
+
void view.getUint32(offset + GRID_OFF_GRID_INDEX, true); // mGridIndex, unused
|
|
476
|
+
const gridSize = Number(view.getBigUint64(offset + GRID_OFF_GRID_SIZE, true));
|
|
477
|
+
requireBytes(buffer, offset + gridSize, `grid image for grid #${index}`);
|
|
478
|
+
const name = decodeCString(new Uint8Array(buffer, offset + GRID_OFF_GRID_NAME, GRID_NAME_MAX));
|
|
479
|
+
const gridTypeId = view.getUint32(offset + GRID_OFF_GRID_TYPE, true);
|
|
480
|
+
const gridClassId = view.getUint32(offset + GRID_OFF_GRID_CLASS, true);
|
|
481
|
+
const worldBBox = {
|
|
482
|
+
min: [
|
|
483
|
+
view.getFloat64(offset + GRID_OFF_WORLD_BBOX, true),
|
|
484
|
+
view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 8, true),
|
|
485
|
+
view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 16, true),
|
|
486
|
+
],
|
|
487
|
+
max: [
|
|
488
|
+
view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 24, true),
|
|
489
|
+
view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 32, true),
|
|
490
|
+
view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 40, true),
|
|
491
|
+
],
|
|
492
|
+
};
|
|
493
|
+
const voxelSize = [
|
|
494
|
+
view.getFloat64(offset + GRID_OFF_VOXEL_SIZE, true),
|
|
495
|
+
view.getFloat64(offset + GRID_OFF_VOXEL_SIZE + 8, true),
|
|
496
|
+
view.getFloat64(offset + GRID_OFF_VOXEL_SIZE + 16, true),
|
|
497
|
+
];
|
|
498
|
+
const treeOffset = offset + GRID_DATA_SIZE;
|
|
499
|
+
requireBytes(buffer, treeOffset + TREE_SIZE, `TreeData for grid #${index}`);
|
|
500
|
+
const voxelCount = Number(view.getBigUint64(treeOffset + TREE_OFF_VOXEL_COUNT, true));
|
|
501
|
+
const nodeOffsetRoot = Number(view.getBigUint64(treeOffset + TREE_OFF_NODE_OFFSET_ROOT, true));
|
|
502
|
+
const rootOffset = treeOffset + nodeOffsetRoot;
|
|
503
|
+
requireBytes(buffer, rootOffset + ROOT_BASE_SIZE, `RootData bbox for grid #${index}`);
|
|
504
|
+
const indexBBox = {
|
|
505
|
+
min: [
|
|
506
|
+
view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN, true),
|
|
507
|
+
view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN + 4, true),
|
|
508
|
+
view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN + 8, true),
|
|
509
|
+
],
|
|
510
|
+
max: [
|
|
511
|
+
view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX, true),
|
|
512
|
+
view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX + 4, true),
|
|
513
|
+
view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX + 8, true),
|
|
514
|
+
],
|
|
515
|
+
};
|
|
516
|
+
const gridType = gridTypeName(gridTypeId);
|
|
517
|
+
const gridClass = gridClassName(gridClassId);
|
|
518
|
+
validateGridType(gridType, name);
|
|
519
|
+
const gridBytes = new Uint8Array(buffer, offset, gridSize);
|
|
520
|
+
records.push({
|
|
521
|
+
metadata: {
|
|
522
|
+
name,
|
|
523
|
+
gridType,
|
|
524
|
+
gridClass,
|
|
525
|
+
worldBBox,
|
|
526
|
+
indexBBox,
|
|
527
|
+
voxelSize,
|
|
528
|
+
voxelCount,
|
|
529
|
+
gridByteSize: gridSize,
|
|
530
|
+
},
|
|
531
|
+
image: u32View(gridBytes),
|
|
532
|
+
});
|
|
533
|
+
offset += gridSize;
|
|
534
|
+
index += 1;
|
|
535
|
+
if (expectedCount !== undefined && index >= expectedCount)
|
|
536
|
+
break;
|
|
537
|
+
}
|
|
538
|
+
return records;
|
|
539
|
+
}
|
|
540
|
+
// ---------------------------------------------------------------------------
|
|
541
|
+
// Top-level format sniff + public API
|
|
542
|
+
// ---------------------------------------------------------------------------
|
|
543
|
+
function sniffFormat(buffer) {
|
|
544
|
+
requireBytes(buffer, 8, "the NanoVDB magic");
|
|
545
|
+
const magic = readMagic(buffer, 0);
|
|
546
|
+
// "NanoVDB0" is genuinely ambiguous pre-v32.6 (used for both FileHeader and
|
|
547
|
+
// raw GridData); we treat it as a (legacy) FileHeader, matching the plain
|
|
548
|
+
// reading "legacy files use NanoVDB0" — none of our fixtures exercise this.
|
|
549
|
+
if (magic === "NanoVDB2" || magic === "NanoVDB0")
|
|
550
|
+
return "segment";
|
|
551
|
+
if (magic === "NanoVDB1")
|
|
552
|
+
return "raw";
|
|
553
|
+
throw new NvdbFormatError(`NvdbFile: unrecognized magic "${magic}" at byte 0 (expected one of ` +
|
|
554
|
+
`${MAGIC_ASCII.join(", ")}) — this does not look like a NanoVDB file.`);
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Parses a `.nvdb` file (or raw grid buffer) and exposes GPU-ready grid
|
|
558
|
+
* images as flat u32 views — "a valid NanoVDB grid image in a flat u32
|
|
559
|
+
* buffer" is the single contract between the CPU and GPU halves (SPEC §1).
|
|
560
|
+
*/
|
|
561
|
+
export class NvdbFile {
|
|
562
|
+
records;
|
|
563
|
+
sourceBuffer;
|
|
564
|
+
constructor(sourceBuffer, records) {
|
|
565
|
+
this.sourceBuffer = sourceBuffer;
|
|
566
|
+
this.records = records;
|
|
567
|
+
}
|
|
568
|
+
static async fromURL(url) {
|
|
569
|
+
const response = await fetch(url);
|
|
570
|
+
if (!response.ok) {
|
|
571
|
+
throw new Error(`NvdbFile.fromURL: failed to fetch ${String(url)} (${response.status} ${response.statusText})`);
|
|
572
|
+
}
|
|
573
|
+
const buffer = await response.arrayBuffer();
|
|
574
|
+
return NvdbFile.fromArrayBuffer(buffer);
|
|
575
|
+
}
|
|
576
|
+
static fromArrayBuffer(buffer) {
|
|
577
|
+
const format = sniffFormat(buffer);
|
|
578
|
+
const records = format === "segment" ? parseSegments(buffer) : parseRawGridBuffer(buffer);
|
|
579
|
+
return new NvdbFile(buffer, records);
|
|
580
|
+
}
|
|
581
|
+
get grids() {
|
|
582
|
+
return this.records.map((r) => r.metadata);
|
|
583
|
+
}
|
|
584
|
+
/** Zero-copy u32 view of grid `i`'s image where the codec/alignment allows it. */
|
|
585
|
+
gridImage(i) {
|
|
586
|
+
return this.getRecord(i, "gridImage").image;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* True when `gridImage(i)` is a zero-copy view into the buffer originally
|
|
590
|
+
* passed to `fromArrayBuffer`/`fromURL`. False when a copy was required —
|
|
591
|
+
* either ZIP decompression, or a codec-NONE grid segment that landed on a
|
|
592
|
+
* non-4-byte-aligned offset (grid data follows a variable-length name, so
|
|
593
|
+
* alignment isn't guaranteed).
|
|
594
|
+
*/
|
|
595
|
+
isGridImageZeroCopy(i) {
|
|
596
|
+
return this.getRecord(i, "isGridImageZeroCopy").image.buffer === this.sourceBuffer;
|
|
597
|
+
}
|
|
598
|
+
getRecord(i, caller) {
|
|
599
|
+
const record = this.records[i];
|
|
600
|
+
if (!record) {
|
|
601
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `NvdbFile.${caller}: index ${i} out of range (file has ${this.records.length} grid(s))`);
|
|
602
|
+
}
|
|
603
|
+
return record;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
//# sourceMappingURL=nvdb-file.js.map
|