@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 @@
|
|
|
1
|
+
{"version":3,"file":"nvdb-file.js","sourceRoot":"","sources":["../../src/tools/nvdb-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAEtC,wEAAwE;AACxE,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAU,CAAC;AAEzE,oEAAoE;AACpE,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,CAAC;I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AAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["/**\n * `.nvdb` loader — Phase 1 (docs/archive/v1/PLAN.md), implementing the `NvdbFile`\n * contract from docs/archive/v1/SPEC.md §2.2: parse a `.nvdb` file (or a raw NanoVDB\n * grid buffer) into GPU-ready grid images — \"a valid NanoVDB grid image in\n * a flat u32 buffer\" (SPEC §1).\n *\n * Ground truth for every byte offset below is the C++ that wrote the test\n * fixtures:\n * - fixtures/downloads/openvdb-sparse/nanovdb/nanovdb/io/IO.h\n * (FileHeader/FileMetaData layout, Segment/Codec framing)\n * - fixtures/downloads/openvdb-sparse/nanovdb/nanovdb/NanoVDB.h\n * (magic numbers, Version packing, GridType/GridClass enums, GridData)\n * - vendor/stride-tables.json (extracted PNanoVDB.h defines: GridData,\n * TreeData and RootData offsets, ABI 32.9.1)\n *\n * ## `.nvdb` \"segment\" format (FileHeader magic `NanoVDB0`/`NanoVDB2`)\n *\n * FileHeader (16B), [FileMetaData (176B), gridName (nameSize B)] x gridCount,\n * [grid data (compressed per codec)] x gridCount\n *\n * A file is one or more such segments back to back (`io::Segment::write`\n * writes the header and every grid's metadata before the grids;\n * `writeGrids` writes one segment per GridHandle). With one grid per segment\n * the layout is FileHeader, FileMetaData, name, grid data.\n *\n * FileHeader (`struct FileHeader`, IO.h/NanoVDB.h, 16 bytes):\n *\n * field | offset | size | type\n * -----------|--------|------|------\n * magic | 0 | 8 | u64 (ASCII \"NanoVDB0\"/\"NanoVDB2\")\n * version | 8 | 4 | u32 (major<<21 | minor<<10 | patch)\n * gridCount | 12 | 2 | u16\n * codec | 14 | 2 | u16 (0=NONE, 1=ZIP, 2=BLOSC)\n *\n * FileMetaData (`struct FileMetaData`, NanoVDB.h, 176 bytes):\n *\n * field | offset | size | type\n * ----------------|--------|------|------\n * gridSize | 0 | 8 | u64 (decompressed grid image bytes)\n * fileSize | 8 | 8 | u64 (on-disk bytes incl. codec framing)\n * nameKey | 16 | 8 | u64 (io::stringHash(gridName))\n * voxelCount | 24 | 8 | u64 (active voxel count)\n * gridType | 32 | 4 | u32 (GridType enum)\n * gridClass | 36 | 4 | u32 (GridClass enum)\n * worldBBox.min | 40 | 24 | f64 x3\n * worldBBox.max | 64 | 24 | f64 x3\n * indexBBox.min | 88 | 12 | i32 x3\n * indexBBox.max | 100 | 12 | i32 x3\n * voxelSize | 112 | 24 | f64 x3\n * nameSize | 136 | 4 | u32 (grid name bytes, incl. NUL)\n * nodeCount[4] | 140 | 16 | u32 x4 (unused by this loader)\n * tileCount[3] | 156 | 12 | u32 x3 (unused by this loader)\n * codec | 168 | 2 | u16 (mirrors FileHeader.codec)\n * blindDataCount | 170 | 2 | u16 (unused by this loader)\n * version | 172 | 4 | u32\n * total: 176 bytes\n *\n * ## ZIP on-disk framing (`io::Internal::write`/`read`, IO.h)\n *\n * Per grid: an 8-byte little-endian u64 giving the *compressed* byte count,\n * followed by that many bytes of zlib-format (RFC 1950) compressed data —\n * i.e. exactly what C's `compress()`/`uncompress()` (and fflate's\n * `zlibSync`/`unzlibSync`) produce/consume. The decompressed length must\n * equal the grid's `gridSize` field. BLOSC uses the same 8-byte-prefixed\n * chunk framing but with blosc-compressed chunks; it is not implemented\n * (SPEC §7 non-goal) — callers get an actionable error instead.\n *\n * ## Raw grid buffer format (magic `NanoVDB1`, no FileHeader)\n *\n * The buffer starts directly with `GridData` (672 bytes, layout below, from\n * vendor/stride-tables.json), immediately followed by `TreeData` (64 bytes)\n * and then the rest of the tree. Multiple grids may be concatenated\n * (`GridData.mGridCount` grids total); each grid's byte length is its own\n * `mGridSize` field, so grids are found by walking `mGridSize` forward.\n * Raw buffers are always uncompressed.\n */\n\nimport { unzlibSync } from \"fflate\";\nimport { NvdbFormatError, VDBToolsError, VDBUnsupportedError } from \"./errors.js\";\n\nexport { NvdbFormatError } from \"./errors.js\";\n\n/** `.nvdb` FileHeader size in bytes (magic + version + grid count + codec). */\nexport const FILE_HEADER_SIZE = 16;\n\n/** Per-grid FileMetaData size in bytes (excluding the trailing grid name). */\nexport const FILE_METADATA_SIZE = 176;\n\n/** GridData block size in bytes (start of every NanoVDB grid image). */\nexport const GRID_DATA_SIZE = 672;\n\n/**\n * NanoVDB 8-byte magic strings: `NanoVDB0` = legacy file header / grid,\n * `NanoVDB1` = raw grid buffer, `NanoVDB2` = current file header. Sniffed\n * by `NvdbFile.fromArrayBuffer`.\n */\nexport const MAGIC_ASCII = [\"NanoVDB0\", \"NanoVDB1\", \"NanoVDB2\"] as const;\n\n/** File codecs we know about; v1 supports NONE and ZIP (fflate). */\nexport const NvdbCodec = {\n NONE: 0,\n ZIP: 1,\n BLOSC: 2,\n} as const;\nexport type NvdbCodec = (typeof NvdbCodec)[keyof typeof NvdbCodec];\n\n/** Grid types targeted for v1 (FogVolume rendering). */\nexport const NVDB_SUPPORTED_GRID_TYPES = [\"Float\", \"Fp4\", \"Fp8\", \"Fp16\", \"FpN\"] as const;\n\nexport interface NvdbGridMetadata {\n name: string;\n gridType: string;\n gridClass: string;\n worldBBox: { min: [number, number, number]; max: [number, number, number] };\n indexBBox: { min: [number, number, number]; max: [number, number, number] };\n voxelSize: [number, number, number];\n voxelCount: number;\n gridByteSize: number;\n}\n\n// ---------------------------------------------------------------------------\n// FileHeader / FileMetaData byte offsets (see module doc comment for the\n// full field table; these are the raw numbers used below).\n// ---------------------------------------------------------------------------\n\nconst FILE_HEADER_OFF_VERSION = 8;\nconst FILE_HEADER_OFF_GRID_COUNT = 12;\nconst FILE_HEADER_OFF_CODEC = 14;\n\nconst META_OFF_GRID_SIZE = 0;\nconst META_OFF_FILE_SIZE = 8;\nconst META_OFF_VOXEL_COUNT = 24;\nconst META_OFF_GRID_TYPE = 32;\nconst META_OFF_GRID_CLASS = 36;\nconst META_OFF_WORLD_BBOX_MIN = 40;\nconst META_OFF_WORLD_BBOX_MAX = 64;\nconst META_OFF_INDEX_BBOX_MIN = 88;\nconst META_OFF_INDEX_BBOX_MAX = 100;\nconst META_OFF_VOXEL_SIZE = 112;\nconst META_OFF_NAME_SIZE = 136;\n\n// ---------------------------------------------------------------------------\n// GridData / TreeData / RootData byte offsets, for the raw-grid-buffer path\n// (magic `NanoVDB1`). Values are the PNanoVDB.h defines baked into\n// vendor/stride-tables.json.\n// ---------------------------------------------------------------------------\n\nconst GRID_OFF_VERSION = 16;\nconst GRID_OFF_GRID_INDEX = 24;\nconst GRID_OFF_GRID_COUNT = 28;\nconst GRID_OFF_GRID_SIZE = 32;\nconst GRID_OFF_GRID_NAME = 40;\nconst GRID_NAME_MAX = 256; // GridData::MaxNameSize\nconst GRID_OFF_WORLD_BBOX = 560;\nconst GRID_OFF_VOXEL_SIZE = 608;\nconst GRID_OFF_GRID_CLASS = 632;\nconst GRID_OFF_GRID_TYPE = 636;\n\nconst TREE_SIZE = 64;\nconst TREE_OFF_NODE_OFFSET_ROOT = 24;\nconst TREE_OFF_VOXEL_COUNT = 56;\n\nconst ROOT_OFF_BBOX_MIN = 0;\nconst ROOT_OFF_BBOX_MAX = 12;\nconst ROOT_BASE_SIZE = 28;\n\n// ---------------------------------------------------------------------------\n// Small helpers\n// ---------------------------------------------------------------------------\n\nexport function requireBytes(buffer: ArrayBuffer, minLength: number, what: string): void {\n if (buffer.byteLength < minLength) {\n throw new NvdbFormatError(\n `NvdbFile: truncated buffer while reading ${what} ` +\n `(need ${minLength} bytes, buffer has ${buffer.byteLength})`,\n );\n }\n}\n\n/**\n * `gridSize` is read off a u64 (FileMetaData.gridSize / mGridSize); most of\n * the u64 range does not fit in a JS `number` without loss of precision. A\n * corrupt or malicious file can set that u64 to something outside\n * `Number.isSafeInteger` range, which would otherwise silently corrupt the\n * arithmetic used to slice/allocate the grid image (Finding 2). Guard it\n * before it's used for anything.\n */\nexport function assertSafeGridSize(gridSize: number, context: string): void {\n if (!Number.isSafeInteger(gridSize) || gridSize < 0) {\n throw new NvdbFormatError(\n `NvdbFile: ${context} has an unrepresentable gridSize (${gridSize}) — the on-disk u64 does not fit ` +\n `in a safe JS integer, so the file is corrupt or malicious.`,\n );\n }\n}\n\n/**\n * Cross-checks FileMetaData's declared `gridSize` (what the loader used to\n * slice/decompress the grid image) against the grid image's own internal\n * `GridData.mGridSize` (u64 at byte offset 32 of every grid image, see\n * NanoVDB.h). A file whose metadata lies (truncation, corruption, or a\n * malicious re-encode) would otherwise yield a silently short/long image and\n * silently wrong voxels downstream — Finding 1 from the T2 verification\n * pass. `gridBytes` must be at least `GRID_OFF_GRID_SIZE + 8` bytes for the\n * field to be readable; anything shorter is itself proof of a mismatch.\n */\nfunction checkInternalGridSize(gridBytes: Uint8Array, expectedGridSize: number, i: number, name: string): void {\n if (gridBytes.byteLength < GRID_OFF_GRID_SIZE + 8) {\n throw new NvdbFormatError(\n `NvdbFile: grid #${i} (\"${name}\") image is only ${gridBytes.byteLength} bytes — too short to contain ` +\n `a GridData header, so its internal mGridSize can't be verified against FileMetaData.gridSize ` +\n `(${expectedGridSize}). The file is corrupt or truncated.`,\n );\n }\n const view = new DataView(gridBytes.buffer, gridBytes.byteOffset, gridBytes.byteLength);\n const internalGridSize = Number(view.getBigUint64(GRID_OFF_GRID_SIZE, true));\n if (internalGridSize !== expectedGridSize) {\n throw new NvdbFormatError(\n `NvdbFile: grid #${i} (\"${name}\")'s FileMetaData.gridSize (${expectedGridSize}) does not match its ` +\n `own internal GridData.mGridSize (${internalGridSize}) — the file's metadata is inconsistent with its ` +\n `grid data (truncated or corrupted); refusing to load a possibly-wrong grid image.`,\n );\n }\n}\n\nexport function readMagic(buffer: ArrayBuffer, offset: number): string {\n const bytes = new Uint8Array(buffer, offset, 8);\n return String.fromCharCode(...bytes);\n}\n\nexport function decodeCString(bytes: Uint8Array): string {\n let end = bytes.indexOf(0);\n if (end < 0) end = bytes.length;\n return new TextDecoder().decode(bytes.subarray(0, end));\n}\n\n/** Packed NanoVDB `Version`: major<<21 | minor<<10 | patch. */\ninterface ParsedVersion {\n major: number;\n minor: number;\n patch: number;\n}\n\nfunction parseVersion(raw: number): ParsedVersion {\n return {\n major: (raw >>> 21) & 0x7ff,\n minor: (raw >>> 10) & 0x7ff,\n patch: raw & 0x3ff,\n };\n}\n\nfunction formatVersion(v: ParsedVersion): string {\n return `${v.major}.${v.minor}.${v.patch}`;\n}\n\n/** ABI major version this loader targets (vendor/stride-tables.json `$meta.abi` = \"32.9.1\"). */\nconst NANOVDB_MAJOR_VERSION = 32;\n\nexport function checkVersion(raw: number): ParsedVersion {\n const v = parseVersion(raw);\n if (v.major !== NANOVDB_MAJOR_VERSION) {\n throw new NvdbFormatError(\n `NvdbFile: incompatible NanoVDB version ${formatVersion(v)} ` +\n `(this loader targets NanoVDB ${NANOVDB_MAJOR_VERSION}.x). ` +\n `Re-export the file with a matching major version of NanoVDB.`,\n );\n }\n return v;\n}\n\n// GridType enum names (NanoVDB.h `enum class GridType`), indexed by id.\n// 21/22 are retired (IndexMask/OnIndexMask) and kept only as placeholders.\nconst GRID_TYPE_NAMES: readonly string[] = [\n \"Unknown\",\n \"Float\",\n \"Double\",\n \"Int16\",\n \"Int32\",\n \"Int64\",\n \"Vec3f\",\n \"Vec3d\",\n \"Mask\",\n \"Half\",\n \"UInt32\",\n \"Boolean\",\n \"RGBA8\",\n \"Fp4\",\n \"Fp8\",\n \"Fp16\",\n \"FpN\",\n \"Vec4f\",\n \"Vec4d\",\n \"Index\",\n \"OnIndex\",\n \"Retired21\",\n \"Retired22\",\n \"PointIndex\",\n \"Vec3u8\",\n \"Vec3u16\",\n \"UInt8\",\n \"End\",\n];\n\n// GridClass enum names (NanoVDB.h `enum class GridClass`), indexed by id.\nconst GRID_CLASS_NAMES: readonly string[] = [\n \"Unknown\",\n \"LevelSet\",\n \"FogVolume\",\n \"Staggered\",\n \"PointIndex\",\n \"PointData\",\n \"Topology\",\n \"VoxelVolume\",\n \"IndexGrid\",\n \"TensorGrid\",\n \"VoxelBVH\",\n \"End\",\n];\n\nexport function gridTypeName(id: number): string {\n return GRID_TYPE_NAMES[id] ?? `Unknown(${id})`;\n}\n\nexport function gridClassName(id: number): string {\n return GRID_CLASS_NAMES[id] ?? `Unknown(${id})`;\n}\n\nconst SUPPORTED_GRID_TYPES_SET: readonly string[] = NVDB_SUPPORTED_GRID_TYPES;\n\nexport function validateGridType(gridType: string, gridName: string): void {\n if (!SUPPORTED_GRID_TYPES_SET.includes(gridType)) {\n throw new VDBUnsupportedError(\n `NvdbFile: grid \"${gridName}\" is a ${gridType} grid, which this loader does not ` +\n `support — v1 only handles FogVolume grids of type ${NVDB_SUPPORTED_GRID_TYPES.join(\"/\")}. ` +\n `Re-export as float/fp4/fp8/fp16 (or fpn), e.g. \\`nanovdb_convert --fp8 in.vdb out.nvdb\\`.`,\n );\n }\n}\n\n/** Zero-copy u32 view when the input is already 4-byte aligned; a copy otherwise. */\nfunction u32View(bytes: Uint8Array): Uint32Array {\n if (bytes.byteOffset % 4 === 0 && bytes.byteLength % 4 === 0) {\n return new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);\n }\n const copy = bytes.slice(); // fresh ArrayBuffer, byteOffset 0\n return new Uint32Array(copy.buffer, copy.byteOffset, copy.byteLength / 4);\n}\n\nexport interface ParsedFileMetaData {\n gridSize: number;\n /** On-disk bytes of the grid's data including codec framing (FileMetaData.fileSize). */\n fileSize: number;\n voxelCount: number;\n gridTypeId: number;\n gridClassId: number;\n worldBBox: NvdbGridMetadata[\"worldBBox\"];\n indexBBox: NvdbGridMetadata[\"indexBBox\"];\n voxelSize: [number, number, number];\n nameSize: number;\n}\n\nexport function readFileMetaData(view: DataView, offset: number): ParsedFileMetaData {\n const gridSize = Number(view.getBigUint64(offset + META_OFF_GRID_SIZE, true));\n const fileSize = Number(view.getBigUint64(offset + META_OFF_FILE_SIZE, true));\n const voxelCount = Number(view.getBigUint64(offset + META_OFF_VOXEL_COUNT, true));\n const gridTypeId = view.getUint32(offset + META_OFF_GRID_TYPE, true);\n const gridClassId = view.getUint32(offset + META_OFF_GRID_CLASS, true);\n const worldBBox = {\n min: [\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN, true),\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN + 8, true),\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MIN + 16, true),\n ] as [number, number, number],\n max: [\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX, true),\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX + 8, true),\n view.getFloat64(offset + META_OFF_WORLD_BBOX_MAX + 16, true),\n ] as [number, number, number],\n };\n const indexBBox = {\n min: [\n view.getInt32(offset + META_OFF_INDEX_BBOX_MIN, true),\n view.getInt32(offset + META_OFF_INDEX_BBOX_MIN + 4, true),\n view.getInt32(offset + META_OFF_INDEX_BBOX_MIN + 8, true),\n ] as [number, number, number],\n max: [\n view.getInt32(offset + META_OFF_INDEX_BBOX_MAX, true),\n view.getInt32(offset + META_OFF_INDEX_BBOX_MAX + 4, true),\n view.getInt32(offset + META_OFF_INDEX_BBOX_MAX + 8, true),\n ] as [number, number, number],\n };\n const voxelSize: [number, number, number] = [\n view.getFloat64(offset + META_OFF_VOXEL_SIZE, true),\n view.getFloat64(offset + META_OFF_VOXEL_SIZE + 8, true),\n view.getFloat64(offset + META_OFF_VOXEL_SIZE + 16, true),\n ];\n const nameSize = view.getUint32(offset + META_OFF_NAME_SIZE, true);\n return { gridSize, fileSize, voxelCount, gridTypeId, gridClassId, worldBBox, indexBBox, voxelSize, nameSize };\n}\n\nexport interface GridRecord {\n metadata: NvdbGridMetadata;\n image: Uint32Array;\n}\n\n// ---------------------------------------------------------------------------\n// Segment format: FileHeader + [FileMetaData, gridName] x N + [grid data] x N,\n// one or more segments per file (io::Segment, IO.h)\n// ---------------------------------------------------------------------------\n\n/** Native file magics a segment's FileHeader may carry. */\nexport function isFileHeaderMagic(magic: string): boolean {\n return magic === \"NanoVDB2\" || magic === \"NanoVDB0\";\n}\n\n/** Checks a FileHeader's version and codec; returns its grid count and codec. */\nexport function readFileHeader(view: DataView, offset: number): { gridCount: number; codec: NvdbCodec } {\n checkVersion(view.getUint32(offset + FILE_HEADER_OFF_VERSION, true));\n const gridCount = view.getUint16(offset + FILE_HEADER_OFF_GRID_COUNT, true);\n const codec = view.getUint16(offset + FILE_HEADER_OFF_CODEC, true);\n if (codec === NvdbCodec.BLOSC) {\n throw new VDBUnsupportedError(\n \"NvdbFile: this file uses the BLOSC codec, which is not supported in the browser. \" +\n \"Re-export it with codec NONE or ZIP (e.g. `nanovdb_convert --codec=zip`).\",\n );\n }\n if (codec !== NvdbCodec.NONE && codec !== NvdbCodec.ZIP) {\n throw new NvdbFormatError(`NvdbFile: unknown codec value ${codec} in FileHeader`);\n }\n return { gridCount, codec: codec as NvdbCodec };\n}\n\n/**\n * Inflates one ZIP grid payload into exactly `gridSize` bytes, bounded\n * (Finding 2): a zip-bomb would otherwise inflate fully in memory before any\n * size check runs. fflate's `out` option makes inflate() write into a fixed\n * buffer and *truncate* rather than grow past it, so the output is\n * allocated at gridSize + 1 bytes: a well-formed payload lands at exactly\n * `gridSize` bytes, an oversized one is clamped to gridSize + 1 and rejected.\n */\nexport function inflateZipGrid(compressed: Uint8Array, gridSize: number, i: number, name: string): Uint8Array {\n // Cap the declared size before allocating: deflate cannot expand more than 1032:1, so a gridSize beyond\n // that bound for this payload is a lie (a tiny file declaring a huge grid would otherwise allocate it).\n if (gridSize > compressed.byteLength * 1032 + 64) {\n throw new NvdbFormatError(\n `NvdbFile: ZIP grid #${i} (\"${name}\") declares ${gridSize} bytes but its ${compressed.byteLength}-byte payload ` +\n `cannot inflate to more than ${compressed.byteLength * 1032 + 64} (deflate expands at most 1032:1) — the file's metadata is untrustworthy.`,\n );\n }\n const outBound = new Uint8Array(gridSize + 1);\n let decompressed: Uint8Array;\n try {\n decompressed = unzlibSync(compressed, { out: outBound });\n } catch (err) {\n throw new NvdbFormatError(`NvdbFile: failed to inflate ZIP-compressed grid #${i} (\"${name}\"): ${(err as Error).message}`);\n }\n if (decompressed.byteLength === outBound.length) {\n throw new NvdbFormatError(\n `NvdbFile: ZIP-decompressed grid #${i} (\"${name}\") exceeds its declared gridSize of ` +\n `${gridSize} bytes (decompression is bounded to gridSize + 1 bytes to avoid unbounded memory ` +\n `use on a corrupt or malicious file) — the file's metadata is untrustworthy.`,\n );\n }\n if (decompressed.byteLength !== gridSize) {\n throw new NvdbFormatError(\n `NvdbFile: ZIP-decompressed grid #${i} (\"${name}\") is ${decompressed.byteLength} ` +\n `bytes, expected ${gridSize}`,\n );\n }\n return decompressed;\n}\n\n/** Runs the shared checks on a decoded grid image and builds its record. */\nexport function finishGridRecord(meta: ParsedFileMetaData, name: string, i: number, gridBytes: Uint8Array): GridRecord {\n checkInternalGridSize(gridBytes, meta.gridSize, i, name);\n const gridType = gridTypeName(meta.gridTypeId);\n const gridClass = gridClassName(meta.gridClassId);\n validateGridType(gridType, name);\n return {\n metadata: {\n name,\n gridType,\n gridClass,\n worldBBox: meta.worldBBox,\n indexBBox: meta.indexBBox,\n voxelSize: meta.voxelSize,\n voxelCount: meta.voxelCount,\n gridByteSize: meta.gridSize,\n },\n image: u32View(gridBytes),\n };\n}\n\n/**\n * A segment is a FileHeader, then every grid's FileMetaData + name, then every\n * grid's data in the same order (`Segment::write` writes the header and all\n * metadata, then `Internal::write` writes each grid). A file is one or more\n * segments back to back (`writeGrids` writes one per GridHandle); grids are\n * numbered across segments. With one grid per segment the layout is\n * FileHeader, FileMetaData, name, grid data.\n */\nfunction parseSegments(buffer: ArrayBuffer): GridRecord[] {\n const view = new DataView(buffer);\n const records: GridRecord[] = [];\n let offset = 0;\n\n do {\n requireBytes(buffer, offset + FILE_HEADER_SIZE, \"FileHeader\");\n if (offset > 0 && !isFileHeaderMagic(readMagic(buffer, offset))) {\n throw new NvdbFormatError(\n `NvdbFile: the ${buffer.byteLength - offset} bytes after byte ${offset} are not another segment ` +\n `(magic \"${readMagic(buffer, offset)}\"); the file is corrupt.`,\n );\n }\n const { gridCount, codec } = readFileHeader(view, offset);\n offset += FILE_HEADER_SIZE;\n\n const first = records.length;\n const metas: { meta: ParsedFileMetaData; name: string }[] = [];\n for (let k = 0; k < gridCount; k++) {\n const i = first + k;\n requireBytes(buffer, offset + FILE_METADATA_SIZE, `FileMetaData for grid #${i}`);\n const meta = readFileMetaData(view, offset);\n offset += FILE_METADATA_SIZE;\n requireBytes(buffer, offset + meta.nameSize, `grid name for grid #${i}`);\n const name = decodeCString(new Uint8Array(buffer, offset, meta.nameSize));\n offset += meta.nameSize;\n assertSafeGridSize(meta.gridSize, `grid #${i} (\"${name}\")'s FileMetaData.gridSize`);\n metas.push({ meta, name });\n }\n\n for (let k = 0; k < gridCount; k++) {\n const i = first + k;\n const { meta, name } = metas[k]!;\n let gridBytes: Uint8Array;\n if (codec === NvdbCodec.NONE) {\n requireBytes(buffer, offset + meta.gridSize, `grid data for grid #${i} (\"${name}\")`);\n gridBytes = new Uint8Array(buffer, offset, meta.gridSize);\n offset += meta.gridSize;\n } else {\n // Codec.ZIP: 8-byte LE compressed-size prefix, then that many bytes of\n // zlib (RFC 1950) compressed data (io::Internal::write/read, IO.h).\n requireBytes(buffer, offset + 8, `ZIP size prefix for grid #${i} (\"${name}\")`);\n const compressedSize = Number(view.getBigUint64(offset, true));\n offset += 8;\n requireBytes(buffer, offset + compressedSize, `ZIP payload for grid #${i} (\"${name}\")`);\n gridBytes = inflateZipGrid(new Uint8Array(buffer, offset, compressedSize), meta.gridSize, i, name);\n offset += compressedSize;\n }\n records.push(finishGridRecord(meta, name, i, gridBytes));\n }\n } while (offset < buffer.byteLength);\n\n return records;\n}\n\n// ---------------------------------------------------------------------------\n// Raw grid buffer format: GridData [+ TreeData + ...] x N, no FileHeader\n// ---------------------------------------------------------------------------\n\nfunction parseRawGridBuffer(buffer: ArrayBuffer): GridRecord[] {\n const view = new DataView(buffer);\n const records: GridRecord[] = [];\n\n let offset = 0;\n let index = 0;\n let expectedCount: number | undefined;\n\n while (offset < buffer.byteLength) {\n requireBytes(buffer, offset + GRID_DATA_SIZE, `GridData for grid #${index}`);\n const magic = readMagic(buffer, offset);\n if (magic !== \"NanoVDB1\" && magic !== \"NanoVDB0\") {\n throw new NvdbFormatError(`NvdbFile: expected a grid magic at byte ${offset}, found \"${magic}\"`);\n }\n checkVersion(view.getUint32(offset + GRID_OFF_VERSION, true));\n\n const gridCount = view.getUint32(offset + GRID_OFF_GRID_COUNT, true);\n expectedCount ??= gridCount;\n void view.getUint32(offset + GRID_OFF_GRID_INDEX, true); // mGridIndex, unused\n\n const gridSize = Number(view.getBigUint64(offset + GRID_OFF_GRID_SIZE, true));\n requireBytes(buffer, offset + gridSize, `grid image for grid #${index}`);\n\n const name = decodeCString(new Uint8Array(buffer, offset + GRID_OFF_GRID_NAME, GRID_NAME_MAX));\n\n const gridTypeId = view.getUint32(offset + GRID_OFF_GRID_TYPE, true);\n const gridClassId = view.getUint32(offset + GRID_OFF_GRID_CLASS, true);\n const worldBBox = {\n min: [\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX, true),\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 8, true),\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 16, true),\n ] as [number, number, number],\n max: [\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 24, true),\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 32, true),\n view.getFloat64(offset + GRID_OFF_WORLD_BBOX + 40, true),\n ] as [number, number, number],\n };\n const voxelSize: [number, number, number] = [\n view.getFloat64(offset + GRID_OFF_VOXEL_SIZE, true),\n view.getFloat64(offset + GRID_OFF_VOXEL_SIZE + 8, true),\n view.getFloat64(offset + GRID_OFF_VOXEL_SIZE + 16, true),\n ];\n\n const treeOffset = offset + GRID_DATA_SIZE;\n requireBytes(buffer, treeOffset + TREE_SIZE, `TreeData for grid #${index}`);\n const voxelCount = Number(view.getBigUint64(treeOffset + TREE_OFF_VOXEL_COUNT, true));\n const nodeOffsetRoot = Number(view.getBigUint64(treeOffset + TREE_OFF_NODE_OFFSET_ROOT, true));\n const rootOffset = treeOffset + nodeOffsetRoot;\n requireBytes(buffer, rootOffset + ROOT_BASE_SIZE, `RootData bbox for grid #${index}`);\n const indexBBox = {\n min: [\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN, true),\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN + 4, true),\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MIN + 8, true),\n ] as [number, number, number],\n max: [\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX, true),\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX + 4, true),\n view.getInt32(rootOffset + ROOT_OFF_BBOX_MAX + 8, true),\n ] as [number, number, number],\n };\n\n const gridType = gridTypeName(gridTypeId);\n const gridClass = gridClassName(gridClassId);\n validateGridType(gridType, name);\n\n const gridBytes = new Uint8Array(buffer, offset, gridSize);\n records.push({\n metadata: {\n name,\n gridType,\n gridClass,\n worldBBox,\n indexBBox,\n voxelSize,\n voxelCount,\n gridByteSize: gridSize,\n },\n image: u32View(gridBytes),\n });\n\n offset += gridSize;\n index += 1;\n if (expectedCount !== undefined && index >= expectedCount) break;\n }\n\n return records;\n}\n\n// ---------------------------------------------------------------------------\n// Top-level format sniff + public API\n// ---------------------------------------------------------------------------\n\nfunction sniffFormat(buffer: ArrayBuffer): \"segment\" | \"raw\" {\n requireBytes(buffer, 8, \"the NanoVDB magic\");\n const magic = readMagic(buffer, 0);\n // \"NanoVDB0\" is genuinely ambiguous pre-v32.6 (used for both FileHeader and\n // raw GridData); we treat it as a (legacy) FileHeader, matching the plain\n // reading \"legacy files use NanoVDB0\" — none of our fixtures exercise this.\n if (magic === \"NanoVDB2\" || magic === \"NanoVDB0\") return \"segment\";\n if (magic === \"NanoVDB1\") return \"raw\";\n throw new NvdbFormatError(\n `NvdbFile: unrecognized magic \"${magic}\" at byte 0 (expected one of ` +\n `${MAGIC_ASCII.join(\", \")}) — this does not look like a NanoVDB file.`,\n );\n}\n\n/**\n * Parses a `.nvdb` file (or raw grid buffer) and exposes GPU-ready grid\n * images as flat u32 views — \"a valid NanoVDB grid image in a flat u32\n * buffer\" is the single contract between the CPU and GPU halves (SPEC §1).\n */\nexport class NvdbFile {\n private readonly records: readonly GridRecord[];\n private readonly sourceBuffer: ArrayBuffer;\n\n private constructor(sourceBuffer: ArrayBuffer, records: readonly GridRecord[]) {\n this.sourceBuffer = sourceBuffer;\n this.records = records;\n }\n\n static async fromURL(url: string | URL): Promise<NvdbFile> {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(\n `NvdbFile.fromURL: failed to fetch ${String(url)} (${response.status} ${response.statusText})`,\n );\n }\n const buffer = await response.arrayBuffer();\n return NvdbFile.fromArrayBuffer(buffer);\n }\n\n static fromArrayBuffer(buffer: ArrayBuffer): NvdbFile {\n const format = sniffFormat(buffer);\n const records = format === \"segment\" ? parseSegments(buffer) : parseRawGridBuffer(buffer);\n return new NvdbFile(buffer, records);\n }\n\n get grids(): readonly NvdbGridMetadata[] {\n return this.records.map((r) => r.metadata);\n }\n\n /** Zero-copy u32 view of grid `i`'s image where the codec/alignment allows it. */\n gridImage(i: number): Uint32Array {\n return this.getRecord(i, \"gridImage\").image;\n }\n\n /**\n * True when `gridImage(i)` is a zero-copy view into the buffer originally\n * passed to `fromArrayBuffer`/`fromURL`. False when a copy was required —\n * either ZIP decompression, or a codec-NONE grid segment that landed on a\n * non-4-byte-aligned offset (grid data follows a variable-length name, so\n * alignment isn't guaranteed).\n */\n isGridImageZeroCopy(i: number): boolean {\n return this.getRecord(i, \"isGridImageZeroCopy\").image.buffer === this.sourceBuffer;\n }\n\n private getRecord(i: number, caller: string): GridRecord {\n const record = this.records[i];\n if (!record) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `NvdbFile.${caller}: index ${i} out of range (file has ${this.records.length} grid(s))`);\n }\n return record;\n }\n}\n"]}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `NvdbStreamReader` (K4.16): read a `.nvdb` file from pushed bytes and emit
|
|
3
|
+
* each grid as soon as its data is complete, so a coarse preview written first
|
|
4
|
+
* (docs/dev/design/K4-5-coarse-first.md, option a) can be drawn while the full
|
|
5
|
+
* grid is still downloading.
|
|
6
|
+
*
|
|
7
|
+
* const reader = new NvdbStreamReader();
|
|
8
|
+
* for await (const chunk of response.body) for (const g of reader.push(chunk)) show(g);
|
|
9
|
+
* reader.end(); // throws if the stream stopped mid-grid
|
|
10
|
+
*
|
|
11
|
+
* The framing is NanoVDB's `io::Segment` (IO.h; see `nvdb-file.ts`): a 16-byte
|
|
12
|
+
* FileHeader, then a 176-byte FileMetaData + name per grid, then each grid's
|
|
13
|
+
* data (the image for codec NONE; a u64 size + zlib stream for codec ZIP). A
|
|
14
|
+
* file is one or more segments. Every size the reader allocates is declared
|
|
15
|
+
* up front, so it checks each one before allocating:
|
|
16
|
+
*
|
|
17
|
+
* - `gridSize` must be a safe integer, at least a GridData header, and at most
|
|
18
|
+
* `maxGridBytes` (default 1 GiB);
|
|
19
|
+
* - a ZIP payload must be at most zlib's `compressBound(gridSize)` (+64), and
|
|
20
|
+
* inflates into gridSize + 1 bytes at most (`inflateZipGrid`);
|
|
21
|
+
* - a grid name is at most `maxNameBytes` (default 64 KiB).
|
|
22
|
+
*
|
|
23
|
+
* Memory: the reader holds the current segment's metadata and the grid it is
|
|
24
|
+
* filling, never the whole file. Emitted images are handed off (a fresh buffer
|
|
25
|
+
* per grid, 4-byte aligned, so `image` is a zero-copy `Uint32Array`).
|
|
26
|
+
*
|
|
27
|
+
* Errors are `NvdbFormatError` (a `VDBToolsError`) for malformed or
|
|
28
|
+
* truncated data and `VDBUnsupportedError` for valid data out of scope
|
|
29
|
+
* (BLOSC, a raw `NanoVDB1` grid buffer, unsupported grid types). After an
|
|
30
|
+
* error the reader is failed: every later `push` rethrows it.
|
|
31
|
+
*/
|
|
32
|
+
import { NvdbFormatError } from "./errors.js";
|
|
33
|
+
import { type NvdbGridMetadata } from "./nvdb-file.js";
|
|
34
|
+
export { NvdbFormatError };
|
|
35
|
+
export interface NvdbStreamReaderOptions {
|
|
36
|
+
/** Largest `gridSize` (decoded image bytes) the reader allocates. Default 1 GiB. */
|
|
37
|
+
maxGridBytes?: number;
|
|
38
|
+
/** Largest grid name (FileMetaData.nameSize). Default 64 KiB. */
|
|
39
|
+
maxNameBytes?: number;
|
|
40
|
+
/**
|
|
41
|
+
* The whole stream's size in bytes when the caller knows it (a Response's
|
|
42
|
+
* Content-Length: see {@link nvdbResponseLength}). Takes precedence over the
|
|
43
|
+
* size derived from the grids' FileMetaData.
|
|
44
|
+
*/
|
|
45
|
+
bytesTotal?: number;
|
|
46
|
+
/** Called after every `push` with the progress so far (not inside the push's error handling). */
|
|
47
|
+
onProgress?: (progress: NvdbProgress) => void;
|
|
48
|
+
}
|
|
49
|
+
/** Download progress of an {@link NvdbStreamReader}. */
|
|
50
|
+
export interface NvdbProgress {
|
|
51
|
+
/** File bytes pushed so far (what the reader consumed; decoded bytes if the transport decompresses). */
|
|
52
|
+
bytesReceived: number;
|
|
53
|
+
/**
|
|
54
|
+
* The expected total, or null while unknown: the `bytesTotal` option when
|
|
55
|
+
* given, else the end of the latest segment whose FileMetaData have all
|
|
56
|
+
* arrived (header + every grid's metadata, name and `fileSize`). That is
|
|
57
|
+
* exact for a one-segment file and a lower bound while a later segment is
|
|
58
|
+
* still ahead. Null until the first segment's metadata is in.
|
|
59
|
+
*/
|
|
60
|
+
bytesTotal: number | null;
|
|
61
|
+
/** Grids emitted so far. */
|
|
62
|
+
gridsEmitted: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The byte length of a `fetch` Response's body when the header says so: its
|
|
66
|
+
* Content-Length, unless a Content-Encoding makes the (decoded) bytes the
|
|
67
|
+
* reader sees differ from it. Null when unknown.
|
|
68
|
+
*/
|
|
69
|
+
export declare function nvdbResponseLength(response: {
|
|
70
|
+
headers: {
|
|
71
|
+
get(name: string): string | null;
|
|
72
|
+
};
|
|
73
|
+
}): number | null;
|
|
74
|
+
/** One grid, emitted by {@link NvdbStreamReader.push} as soon as its data is complete. */
|
|
75
|
+
export interface NvdbStreamGrid {
|
|
76
|
+
/** Grid number in the file (counted across segments). */
|
|
77
|
+
index: number;
|
|
78
|
+
metadata: NvdbGridMetadata;
|
|
79
|
+
/** The decoded grid image (zero-copy view of a buffer of its own). */
|
|
80
|
+
image: Uint32Array;
|
|
81
|
+
/** File bytes pushed when this grid completed (the end of its data). */
|
|
82
|
+
bytesReceived: number;
|
|
83
|
+
/** The expected file size when this grid completed, or null if unknown (see {@link NvdbProgress.bytesTotal}). */
|
|
84
|
+
bytesTotal: number | null;
|
|
85
|
+
/** The preview level from a `<name>.lod<N>` name, or null for a full grid. */
|
|
86
|
+
lod: number | null;
|
|
87
|
+
/** The name without its `.lod<N>` suffix (the full grid's name). */
|
|
88
|
+
baseName: string;
|
|
89
|
+
}
|
|
90
|
+
/** The preview name for `name` at `resolution`: `<name>.lod<resolution>` (K4.5). */
|
|
91
|
+
export declare function nvdbLodName(name: string, resolution: number): string;
|
|
92
|
+
/** Splits a `<name>.lod<N>` preview name; a full grid's name gives `lod: null`. */
|
|
93
|
+
export declare function parseNvdbLodName(name: string): {
|
|
94
|
+
baseName: string;
|
|
95
|
+
lod: number | null;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Push-based `.nvdb` reader: `push(chunk)` returns the grids that chunk
|
|
99
|
+
* completed. Call `end()` when the stream ends to detect truncation.
|
|
100
|
+
*/
|
|
101
|
+
export declare class NvdbStreamReader {
|
|
102
|
+
#private;
|
|
103
|
+
constructor(options?: NvdbStreamReaderOptions);
|
|
104
|
+
/** The expected file size in bytes, or null while unknown (see {@link NvdbProgress.bytesTotal}). */
|
|
105
|
+
get bytesTotal(): number | null;
|
|
106
|
+
/** Progress so far. */
|
|
107
|
+
get progress(): NvdbProgress;
|
|
108
|
+
/** File bytes pushed so far. */
|
|
109
|
+
get bytesReceived(): number;
|
|
110
|
+
/** Grids emitted so far. */
|
|
111
|
+
get gridsEmitted(): number;
|
|
112
|
+
/**
|
|
113
|
+
* Metadata of every grid whose FileMetaData has arrived, in file order,
|
|
114
|
+
* including grids whose data has not (a segment lists all its grids before
|
|
115
|
+
* any data, so the full grid's `gridByteSize` is known before its preview
|
|
116
|
+
* is emitted). Names are as stored; see {@link parseNvdbLodName}.
|
|
117
|
+
*/
|
|
118
|
+
get grids(): readonly NvdbGridMetadata[];
|
|
119
|
+
/** True between segments: every grid announced so far has been emitted. */
|
|
120
|
+
get atBoundary(): boolean;
|
|
121
|
+
/** Pushes the next bytes of the file; returns the grids they completed, in order. */
|
|
122
|
+
push(chunk: Uint8Array): NvdbStreamGrid[];
|
|
123
|
+
/** Declares the end of the stream; throws `NvdbFormatError` if it stopped inside a segment. */
|
|
124
|
+
end(): void;
|
|
125
|
+
}
|
|
126
|
+
/** What {@link readNvdbStream} reads: a `fetch` Response (its Content-Length feeds `bytesTotal`), its body, or chunks. */
|
|
127
|
+
export type NvdbStreamSource = {
|
|
128
|
+
body: ReadableStream<Uint8Array> | null;
|
|
129
|
+
headers: {
|
|
130
|
+
get(name: string): string | null;
|
|
131
|
+
};
|
|
132
|
+
} | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
133
|
+
/**
|
|
134
|
+
* Reads a byte stream (a `fetch` Response or body, or any async iterable of chunks) through
|
|
135
|
+
* an {@link NvdbStreamReader}, yielding each grid as it completes. Stops
|
|
136
|
+
* reading (and cancels the stream) when the consumer breaks out of the loop.
|
|
137
|
+
*/
|
|
138
|
+
export declare function readNvdbStream(source: NvdbStreamSource, options?: NvdbStreamReaderOptions): AsyncGenerator<NvdbStreamGrid, void, undefined>;
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `NvdbStreamReader` (K4.16): read a `.nvdb` file from pushed bytes and emit
|
|
3
|
+
* each grid as soon as its data is complete, so a coarse preview written first
|
|
4
|
+
* (docs/dev/design/K4-5-coarse-first.md, option a) can be drawn while the full
|
|
5
|
+
* grid is still downloading.
|
|
6
|
+
*
|
|
7
|
+
* const reader = new NvdbStreamReader();
|
|
8
|
+
* for await (const chunk of response.body) for (const g of reader.push(chunk)) show(g);
|
|
9
|
+
* reader.end(); // throws if the stream stopped mid-grid
|
|
10
|
+
*
|
|
11
|
+
* The framing is NanoVDB's `io::Segment` (IO.h; see `nvdb-file.ts`): a 16-byte
|
|
12
|
+
* FileHeader, then a 176-byte FileMetaData + name per grid, then each grid's
|
|
13
|
+
* data (the image for codec NONE; a u64 size + zlib stream for codec ZIP). A
|
|
14
|
+
* file is one or more segments. Every size the reader allocates is declared
|
|
15
|
+
* up front, so it checks each one before allocating:
|
|
16
|
+
*
|
|
17
|
+
* - `gridSize` must be a safe integer, at least a GridData header, and at most
|
|
18
|
+
* `maxGridBytes` (default 1 GiB);
|
|
19
|
+
* - a ZIP payload must be at most zlib's `compressBound(gridSize)` (+64), and
|
|
20
|
+
* inflates into gridSize + 1 bytes at most (`inflateZipGrid`);
|
|
21
|
+
* - a grid name is at most `maxNameBytes` (default 64 KiB).
|
|
22
|
+
*
|
|
23
|
+
* Memory: the reader holds the current segment's metadata and the grid it is
|
|
24
|
+
* filling, never the whole file. Emitted images are handed off (a fresh buffer
|
|
25
|
+
* per grid, 4-byte aligned, so `image` is a zero-copy `Uint32Array`).
|
|
26
|
+
*
|
|
27
|
+
* Errors are `NvdbFormatError` (a `VDBToolsError`) for malformed or
|
|
28
|
+
* truncated data and `VDBUnsupportedError` for valid data out of scope
|
|
29
|
+
* (BLOSC, a raw `NanoVDB1` grid buffer, unsupported grid types). After an
|
|
30
|
+
* error the reader is failed: every later `push` rethrows it.
|
|
31
|
+
*/
|
|
32
|
+
import { NvdbFormatError, VDBToolsError, VDBUnsupportedError } from "./errors.js";
|
|
33
|
+
import { NvdbCodec, FILE_HEADER_SIZE, FILE_METADATA_SIZE, GRID_DATA_SIZE, assertSafeGridSize, decodeCString, finishGridRecord, gridClassName, gridTypeName, inflateZipGrid, isFileHeaderMagic, readFileHeader, readFileMetaData, validateGridType, } from "./nvdb-file.js";
|
|
34
|
+
export { NvdbFormatError };
|
|
35
|
+
/**
|
|
36
|
+
* The byte length of a `fetch` Response's body when the header says so: its
|
|
37
|
+
* Content-Length, unless a Content-Encoding makes the (decoded) bytes the
|
|
38
|
+
* reader sees differ from it. Null when unknown.
|
|
39
|
+
*/
|
|
40
|
+
export function nvdbResponseLength(response) {
|
|
41
|
+
const encoding = response.headers.get("content-encoding");
|
|
42
|
+
if (encoding !== null && encoding.trim() !== "" && encoding.trim().toLowerCase() !== "identity")
|
|
43
|
+
return null;
|
|
44
|
+
const raw = response.headers.get("content-length");
|
|
45
|
+
if (raw === null || !/^\d+$/.test(raw.trim()))
|
|
46
|
+
return null;
|
|
47
|
+
const n = Number(raw);
|
|
48
|
+
return Number.isSafeInteger(n) ? n : null;
|
|
49
|
+
}
|
|
50
|
+
const DEFAULT_MAX_GRID_BYTES = 1 << 30;
|
|
51
|
+
const DEFAULT_MAX_NAME_BYTES = 1 << 16;
|
|
52
|
+
const ZIP_PREFIX = 8;
|
|
53
|
+
/** zlib's `compressBound` (the largest `compress()` output for `n` input bytes), plus slack. */
|
|
54
|
+
function zipBound(n) {
|
|
55
|
+
return n + Math.floor(n / 4096) + Math.floor(n / 16384) + Math.floor(n / 33554432) + 13 + 64;
|
|
56
|
+
}
|
|
57
|
+
const LOD_SUFFIX = /^(.*)\.lod(\d+)$/;
|
|
58
|
+
/** The preview name for `name` at `resolution`: `<name>.lod<resolution>` (K4.5). */
|
|
59
|
+
export function nvdbLodName(name, resolution) {
|
|
60
|
+
if (!Number.isInteger(resolution) || resolution < 1) {
|
|
61
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `nvdbLodName: resolution must be a positive integer, got ${resolution}`);
|
|
62
|
+
}
|
|
63
|
+
return `${name}.lod${resolution}`;
|
|
64
|
+
}
|
|
65
|
+
/** Splits a `<name>.lod<N>` preview name; a full grid's name gives `lod: null`. */
|
|
66
|
+
export function parseNvdbLodName(name) {
|
|
67
|
+
const m = LOD_SUFFIX.exec(name);
|
|
68
|
+
return m ? { baseName: m[1], lod: Number(m[2]) } : { baseName: name, lod: null };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Push-based `.nvdb` reader: `push(chunk)` returns the grids that chunk
|
|
72
|
+
* completed. Call `end()` when the stream ends to detect truncation.
|
|
73
|
+
*/
|
|
74
|
+
export class NvdbStreamReader {
|
|
75
|
+
#maxGridBytes;
|
|
76
|
+
#maxNameBytes;
|
|
77
|
+
#onProgress;
|
|
78
|
+
#declaredTotal;
|
|
79
|
+
#segmentStart = 0;
|
|
80
|
+
#knownEnd = null;
|
|
81
|
+
/** Small fixed-size fields (FileHeader, FileMetaData, ZIP prefix) and names. */
|
|
82
|
+
#scratch = new Uint8Array(FILE_METADATA_SIZE);
|
|
83
|
+
/** The buffer being filled (scratch or a grid payload) and how far. */
|
|
84
|
+
#target;
|
|
85
|
+
#filled = 0;
|
|
86
|
+
#phase = "header";
|
|
87
|
+
#codec = NvdbCodec.NONE;
|
|
88
|
+
#segmentGrids = 0;
|
|
89
|
+
#pending = [];
|
|
90
|
+
#nextMeta = null;
|
|
91
|
+
#gridInSegment = 0;
|
|
92
|
+
#received = 0;
|
|
93
|
+
#segments = 0;
|
|
94
|
+
#emitted = 0;
|
|
95
|
+
#failed = null;
|
|
96
|
+
#grids = [];
|
|
97
|
+
constructor(options = {}) {
|
|
98
|
+
this.#maxGridBytes = options.maxGridBytes ?? DEFAULT_MAX_GRID_BYTES;
|
|
99
|
+
this.#maxNameBytes = options.maxNameBytes ?? DEFAULT_MAX_NAME_BYTES;
|
|
100
|
+
if (!Number.isSafeInteger(this.#maxGridBytes) || this.#maxGridBytes < GRID_DATA_SIZE) {
|
|
101
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `NvdbStreamReader: maxGridBytes must be an integer >= ${GRID_DATA_SIZE}`);
|
|
102
|
+
}
|
|
103
|
+
if (!Number.isSafeInteger(this.#maxNameBytes) || this.#maxNameBytes < 1) {
|
|
104
|
+
throw new VDBToolsError("VDB_BAD_OPTION", "NvdbStreamReader: maxNameBytes must be a positive integer");
|
|
105
|
+
}
|
|
106
|
+
this.#onProgress = options.onProgress;
|
|
107
|
+
this.#declaredTotal = options.bytesTotal ?? null;
|
|
108
|
+
if (this.#declaredTotal !== null && (!Number.isSafeInteger(this.#declaredTotal) || this.#declaredTotal < 0)) {
|
|
109
|
+
throw new VDBToolsError("VDB_BAD_OPTION", "NvdbStreamReader: bytesTotal must be a non-negative integer");
|
|
110
|
+
}
|
|
111
|
+
this.#target = this.#scratch.subarray(0, FILE_HEADER_SIZE);
|
|
112
|
+
}
|
|
113
|
+
/** The expected file size in bytes, or null while unknown (see {@link NvdbProgress.bytesTotal}). */
|
|
114
|
+
get bytesTotal() {
|
|
115
|
+
return this.#declaredTotal ?? this.#knownEnd;
|
|
116
|
+
}
|
|
117
|
+
/** Progress so far. */
|
|
118
|
+
get progress() {
|
|
119
|
+
return { bytesReceived: this.#received, bytesTotal: this.bytesTotal, gridsEmitted: this.#emitted };
|
|
120
|
+
}
|
|
121
|
+
/** File bytes pushed so far. */
|
|
122
|
+
get bytesReceived() {
|
|
123
|
+
return this.#received;
|
|
124
|
+
}
|
|
125
|
+
/** Grids emitted so far. */
|
|
126
|
+
get gridsEmitted() {
|
|
127
|
+
return this.#emitted;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Metadata of every grid whose FileMetaData has arrived, in file order,
|
|
131
|
+
* including grids whose data has not (a segment lists all its grids before
|
|
132
|
+
* any data, so the full grid's `gridByteSize` is known before its preview
|
|
133
|
+
* is emitted). Names are as stored; see {@link parseNvdbLodName}.
|
|
134
|
+
*/
|
|
135
|
+
get grids() {
|
|
136
|
+
return this.#grids;
|
|
137
|
+
}
|
|
138
|
+
/** True between segments: every grid announced so far has been emitted. */
|
|
139
|
+
get atBoundary() {
|
|
140
|
+
return this.#phase === "header" && this.#filled === 0 && this.#segments > 0;
|
|
141
|
+
}
|
|
142
|
+
/** Pushes the next bytes of the file; returns the grids they completed, in order. */
|
|
143
|
+
push(chunk) {
|
|
144
|
+
if (this.#failed)
|
|
145
|
+
throw this.#failed;
|
|
146
|
+
const out = [];
|
|
147
|
+
try {
|
|
148
|
+
let at = 0;
|
|
149
|
+
while (at < chunk.byteLength) {
|
|
150
|
+
const take = Math.min(chunk.byteLength - at, this.#target.byteLength - this.#filled);
|
|
151
|
+
this.#target.set(chunk.subarray(at, at + take), this.#filled);
|
|
152
|
+
this.#filled += take;
|
|
153
|
+
at += take;
|
|
154
|
+
this.#received += take;
|
|
155
|
+
if (this.#filled === this.#target.byteLength)
|
|
156
|
+
this.#advance(out);
|
|
157
|
+
}
|
|
158
|
+
// A zero-length target (an empty name) completes without bytes.
|
|
159
|
+
while (this.#target.byteLength === 0 && this.#filled === 0 && this.#phase !== "header")
|
|
160
|
+
this.#advance(out);
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
this.#failed = err instanceof VDBToolsError ? err : new NvdbFormatError(err.message);
|
|
164
|
+
throw this.#failed;
|
|
165
|
+
}
|
|
166
|
+
if (this.#onProgress && chunk.byteLength > 0)
|
|
167
|
+
this.#onProgress(this.progress);
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
/** Declares the end of the stream; throws `NvdbFormatError` if it stopped inside a segment. */
|
|
171
|
+
end() {
|
|
172
|
+
if (this.#failed)
|
|
173
|
+
throw this.#failed;
|
|
174
|
+
if (this.atBoundary)
|
|
175
|
+
return;
|
|
176
|
+
this.#failed = new NvdbFormatError(`the stream ended after ${this.#received} bytes, in the ${this.#describe()}; the file is truncated.`);
|
|
177
|
+
throw this.#failed;
|
|
178
|
+
}
|
|
179
|
+
#describe() {
|
|
180
|
+
const grid = this.#segmentFirst() + this.#gridInSegment;
|
|
181
|
+
switch (this.#phase) {
|
|
182
|
+
case "header":
|
|
183
|
+
return `FileHeader, ${this.#filled} of ${FILE_HEADER_SIZE} bytes`;
|
|
184
|
+
case "meta":
|
|
185
|
+
return `FileMetaData of grid #${this.#grids.length}, ${this.#filled} of ${FILE_METADATA_SIZE} bytes`;
|
|
186
|
+
case "name":
|
|
187
|
+
return `name of grid #${this.#grids.length}`;
|
|
188
|
+
case "zipPrefix":
|
|
189
|
+
return `ZIP size prefix of grid #${grid}`;
|
|
190
|
+
case "grid":
|
|
191
|
+
return `data of grid #${grid}, ${this.#filled} of ${this.#target.byteLength} bytes`;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
#segmentFirst() {
|
|
195
|
+
return this.#grids.length - this.#segmentGrids;
|
|
196
|
+
}
|
|
197
|
+
#expect(phase, target) {
|
|
198
|
+
this.#phase = phase;
|
|
199
|
+
this.#target = target;
|
|
200
|
+
this.#filled = 0;
|
|
201
|
+
}
|
|
202
|
+
#advance(out) {
|
|
203
|
+
switch (this.#phase) {
|
|
204
|
+
case "header": {
|
|
205
|
+
const magic = String.fromCharCode(...this.#scratch.subarray(0, 8));
|
|
206
|
+
if (!isFileHeaderMagic(magic)) {
|
|
207
|
+
if (magic === "NanoVDB1") {
|
|
208
|
+
throw new VDBUnsupportedError(".nvdb stream: this is a raw NanoVDB grid buffer (magic NanoVDB1), not a segment file; read it whole with NvdbFile.fromArrayBuffer.");
|
|
209
|
+
}
|
|
210
|
+
throw new NvdbFormatError(`expected a NanoVDB FileHeader (magic NanoVDB2 or NanoVDB0) at byte ${this.#received - FILE_HEADER_SIZE}, found "${magic.replace(/[^\x20-\x7e]/g, "?")}".`);
|
|
211
|
+
}
|
|
212
|
+
const view = new DataView(this.#scratch.buffer, 0, FILE_HEADER_SIZE);
|
|
213
|
+
let header;
|
|
214
|
+
try {
|
|
215
|
+
header = readFileHeader(view, 0);
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
const msg = err.message;
|
|
219
|
+
if (/BLOSC/.test(msg))
|
|
220
|
+
throw new VDBUnsupportedError(msg);
|
|
221
|
+
throw new NvdbFormatError(msg);
|
|
222
|
+
}
|
|
223
|
+
if (header.gridCount === 0)
|
|
224
|
+
throw new NvdbFormatError(`segment #${this.#segments} declares 0 grids.`);
|
|
225
|
+
this.#codec = header.codec;
|
|
226
|
+
this.#segmentGrids = header.gridCount;
|
|
227
|
+
this.#segments++;
|
|
228
|
+
this.#segmentStart = this.#received - FILE_HEADER_SIZE;
|
|
229
|
+
this.#pending = [];
|
|
230
|
+
this.#gridInSegment = 0;
|
|
231
|
+
this.#expect("meta", this.#scratch.subarray(0, FILE_METADATA_SIZE));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
case "meta": {
|
|
235
|
+
const i = this.#grids.length;
|
|
236
|
+
const meta = readFileMetaData(new DataView(this.#scratch.buffer, 0, FILE_METADATA_SIZE), 0);
|
|
237
|
+
assertSafeGridSize(meta.gridSize, `grid #${i}'s FileMetaData.gridSize`);
|
|
238
|
+
if (meta.gridSize < GRID_DATA_SIZE) {
|
|
239
|
+
throw new NvdbFormatError(`grid #${i} declares gridSize ${meta.gridSize}, smaller than a ${GRID_DATA_SIZE}-byte GridData header.`);
|
|
240
|
+
}
|
|
241
|
+
if (meta.gridSize > this.#maxGridBytes) {
|
|
242
|
+
throw new NvdbFormatError(`grid #${i} declares gridSize ${meta.gridSize} bytes, over maxGridBytes (${this.#maxGridBytes}); raise the option if the file is trusted.`);
|
|
243
|
+
}
|
|
244
|
+
if (meta.nameSize > this.#maxNameBytes) {
|
|
245
|
+
throw new NvdbFormatError(`grid #${i} declares a ${meta.nameSize}-byte name, over maxNameBytes (${this.#maxNameBytes}).`);
|
|
246
|
+
}
|
|
247
|
+
this.#nextMeta = meta;
|
|
248
|
+
this.#expect("name", meta.nameSize <= this.#scratch.byteLength ? this.#scratch.subarray(0, meta.nameSize) : new Uint8Array(meta.nameSize));
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
case "name": {
|
|
252
|
+
const meta = this.#nextMeta;
|
|
253
|
+
const name = decodeCString(this.#target);
|
|
254
|
+
const gridType = gridTypeName(meta.gridTypeId);
|
|
255
|
+
try {
|
|
256
|
+
validateGridType(gridType, name);
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
throw new VDBUnsupportedError(err.message);
|
|
260
|
+
}
|
|
261
|
+
this.#pending.push({ meta, name });
|
|
262
|
+
this.#grids.push({
|
|
263
|
+
name,
|
|
264
|
+
gridType,
|
|
265
|
+
gridClass: gridClassName(meta.gridClassId),
|
|
266
|
+
worldBBox: meta.worldBBox,
|
|
267
|
+
indexBBox: meta.indexBBox,
|
|
268
|
+
voxelSize: meta.voxelSize,
|
|
269
|
+
voxelCount: meta.voxelCount,
|
|
270
|
+
gridByteSize: meta.gridSize,
|
|
271
|
+
});
|
|
272
|
+
this.#nextMeta = null;
|
|
273
|
+
if (this.#pending.length < this.#segmentGrids)
|
|
274
|
+
this.#expect("meta", this.#scratch.subarray(0, FILE_METADATA_SIZE));
|
|
275
|
+
else {
|
|
276
|
+
let end = this.#segmentStart + FILE_HEADER_SIZE;
|
|
277
|
+
for (const g of this.#pending)
|
|
278
|
+
end += FILE_METADATA_SIZE + g.meta.nameSize + g.meta.fileSize;
|
|
279
|
+
this.#knownEnd = Number.isSafeInteger(end) ? end : null;
|
|
280
|
+
this.#startGrid();
|
|
281
|
+
}
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
case "zipPrefix": {
|
|
285
|
+
const { meta, name } = this.#pending[this.#gridInSegment];
|
|
286
|
+
const size = Number(new DataView(this.#scratch.buffer, 0, ZIP_PREFIX).getBigUint64(0, true));
|
|
287
|
+
const bound = zipBound(meta.gridSize);
|
|
288
|
+
if (!Number.isSafeInteger(size) || size < 1 || size > bound) {
|
|
289
|
+
throw new NvdbFormatError(`grid #${this.#segmentFirst() + this.#gridInSegment} ("${name}") declares a ${size}-byte ZIP payload for a ` +
|
|
290
|
+
`${meta.gridSize}-byte grid (zlib's bound is ${bound}).`);
|
|
291
|
+
}
|
|
292
|
+
this.#expect("grid", new Uint8Array(size));
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
case "grid": {
|
|
296
|
+
const k = this.#gridInSegment;
|
|
297
|
+
const index = this.#segmentFirst() + k;
|
|
298
|
+
const { meta, name } = this.#pending[k];
|
|
299
|
+
const bytes = this.#codec === NvdbCodec.ZIP ? inflateZipGrid(this.#target, meta.gridSize, index, name) : this.#target;
|
|
300
|
+
const record = finishGridRecord(meta, name, index, bytes);
|
|
301
|
+
this.#grids[index] = record.metadata;
|
|
302
|
+
const { baseName, lod } = parseNvdbLodName(name);
|
|
303
|
+
out.push({ index, metadata: record.metadata, image: record.image, bytesReceived: this.#received, bytesTotal: this.bytesTotal, lod, baseName });
|
|
304
|
+
this.#emitted++;
|
|
305
|
+
this.#gridInSegment++;
|
|
306
|
+
if (this.#gridInSegment < this.#segmentGrids)
|
|
307
|
+
this.#startGrid();
|
|
308
|
+
else {
|
|
309
|
+
this.#pending = [];
|
|
310
|
+
this.#expect("header", this.#scratch.subarray(0, FILE_HEADER_SIZE));
|
|
311
|
+
}
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
#startGrid() {
|
|
317
|
+
const { meta } = this.#pending[this.#gridInSegment];
|
|
318
|
+
if (this.#codec === NvdbCodec.ZIP)
|
|
319
|
+
this.#expect("zipPrefix", this.#scratch.subarray(0, ZIP_PREFIX));
|
|
320
|
+
else
|
|
321
|
+
this.#expect("grid", new Uint8Array(meta.gridSize));
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function isResponse(source) {
|
|
325
|
+
return typeof source.headers === "object" && "body" in source;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Reads a byte stream (a `fetch` Response or body, or any async iterable of chunks) through
|
|
329
|
+
* an {@link NvdbStreamReader}, yielding each grid as it completes. Stops
|
|
330
|
+
* reading (and cancels the stream) when the consumer breaks out of the loop.
|
|
331
|
+
*/
|
|
332
|
+
export async function* readNvdbStream(source, options = {}) {
|
|
333
|
+
if (isResponse(source)) {
|
|
334
|
+
const len = nvdbResponseLength(source);
|
|
335
|
+
if (source.body === null)
|
|
336
|
+
throw new NvdbFormatError("readNvdbStream: the response has no body.");
|
|
337
|
+
options = len !== null && options.bytesTotal === undefined ? { ...options, bytesTotal: len } : options;
|
|
338
|
+
source = source.body;
|
|
339
|
+
}
|
|
340
|
+
const reader = new NvdbStreamReader(options);
|
|
341
|
+
if (typeof source.getReader === "function") {
|
|
342
|
+
const r = source.getReader();
|
|
343
|
+
let finished = false;
|
|
344
|
+
try {
|
|
345
|
+
for (;;) {
|
|
346
|
+
const { done, value } = await r.read();
|
|
347
|
+
if (done)
|
|
348
|
+
break;
|
|
349
|
+
yield* reader.push(value);
|
|
350
|
+
}
|
|
351
|
+
finished = true;
|
|
352
|
+
reader.end();
|
|
353
|
+
}
|
|
354
|
+
finally {
|
|
355
|
+
if (!finished)
|
|
356
|
+
await r.cancel().catch(() => undefined);
|
|
357
|
+
r.releaseLock();
|
|
358
|
+
}
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
for await (const chunk of source)
|
|
362
|
+
yield* reader.push(chunk);
|
|
363
|
+
reader.end();
|
|
364
|
+
}
|
|
365
|
+
//# sourceMappingURL=nvdb-stream.js.map
|