@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,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* level-set.ts — mjurczyk's level-set bake sampler (`sampleLevelSet`), an
|
|
3
|
+
* option of the `.wvdb` bake (`levelSetSampler: 'surface-mean'`, K4.13).
|
|
4
|
+
*
|
|
5
|
+
* Portions derived from mjurczyk/openvdb (MIT), commit 75e7345:
|
|
6
|
+
* `src/openvdb/utils/levelSet.js` (`sampleLevelSet`, `getVoxelDistance`,
|
|
7
|
+
* `getTrilinearDistance`) and `src/wvdb/bake.js` (`sampleLevelSetGrid`, the
|
|
8
|
+
* band limit). His arithmetic order is kept so the output is bit-identical.
|
|
9
|
+
*
|
|
10
|
+
* What it does (his notes, restated): a level set's narrow band is often
|
|
11
|
+
* thinner than a texel, so a point sample is only inside or outside and the
|
|
12
|
+
* surface gets steps. When texels are larger than a voxel, a texel whose eight
|
|
13
|
+
* corners do not all have the same sign (it crosses the surface) is the mean
|
|
14
|
+
* of 4x4x4 sub-samples inside it; every other texel is a trilinear sample at
|
|
15
|
+
* its centre (only near the surface; far voxels keep the nearest value). A
|
|
16
|
+
* voxel's distance is its value clamped to `±background` when active, and
|
|
17
|
+
* `±background` by sign when inactive. Finally, values inside the band are
|
|
18
|
+
* clamped one quantization step inside it (`background - 2·background /
|
|
19
|
+
* (2^bits - 1)`) so they never decode as outside.
|
|
20
|
+
*
|
|
21
|
+
* The spec text (§8) instead point-samples and encodes by the source's active
|
|
22
|
+
* state; that stays the default (`levelSetSampler: 'spec'`, DIVERGES V17).
|
|
23
|
+
*/
|
|
24
|
+
import { VDBToolsError } from "../errors.js";
|
|
25
|
+
/** Sub-samples on each axis for texels that cross the surface (his `filterSamples`). */
|
|
26
|
+
const FILTER_SAMPLES = 4;
|
|
27
|
+
/**
|
|
28
|
+
* His `sampleLevelSetGrid`: samples a level set over `bbox` at `dimensions`
|
|
29
|
+
* (x fastest) and applies the band limit for `bits`.
|
|
30
|
+
*/
|
|
31
|
+
export function sampleWvdbLevelSetSurfaceMean(source, bbox, dimensions, bits = 8) {
|
|
32
|
+
const [width, height, depth] = dimensions;
|
|
33
|
+
const values = new Float32Array(width * height * depth);
|
|
34
|
+
const background = source.background;
|
|
35
|
+
if (!source.bbox || !bbox)
|
|
36
|
+
return values.fill(background);
|
|
37
|
+
const access = source.index;
|
|
38
|
+
if (!access) {
|
|
39
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `levelSetSampler 'surface-mean': source "${source.name}" has no index access (use wvdbSourceFromVdbGrid or wvdbSourceFromNvdb)`);
|
|
40
|
+
}
|
|
41
|
+
const min = bbox[0];
|
|
42
|
+
const size = [bbox[1][0] - min[0], bbox[1][1] - min[1], bbox[1][2] - min[2]];
|
|
43
|
+
const world = [0, 0, 0];
|
|
44
|
+
const index = [0, 0, 0];
|
|
45
|
+
const rounded = [0, 0, 0];
|
|
46
|
+
const corner = [0, 0, 0];
|
|
47
|
+
const toIndex = (x, y, z) => {
|
|
48
|
+
world[0] = min[0] + (x / width) * size[0];
|
|
49
|
+
world[1] = min[1] + (y / height) * size[1];
|
|
50
|
+
world[2] = min[2] + (z / depth) * size[2];
|
|
51
|
+
return access.toIndex(world, index);
|
|
52
|
+
};
|
|
53
|
+
// His grid.getValue / isActive round the position (Vector3.round: Math.round per axis).
|
|
54
|
+
const lookup = (p) => {
|
|
55
|
+
rounded[0] = Math.round(p[0]);
|
|
56
|
+
rounded[1] = Math.round(p[1]);
|
|
57
|
+
rounded[2] = Math.round(p[2]);
|
|
58
|
+
return access.voxel(rounded);
|
|
59
|
+
};
|
|
60
|
+
// getVoxelDistance: inactive voxels are only outside (+b) or inside (-b); values clamp to the band.
|
|
61
|
+
const voxelDistance = (p) => {
|
|
62
|
+
const { value, active } = lookup(p);
|
|
63
|
+
if (!Number.isFinite(value))
|
|
64
|
+
return background;
|
|
65
|
+
if (!active)
|
|
66
|
+
return value < 0.0 ? -background : background;
|
|
67
|
+
return Math.min(Math.max(value, -background), background);
|
|
68
|
+
};
|
|
69
|
+
// getTrilinearDistance: trilinear only near the surface; far voxels keep the nearest value.
|
|
70
|
+
const trilinearDistance = (p) => {
|
|
71
|
+
const nearest = voxelDistance(p);
|
|
72
|
+
if (Math.abs(nearest) >= background)
|
|
73
|
+
return nearest;
|
|
74
|
+
const x0 = Math.floor(p[0]);
|
|
75
|
+
const y0 = Math.floor(p[1]);
|
|
76
|
+
const z0 = Math.floor(p[2]);
|
|
77
|
+
const wx = p[0] - x0;
|
|
78
|
+
const wy = p[1] - y0;
|
|
79
|
+
const wz = p[2] - z0;
|
|
80
|
+
let value = 0.0;
|
|
81
|
+
for (let i = 0; i < 8; i++) {
|
|
82
|
+
const dx = i & 1;
|
|
83
|
+
const dy = (i >> 1) & 1;
|
|
84
|
+
const dz = (i >> 2) & 1;
|
|
85
|
+
const weight = (dx ? wx : 1.0 - wx) * (dy ? wy : 1.0 - wy) * (dz ? wz : 1.0 - wz);
|
|
86
|
+
if (weight > 0.0) {
|
|
87
|
+
corner[0] = x0 + dx;
|
|
88
|
+
corner[1] = y0 + dy;
|
|
89
|
+
corner[2] = z0 + dz;
|
|
90
|
+
value += weight * voxelDistance(corner);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return value;
|
|
94
|
+
};
|
|
95
|
+
// Texel size in voxels.
|
|
96
|
+
const texel = access.toIndexVector([size[0] / width, size[1] / height, size[2] / depth], [0, 0, 0]);
|
|
97
|
+
const filter = Math.max(Math.abs(texel[0]), Math.abs(texel[1]), Math.abs(texel[2])) > 1.0;
|
|
98
|
+
// Signs at texel corners, one corner slice for each side of the texel row.
|
|
99
|
+
const cornersX = width + 1;
|
|
100
|
+
const cornerSlice = cornersX * (height + 1);
|
|
101
|
+
let lowerSigns = new Uint8Array(filter ? cornerSlice : 0);
|
|
102
|
+
let upperSigns = new Uint8Array(filter ? cornerSlice : 0);
|
|
103
|
+
const fillSigns = (signs, z) => {
|
|
104
|
+
for (let y = 0; y <= height; y++) {
|
|
105
|
+
for (let x = 0; x <= width; x++) {
|
|
106
|
+
signs[x + y * cornersX] = lookup(toIndex(x, y, z)).value < 0.0 ? 1 : 0;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const crossesSurface = (x, y) => {
|
|
111
|
+
const first = lowerSigns[x + y * cornersX];
|
|
112
|
+
for (let i = 1; i < 8; i++) {
|
|
113
|
+
const signs = (i >> 2) & 1 ? upperSigns : lowerSigns;
|
|
114
|
+
if (signs[x + (i & 1) + (y + ((i >> 1) & 1)) * cornersX] !== first)
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
};
|
|
119
|
+
if (filter)
|
|
120
|
+
fillSigns(lowerSigns, 0);
|
|
121
|
+
const subSamples = FILTER_SAMPLES * FILTER_SAMPLES * FILTER_SAMPLES;
|
|
122
|
+
let offset = 0;
|
|
123
|
+
for (let z = 0; z < depth; z++) {
|
|
124
|
+
if (filter)
|
|
125
|
+
fillSigns(upperSigns, z + 1);
|
|
126
|
+
for (let y = 0; y < height; y++) {
|
|
127
|
+
for (let x = 0; x < width; x++, offset++) {
|
|
128
|
+
if (filter && crossesSurface(x, y)) {
|
|
129
|
+
let sum = 0.0;
|
|
130
|
+
for (let i = 0; i < subSamples; i++) {
|
|
131
|
+
const sx = (i % FILTER_SAMPLES) + 0.5;
|
|
132
|
+
const sy = (Math.floor(i / FILTER_SAMPLES) % FILTER_SAMPLES) + 0.5;
|
|
133
|
+
const sz = Math.floor(i / (FILTER_SAMPLES * FILTER_SAMPLES)) + 0.5;
|
|
134
|
+
sum += voxelDistance(toIndex(x + sx / FILTER_SAMPLES, y + sy / FILTER_SAMPLES, z + sz / FILTER_SAMPLES));
|
|
135
|
+
}
|
|
136
|
+
values[offset] = sum / subSamples;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
values[offset] = trilinearDistance(toIndex(x + 0.5, y + 0.5, z + 0.5));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
[lowerSigns, upperSigns] = [upperSigns, lowerSigns];
|
|
144
|
+
}
|
|
145
|
+
// Values in the band stay one quantization step inside it, so they never decode as outside.
|
|
146
|
+
const bandLimit = background - (2.0 * background) / ((1 << bits) - 1);
|
|
147
|
+
for (let i = 0; i < values.length; i++) {
|
|
148
|
+
if (Math.abs(values[i]) < background)
|
|
149
|
+
values[i] = Math.min(Math.max(values[i], -bandLimit), bandLimit);
|
|
150
|
+
}
|
|
151
|
+
return values;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=level-set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"level-set.js","sourceRoot":"","sources":["../../../src/tools/wvdb/level-set.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAqB7C,wFAAwF;AACxF,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAC3C,MAA0B,EAC1B,IAAoB,EACpB,UAAoB,EACpB,OAAiB,CAAC;IAElB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,UAAU,CAAC;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AAC,MAAM,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;gBACzE,CAAC;YACH,CAAC;QACH,CAAC;QACD,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACtD,CAAC;IAED,4FAA4F;IAC5F,MAAM,SAAS,GAAG,UAAU,GAAG,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACtE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,GAAG,UAAU;YAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAE,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC;IAC3G,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * level-set.ts — mjurczyk's level-set bake sampler (`sampleLevelSet`), an\n * option of the `.wvdb` bake (`levelSetSampler: 'surface-mean'`, K4.13).\n *\n * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345:\n * `src/openvdb/utils/levelSet.js` (`sampleLevelSet`, `getVoxelDistance`,\n * `getTrilinearDistance`) and `src/wvdb/bake.js` (`sampleLevelSetGrid`, the\n * band limit). His arithmetic order is kept so the output is bit-identical.\n *\n * What it does (his notes, restated): a level set's narrow band is often\n * thinner than a texel, so a point sample is only inside or outside and the\n * surface gets steps. When texels are larger than a voxel, a texel whose eight\n * corners do not all have the same sign (it crosses the surface) is the mean\n * of 4x4x4 sub-samples inside it; every other texel is a trilinear sample at\n * its centre (only near the surface; far voxels keep the nearest value). A\n * voxel's distance is its value clamped to `±background` when active, and\n * `±background` by sign when inactive. Finally, values inside the band are\n * clamped one quantization step inside it (`background - 2·background /\n * (2^bits - 1)`) so they never decode as outside.\n *\n * The spec text (§8) instead point-samples and encodes by the source's active\n * state; that stays the default (`levelSetSampler: 'spec'`, DIVERGES V17).\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport type { WvdbBits, WvdbBox, WvdbVec3 } from \"./format.js\";\n\n/** Index-space access to a sample source (axis-aligned or affine map). */\nexport interface WvdbIndexAccess {\n /** World position → fractional index coordinate (the grid's inverse map), into `out`. */\n toIndex(world: WvdbVec3, out: WvdbVec3): WvdbVec3;\n /** A world-space vector → index units (the inverse Jacobian), into `out`. */\n toIndexVector(vector: WvdbVec3, out: WvdbVec3): WvdbVec3;\n /** Value and active state of an integer voxel (inactive tile values included). */\n voxel(ijk: [number, number, number]): { value: number; active: boolean };\n}\n\n/** The part of a sample source this sampler reads. */\nexport interface WvdbLevelSetSource {\n name: string;\n background: number;\n bbox: WvdbBox | null;\n index?: WvdbIndexAccess;\n}\n\n/** Sub-samples on each axis for texels that cross the surface (his `filterSamples`). */\nconst FILTER_SAMPLES = 4;\n\n/**\n * His `sampleLevelSetGrid`: samples a level set over `bbox` at `dimensions`\n * (x fastest) and applies the band limit for `bits`.\n */\nexport function sampleWvdbLevelSetSurfaceMean(\n source: WvdbLevelSetSource,\n bbox: WvdbBox | null,\n dimensions: WvdbVec3,\n bits: WvdbBits = 8,\n): Float32Array {\n const [width, height, depth] = dimensions;\n const values = new Float32Array(width * height * depth);\n const background = source.background;\n if (!source.bbox || !bbox) return values.fill(background);\n const access = source.index;\n if (!access) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `levelSetSampler 'surface-mean': source \"${source.name}\" has no index access (use wvdbSourceFromVdbGrid or wvdbSourceFromNvdb)`);\n }\n const min = bbox[0];\n const size: WvdbVec3 = [bbox[1][0] - min[0], bbox[1][1] - min[1], bbox[1][2] - min[2]];\n\n const world: WvdbVec3 = [0, 0, 0];\n const index: WvdbVec3 = [0, 0, 0];\n const rounded: [number, number, number] = [0, 0, 0];\n const corner: WvdbVec3 = [0, 0, 0];\n\n const toIndex = (x: number, y: number, z: number): WvdbVec3 => {\n world[0] = min[0] + (x / width) * size[0];\n world[1] = min[1] + (y / height) * size[1];\n world[2] = min[2] + (z / depth) * size[2];\n return access.toIndex(world, index);\n };\n\n // His grid.getValue / isActive round the position (Vector3.round: Math.round per axis).\n const lookup = (p: WvdbVec3): { value: number; active: boolean } => {\n rounded[0] = Math.round(p[0]);\n rounded[1] = Math.round(p[1]);\n rounded[2] = Math.round(p[2]);\n return access.voxel(rounded);\n };\n\n // getVoxelDistance: inactive voxels are only outside (+b) or inside (-b); values clamp to the band.\n const voxelDistance = (p: WvdbVec3): number => {\n const { value, active } = lookup(p);\n if (!Number.isFinite(value)) return background;\n if (!active) return value < 0.0 ? -background : background;\n return Math.min(Math.max(value, -background), background);\n };\n\n // getTrilinearDistance: trilinear only near the surface; far voxels keep the nearest value.\n const trilinearDistance = (p: WvdbVec3): number => {\n const nearest = voxelDistance(p);\n if (Math.abs(nearest) >= background) return nearest;\n const x0 = Math.floor(p[0]);\n const y0 = Math.floor(p[1]);\n const z0 = Math.floor(p[2]);\n const wx = p[0] - x0;\n const wy = p[1] - y0;\n const wz = p[2] - z0;\n let value = 0.0;\n for (let i = 0; i < 8; i++) {\n const dx = i & 1;\n const dy = (i >> 1) & 1;\n const dz = (i >> 2) & 1;\n const weight = (dx ? wx : 1.0 - wx) * (dy ? wy : 1.0 - wy) * (dz ? wz : 1.0 - wz);\n if (weight > 0.0) {\n corner[0] = x0 + dx;\n corner[1] = y0 + dy;\n corner[2] = z0 + dz;\n value += weight * voxelDistance(corner);\n }\n }\n return value;\n };\n\n // Texel size in voxels.\n const texel = access.toIndexVector([size[0] / width, size[1] / height, size[2] / depth], [0, 0, 0]);\n const filter = Math.max(Math.abs(texel[0]), Math.abs(texel[1]), Math.abs(texel[2])) > 1.0;\n\n // Signs at texel corners, one corner slice for each side of the texel row.\n const cornersX = width + 1;\n const cornerSlice = cornersX * (height + 1);\n let lowerSigns = new Uint8Array(filter ? cornerSlice : 0);\n let upperSigns = new Uint8Array(filter ? cornerSlice : 0);\n\n const fillSigns = (signs: Uint8Array, z: number): void => {\n for (let y = 0; y <= height; y++) {\n for (let x = 0; x <= width; x++) {\n signs[x + y * cornersX] = lookup(toIndex(x, y, z)).value < 0.0 ? 1 : 0;\n }\n }\n };\n\n const crossesSurface = (x: number, y: number): boolean => {\n const first = lowerSigns[x + y * cornersX];\n for (let i = 1; i < 8; i++) {\n const signs = (i >> 2) & 1 ? upperSigns : lowerSigns;\n if (signs[x + (i & 1) + (y + ((i >> 1) & 1)) * cornersX] !== first) return true;\n }\n return false;\n };\n\n if (filter) fillSigns(lowerSigns, 0);\n const subSamples = FILTER_SAMPLES * FILTER_SAMPLES * FILTER_SAMPLES;\n let offset = 0;\n for (let z = 0; z < depth; z++) {\n if (filter) fillSigns(upperSigns, z + 1);\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++, offset++) {\n if (filter && crossesSurface(x, y)) {\n let sum = 0.0;\n for (let i = 0; i < subSamples; i++) {\n const sx = (i % FILTER_SAMPLES) + 0.5;\n const sy = (Math.floor(i / FILTER_SAMPLES) % FILTER_SAMPLES) + 0.5;\n const sz = Math.floor(i / (FILTER_SAMPLES * FILTER_SAMPLES)) + 0.5;\n sum += voxelDistance(toIndex(x + sx / FILTER_SAMPLES, y + sy / FILTER_SAMPLES, z + sz / FILTER_SAMPLES));\n }\n values[offset] = sum / subSamples;\n } else {\n values[offset] = trilinearDistance(toIndex(x + 0.5, y + 0.5, z + 0.5));\n }\n }\n }\n [lowerSigns, upperSigns] = [upperSigns, lowerSigns];\n }\n\n // Values in the band stay one quantization step inside it, so they never decode as outside.\n const bandLimit = background - (2.0 * background) / ((1 << bits) - 1);\n for (let i = 0; i < values.length; i++) {\n if (Math.abs(values[i]!) < background) values[i] = Math.min(Math.max(values[i]!, -bandLimit), bandLimit);\n }\n return values;\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `.wvdb` dense level → NanoVDB FLOAT grid with identical voxels (K3.2, R1 §6 Step 2 A/B).
|
|
3
|
+
*
|
|
4
|
+
* The sparse-vs-dense A/B renders the same voxels through both samplers, so the only difference
|
|
5
|
+
* is the sampler (hardware trilinear on `r8unorm` vs the sparse 8-tap trilinear). This takes the
|
|
6
|
+
* exact texels the dense source uploads (`wvdbDenseVolume`, his 8-bit `clamp(v / scale, 0, 1)`) and
|
|
7
|
+
* writes each one as the f32 the GPU decodes from `r8unorm`: `k / 255`. Texel `(x, y, z)` becomes
|
|
8
|
+
* index voxel `(x, y, z)`; non-zero texels are active, zero texels are the 0 background (so the
|
|
9
|
+
* grid's stats are the mean of the non-zero texels, his `getDensityStats` rule up to the f32 sum).
|
|
10
|
+
*
|
|
11
|
+
* The unit box of the volume maps to the index box `[0, dims − 1]` (pass it as the sparse source's
|
|
12
|
+
* `indexBox`: the built grid's own bbox is the active voxels' only). The Map scales each axis by that
|
|
13
|
+
* axis's voxel size in the `.wvdb` box (`(bbox.max − bbox.min) / dims`: a bake rounds each side's
|
|
14
|
+
* texel count on its own, so voxels are generally not cubic) with the first voxel centre at
|
|
15
|
+
* `bbox.min + voxel / 2`, where the dense texture puts it. CPU tools (`vdbResampleError`, a
|
|
16
|
+
* world-space sample through the Map) then compare the grid with its source in world space; the
|
|
17
|
+
* froxel renderer places volumes by their box, not the grid's Map. Without a box the Map is the identity.
|
|
18
|
+
*/
|
|
19
|
+
import { type VDBBuiltGrid } from "../nanovdb/serialize.js";
|
|
20
|
+
import type { WvdbDenseVolume } from "./dense.js";
|
|
21
|
+
export interface WvdbDenseToNvdbOptions {
|
|
22
|
+
/** Channel to convert (a scalar one). Default `'density'`. */
|
|
23
|
+
channel?: "density" | "mask" | "emission";
|
|
24
|
+
/** Grid name. Default: the channel's grid name in the `.wvdb`. */
|
|
25
|
+
gridName?: string;
|
|
26
|
+
}
|
|
27
|
+
/** The converted grid plus the index box the dense texture covered. */
|
|
28
|
+
export interface WvdbNvdbGrid extends VDBBuiltGrid {
|
|
29
|
+
/** `[0, 0, 0]` to `dims − 1`: the dense texture's voxels (inclusive). */
|
|
30
|
+
readonly textureIndexBox: {
|
|
31
|
+
min: [number, number, number];
|
|
32
|
+
max: [number, number, number];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* K5.9: the `vdbSparseSource` options (`@pmndrs/vdb/three`) that line a sparse copy up with the dense source: the
|
|
36
|
+
* texture's index box, the dense density stats (so `normalizeDensity` divides by the same mean) and the `.wvdb`
|
|
37
|
+
* box (when it has one). Spread them in: `vdbSparseSource(grids, { density: id }, { ...grid.sparseSourceOptions, lod })`.
|
|
38
|
+
* For an aux channel (mask, emission) pass `textureIndexBox` as its `auxIndexBoxes` entry instead.
|
|
39
|
+
*/
|
|
40
|
+
readonly sparseSourceOptions: {
|
|
41
|
+
readonly indexBox: {
|
|
42
|
+
min: [number, number, number];
|
|
43
|
+
max: [number, number, number];
|
|
44
|
+
};
|
|
45
|
+
readonly stats: {
|
|
46
|
+
meanNonZero: number;
|
|
47
|
+
max: number;
|
|
48
|
+
activeVoxels: number;
|
|
49
|
+
};
|
|
50
|
+
readonly bbox?: [[number, number, number], [number, number, number]];
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Converts one scalar channel of a dense `.wvdb` level to a NanoVDB FLOAT grid, voxel for voxel. */
|
|
54
|
+
export declare function wvdbDenseToNvdb(volume: WvdbDenseVolume, o?: WvdbDenseToNvdbOptions): WvdbNvdbGrid;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `.wvdb` dense level → NanoVDB FLOAT grid with identical voxels (K3.2, R1 §6 Step 2 A/B).
|
|
3
|
+
*
|
|
4
|
+
* The sparse-vs-dense A/B renders the same voxels through both samplers, so the only difference
|
|
5
|
+
* is the sampler (hardware trilinear on `r8unorm` vs the sparse 8-tap trilinear). This takes the
|
|
6
|
+
* exact texels the dense source uploads (`wvdbDenseVolume`, his 8-bit `clamp(v / scale, 0, 1)`) and
|
|
7
|
+
* writes each one as the f32 the GPU decodes from `r8unorm`: `k / 255`. Texel `(x, y, z)` becomes
|
|
8
|
+
* index voxel `(x, y, z)`; non-zero texels are active, zero texels are the 0 background (so the
|
|
9
|
+
* grid's stats are the mean of the non-zero texels, his `getDensityStats` rule up to the f32 sum).
|
|
10
|
+
*
|
|
11
|
+
* The unit box of the volume maps to the index box `[0, dims − 1]` (pass it as the sparse source's
|
|
12
|
+
* `indexBox`: the built grid's own bbox is the active voxels' only). The Map scales each axis by that
|
|
13
|
+
* axis's voxel size in the `.wvdb` box (`(bbox.max − bbox.min) / dims`: a bake rounds each side's
|
|
14
|
+
* texel count on its own, so voxels are generally not cubic) with the first voxel centre at
|
|
15
|
+
* `bbox.min + voxel / 2`, where the dense texture puts it. CPU tools (`vdbResampleError`, a
|
|
16
|
+
* world-space sample through the Map) then compare the grid with its source in world space; the
|
|
17
|
+
* froxel renderer places volumes by their box, not the grid's Map. Without a box the Map is the identity.
|
|
18
|
+
*/
|
|
19
|
+
import { VDBToolsError } from "../errors.js";
|
|
20
|
+
import { vdbBuildFromDenseDetailed } from "../nanovdb/serialize.js";
|
|
21
|
+
/** Converts one scalar channel of a dense `.wvdb` level to a NanoVDB FLOAT grid, voxel for voxel. */
|
|
22
|
+
export function wvdbDenseToNvdb(volume, o = {}) {
|
|
23
|
+
const channel = o.channel ?? "density";
|
|
24
|
+
const tex = volume[channel];
|
|
25
|
+
if (!tex)
|
|
26
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `wvdbDenseToNvdb: the volume has no ${channel} channel`);
|
|
27
|
+
if (tex.texelBytes !== 1)
|
|
28
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `wvdbDenseToNvdb: the ${channel} channel is not scalar (r8unorm)`);
|
|
29
|
+
const [w, h, d] = tex.dimensions;
|
|
30
|
+
const values = new Float32Array(w * h * d);
|
|
31
|
+
// Texels are x fastest (x + (y + z·h)·w); vdbBuildFromDense reads x-major ((x·h + y)·d + z).
|
|
32
|
+
for (let z = 0; z < d; z++)
|
|
33
|
+
for (let y = 0; y < h; y++)
|
|
34
|
+
for (let x = 0; x < w; x++)
|
|
35
|
+
values[(x * h + y) * d + z] = tex.data[x + (y + z * h) * w] / 255;
|
|
36
|
+
const bbox = volume.bbox;
|
|
37
|
+
// Per axis (G15a): a bake rounds each side's texel count on its own, so the voxels are not cubic.
|
|
38
|
+
const voxelSize = [w, h, d].map((n, a) => {
|
|
39
|
+
const v = bbox ? (bbox[1][a] - bbox[0][a]) / n : 1;
|
|
40
|
+
return v > 0 && Number.isFinite(v) ? v : 1;
|
|
41
|
+
});
|
|
42
|
+
const worldOrigin = bbox
|
|
43
|
+
? [bbox[0][0] + voxelSize[0] / 2, bbox[0][1] + voxelSize[1] / 2, bbox[0][2] + voxelSize[2] / 2]
|
|
44
|
+
: [0, 0, 0];
|
|
45
|
+
const built = vdbBuildFromDenseDetailed(values, [w, h, d], {
|
|
46
|
+
voxelSize,
|
|
47
|
+
worldOrigin,
|
|
48
|
+
background: 0,
|
|
49
|
+
gridName: o.gridName ?? volume.gridNames[channel] ?? channel,
|
|
50
|
+
gridClass: "FogVolume",
|
|
51
|
+
});
|
|
52
|
+
const textureIndexBox = { min: [0, 0, 0], max: [w - 1, h - 1, d - 1] };
|
|
53
|
+
const sparseSourceOptions = {
|
|
54
|
+
indexBox: { min: [...textureIndexBox.min], max: [...textureIndexBox.max] },
|
|
55
|
+
stats: { meanNonZero: volume.meanDensity, max: volume.maxDensity, activeVoxels: volume.activeTexels },
|
|
56
|
+
...(bbox ? { bbox: [[...bbox[0]], [...bbox[1]]] } : {}),
|
|
57
|
+
};
|
|
58
|
+
return { ...built, textureIndexBox, sparseSourceOptions };
|
|
59
|
+
}
|
|
60
|
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AAC,IAAI,OAAO;QAC5D,SAAS,EAAE,WAAW;KACvB,CAAC,CAAC;IACH,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAA6B,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAA6B,EAAE,CAAC;IAC/H,MAAM,mBAAmB,GAAG;QAC1B,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,eAAe,CAAC,GAAG,CAA6B,EAAE,GAAG,EAAE,CAAC,GAAG,eAAe,CAAC,GAAG,CAA6B,EAAE;QAClI,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE;QACrG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAyD,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChH,CAAC;IACF,OAAO,EAAE,GAAG,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,CAAC;AAC5D,CAAC","sourcesContent":["/**\n * `.wvdb` dense level → NanoVDB FLOAT grid with identical voxels (K3.2, R1 §6 Step 2 A/B).\n *\n * The sparse-vs-dense A/B renders the same voxels through both samplers, so the only difference\n * is the sampler (hardware trilinear on `r8unorm` vs the sparse 8-tap trilinear). This takes the\n * exact texels the dense source uploads (`wvdbDenseVolume`, his 8-bit `clamp(v / scale, 0, 1)`) and\n * writes each one as the f32 the GPU decodes from `r8unorm`: `k / 255`. Texel `(x, y, z)` becomes\n * index voxel `(x, y, z)`; non-zero texels are active, zero texels are the 0 background (so the\n * grid's stats are the mean of the non-zero texels, his `getDensityStats` rule up to the f32 sum).\n *\n * The unit box of the volume maps to the index box `[0, dims − 1]` (pass it as the sparse source's\n * `indexBox`: the built grid's own bbox is the active voxels' only). The Map scales each axis by that\n * axis's voxel size in the `.wvdb` box (`(bbox.max − bbox.min) / dims`: a bake rounds each side's\n * texel count on its own, so voxels are generally not cubic) with the first voxel centre at\n * `bbox.min + voxel / 2`, where the dense texture puts it. CPU tools (`vdbResampleError`, a\n * world-space sample through the Map) then compare the grid with its source in world space; the\n * froxel renderer places volumes by their box, not the grid's Map. Without a box the Map is the identity.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport { vdbBuildFromDenseDetailed, type VDBBuiltGrid } from \"../nanovdb/serialize.js\";\nimport type { WvdbDenseVolume } from \"./dense.js\";\n\nexport interface WvdbDenseToNvdbOptions {\n /** Channel to convert (a scalar one). Default `'density'`. */\n channel?: \"density\" | \"mask\" | \"emission\";\n /** Grid name. Default: the channel's grid name in the `.wvdb`. */\n gridName?: string;\n}\n\n/** The converted grid plus the index box the dense texture covered. */\nexport interface WvdbNvdbGrid extends VDBBuiltGrid {\n /** `[0, 0, 0]` to `dims − 1`: the dense texture's voxels (inclusive). */\n readonly textureIndexBox: { min: [number, number, number]; max: [number, number, number] };\n /**\n * K5.9: the `vdbSparseSource` options (`@pmndrs/vdb/three`) that line a sparse copy up with the dense source: the\n * texture's index box, the dense density stats (so `normalizeDensity` divides by the same mean) and the `.wvdb`\n * box (when it has one). Spread them in: `vdbSparseSource(grids, { density: id }, { ...grid.sparseSourceOptions, lod })`.\n * For an aux channel (mask, emission) pass `textureIndexBox` as its `auxIndexBoxes` entry instead.\n */\n readonly sparseSourceOptions: {\n readonly indexBox: { min: [number, number, number]; max: [number, number, number] };\n readonly stats: { meanNonZero: number; max: number; activeVoxels: number };\n readonly bbox?: [[number, number, number], [number, number, number]];\n };\n}\n\n/** Converts one scalar channel of a dense `.wvdb` level to a NanoVDB FLOAT grid, voxel for voxel. */\nexport function wvdbDenseToNvdb(volume: WvdbDenseVolume, o: WvdbDenseToNvdbOptions = {}): WvdbNvdbGrid {\n const channel = o.channel ?? \"density\";\n const tex = volume[channel];\n if (!tex) throw new VDBToolsError(\"VDB_BAD_OPTION\", `wvdbDenseToNvdb: the volume has no ${channel} channel`);\n if (tex.texelBytes !== 1) throw new VDBToolsError(\"VDB_BAD_OPTION\", `wvdbDenseToNvdb: the ${channel} channel is not scalar (r8unorm)`);\n const [w, h, d] = tex.dimensions;\n const values = new Float32Array(w * h * d);\n // Texels are x fastest (x + (y + z·h)·w); vdbBuildFromDense reads x-major ((x·h + y)·d + z).\n for (let z = 0; z < d; z++)\n for (let y = 0; y < h; y++)\n for (let x = 0; x < w; x++) values[(x * h + y) * d + z] = tex.data[x + (y + z * h) * w]! / 255;\n const bbox = volume.bbox;\n // Per axis (G15a): a bake rounds each side's texel count on its own, so the voxels are not cubic.\n const voxelSize = [w, h, d].map((n, a) => {\n const v = bbox ? (bbox[1][a]! - bbox[0][a]!) / n : 1;\n return v > 0 && Number.isFinite(v) ? v : 1;\n }) as [number, number, number];\n const worldOrigin: [number, number, number] = bbox\n ? [bbox[0][0] + voxelSize[0] / 2, bbox[0][1] + voxelSize[1] / 2, bbox[0][2] + voxelSize[2] / 2]\n : [0, 0, 0];\n const built = vdbBuildFromDenseDetailed(values, [w, h, d], {\n voxelSize,\n worldOrigin,\n background: 0,\n gridName: o.gridName ?? volume.gridNames[channel] ?? channel,\n gridClass: \"FogVolume\",\n });\n const textureIndexBox = { min: [0, 0, 0] as [number, number, number], max: [w - 1, h - 1, d - 1] as [number, number, number] };\n const sparseSourceOptions = {\n indexBox: { min: [...textureIndexBox.min] as [number, number, number], max: [...textureIndexBox.max] as [number, number, number] },\n stats: { meanNonZero: volume.meanDensity, max: volume.maxDensity, activeVoxels: volume.activeTexels },\n ...(bbox ? { bbox: [[...bbox[0]], [...bbox[1]]] as [[number, number, number], [number, number, number]] } : {}),\n };\n return { ...built, textureIndexBox, sparseSourceOptions };\n}\n"]}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* read.ts — `.wvdb` reader (mjurczyk's WebVDB spec v0.5.x, file versions 1
|
|
3
|
+
* and 2): header parsing and validation (§4, §5, §14), whole-file decode, and
|
|
4
|
+
* coarse-first decode from a prefix, a byte range, or a stream (§9, §12.2).
|
|
5
|
+
*
|
|
6
|
+
* Portions derived from mjurczyk/openvdb (MIT), commit 75e7345: the chunk
|
|
7
|
+
* walk mirrors `getWVDBChunks` in `src/openvdb/wvdb/format.js`, and the
|
|
8
|
+
* per-LOD layout rule (a LOD is sparse iff it has a `mask`) mirrors
|
|
9
|
+
* `WVDBReader.getKernelGrid` in `src/three-openvdb/wvdb/WVDBReader.js`.
|
|
10
|
+
*
|
|
11
|
+
* The stream reader decodes chunk by chunk (K4.13), so it holds one chunk's
|
|
12
|
+
* compressed bytes at a time and can show a LOD before all its pages arrive.
|
|
13
|
+
*
|
|
14
|
+
* Decoded volume LODs are dense `Float32Array`s: channel planes one after the
|
|
15
|
+
* other (`values[c * X*Y*Z + x + y*X + z*X*Y]`), x fastest. Voxels of bricks a
|
|
16
|
+
* sparse LOD does not store hold the background (§12.2.3); voxels of a brick
|
|
17
|
+
* outside the LOD are dropped (§3.3). Values are float32, computed exactly as
|
|
18
|
+
* his `decodeWVDBPage` computes them.
|
|
19
|
+
*/
|
|
20
|
+
import { type WvdbBake, type WvdbBox, type WvdbGridClass, type WvdbGridHeader, type WvdbHeader, type WvdbLayout, type WvdbPointsGridHeader, type WvdbSource, type WvdbVec3, type WvdbVolumeGridHeader } from "./format.js";
|
|
21
|
+
export interface WvdbHeaderInfo {
|
|
22
|
+
header: WvdbHeader;
|
|
23
|
+
/** File version from the preamble (equals `header.version`). */
|
|
24
|
+
version: number;
|
|
25
|
+
/** Absolute file offset of the data section; chunk offsets are relative to it. */
|
|
26
|
+
dataStart: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ReadWvdbHeaderOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Total file length, when known. Enables the §14 checks that need it:
|
|
31
|
+
* `headerLength <= fileLength - 12` and every chunk inside the data section.
|
|
32
|
+
*/
|
|
33
|
+
fileLength?: number;
|
|
34
|
+
/** Refuse a LOD whose `X * Y * Z * channels` exceeds this before allocating (§14). Default 2^28. */
|
|
35
|
+
maxVoxels?: number;
|
|
36
|
+
/** Also check the §9 chunk order: coarse to fine, grid order, no gaps. Default false. */
|
|
37
|
+
strictChunkOrder?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** §5.4: any other class string reads as `"unknown"`. */
|
|
40
|
+
export declare function normalizeWvdbClass(value: string): WvdbGridClass;
|
|
41
|
+
/**
|
|
42
|
+
* Reads the preamble and header. Returns `null` while `bytes` (a prefix of
|
|
43
|
+
* the file) does not yet hold the whole header; throws `WvdbFormatError` on a
|
|
44
|
+
* bad magic, an unsupported version, or a header that breaks §5/§14.
|
|
45
|
+
*/
|
|
46
|
+
export declare function readWvdbHeader(bytes: Uint8Array, opts?: ReadWvdbHeaderOptions): WvdbHeaderInfo | null;
|
|
47
|
+
export interface WvdbChunkInfo {
|
|
48
|
+
gridIndex: number;
|
|
49
|
+
lod: number;
|
|
50
|
+
kind: "mask" | "page" | "points";
|
|
51
|
+
/** Relative to dataStart. */
|
|
52
|
+
offset: number;
|
|
53
|
+
length: number;
|
|
54
|
+
/** page: bricks in the page; points: points in the chunk; mask: 0. */
|
|
55
|
+
count: number;
|
|
56
|
+
/** page: index of the first brick of a dense page. points: stored index of the first point. */
|
|
57
|
+
first: number;
|
|
58
|
+
}
|
|
59
|
+
/** All chunks in §9 writer order (LOD, then grid, then mask, then pages). */
|
|
60
|
+
export declare function wvdbChunks(header: WvdbHeader): WvdbChunkInfo[];
|
|
61
|
+
/**
|
|
62
|
+
* Absolute file byte range `[start, end)` that holds the chunks of `lod` for
|
|
63
|
+
* all grids (one contiguous range in a conforming file, §9). `start === end`
|
|
64
|
+
* when the LOD has no chunks.
|
|
65
|
+
*/
|
|
66
|
+
export declare function wvdbLodByteRange(info: WvdbHeaderInfo, lod: number): {
|
|
67
|
+
start: number;
|
|
68
|
+
end: number;
|
|
69
|
+
};
|
|
70
|
+
/** Bytes from the start of the file needed to decode LODs 0..lod (header included). */
|
|
71
|
+
export declare function wvdbPrefixLength(info: WvdbHeaderInfo, lod: number): number;
|
|
72
|
+
export interface WvdbVolumeLevel {
|
|
73
|
+
kind: "volume";
|
|
74
|
+
lod: number;
|
|
75
|
+
dimensions: WvdbVec3;
|
|
76
|
+
layout: WvdbLayout;
|
|
77
|
+
channels: 1 | 3;
|
|
78
|
+
brickCounts: WvdbVec3;
|
|
79
|
+
brickTotal: number;
|
|
80
|
+
/** Mask words of a sparse LOD (bit `index` set = stored); null for dense. */
|
|
81
|
+
mask: Uint32Array | null;
|
|
82
|
+
/** Stored brick indices in file order (dense: 0..brickTotal-1). */
|
|
83
|
+
brickIndices: Uint32Array;
|
|
84
|
+
/** Brick channel ranges in file order, `b * channels + c`. */
|
|
85
|
+
mins: Float32Array;
|
|
86
|
+
maxs: Float32Array;
|
|
87
|
+
/** Dense decoded values: channel planes, x fastest; background where no brick is stored. */
|
|
88
|
+
values: Float32Array;
|
|
89
|
+
/** Bricks decoded so far (equals the LOD's brick count once complete; less in a partial stream event). */
|
|
90
|
+
bricksDecoded: number;
|
|
91
|
+
}
|
|
92
|
+
export interface WvdbPointsLevel {
|
|
93
|
+
kind: "points";
|
|
94
|
+
lod: number;
|
|
95
|
+
/** Stored index of the first point of this LOD within the LOD-ordered point list. */
|
|
96
|
+
firstPoint: number;
|
|
97
|
+
count: number;
|
|
98
|
+
/** xyz per point. */
|
|
99
|
+
positions: Float32Array;
|
|
100
|
+
/** rgb per point in [0, 1], or null when the grid has no colours. */
|
|
101
|
+
colors: Float32Array | null;
|
|
102
|
+
/** Points decoded so far (equals `count` once complete; less in a partial stream event). */
|
|
103
|
+
pointsDecoded: number;
|
|
104
|
+
}
|
|
105
|
+
export type WvdbLevel = WvdbVolumeLevel | WvdbPointsLevel;
|
|
106
|
+
interface WvdbGridBase {
|
|
107
|
+
name: string;
|
|
108
|
+
/** Normalized per §5.4 (unknown strings become `"unknown"`). */
|
|
109
|
+
class: WvdbGridClass;
|
|
110
|
+
bbox: WvdbBox | null;
|
|
111
|
+
header: WvdbGridHeader;
|
|
112
|
+
}
|
|
113
|
+
export interface WvdbVolumeGrid extends WvdbGridBase {
|
|
114
|
+
kind: "volume";
|
|
115
|
+
channels: 1 | 3;
|
|
116
|
+
/** One value per channel. */
|
|
117
|
+
background: number[];
|
|
118
|
+
meanDensity?: number;
|
|
119
|
+
nonZeroVoxels?: number;
|
|
120
|
+
header: WvdbVolumeGridHeader;
|
|
121
|
+
/** Decoded LODs, coarse first (`levels[k].lod === k`). */
|
|
122
|
+
levels: WvdbVolumeLevel[];
|
|
123
|
+
}
|
|
124
|
+
export interface WvdbPointsGrid extends WvdbGridBase {
|
|
125
|
+
kind: "points";
|
|
126
|
+
count: number;
|
|
127
|
+
sourceCount?: number;
|
|
128
|
+
spacing?: number;
|
|
129
|
+
colors: boolean;
|
|
130
|
+
header: WvdbPointsGridHeader;
|
|
131
|
+
/** Decoded LODs, coarse first. LOD k adds its points to LODs 0..k-1 (§3.5). */
|
|
132
|
+
levels: WvdbPointsLevel[];
|
|
133
|
+
}
|
|
134
|
+
export type WvdbGrid = WvdbVolumeGrid | WvdbPointsGrid;
|
|
135
|
+
export interface WvdbFile {
|
|
136
|
+
version: number;
|
|
137
|
+
header: WvdbHeader;
|
|
138
|
+
dataStart: number;
|
|
139
|
+
source: WvdbSource;
|
|
140
|
+
bake: WvdbBake;
|
|
141
|
+
grids: WvdbGrid[];
|
|
142
|
+
/** Number of LODs decoded (LODs 0..lodsDecoded-1). */
|
|
143
|
+
lodsDecoded: number;
|
|
144
|
+
/** True when every LOD of the file is decoded. */
|
|
145
|
+
complete: boolean;
|
|
146
|
+
}
|
|
147
|
+
/** Inflates one zlib chunk, stopping past `maxSize` bytes (§14). */
|
|
148
|
+
export declare function inflateWvdbChunk(bytes: Uint8Array, maxSize: number): Uint8Array;
|
|
149
|
+
/**
|
|
150
|
+
* Decodes LOD `lod` of every grid. `bytes` holds file bytes starting at file
|
|
151
|
+
* offset `byteOffset` (0 for the whole file or a prefix; `range.start` for a
|
|
152
|
+
* range read from `wvdbLodByteRange`). Returns one level per grid, in header
|
|
153
|
+
* order.
|
|
154
|
+
*/
|
|
155
|
+
export declare function decodeWvdbLod(info: WvdbHeaderInfo, lod: number, bytes: Uint8Array, byteOffset?: number): WvdbLevel[];
|
|
156
|
+
export interface ReadWvdbOptions extends Omit<ReadWvdbHeaderOptions, "fileLength"> {
|
|
157
|
+
/** Decode LODs 0..maxLod only. Default: all. */
|
|
158
|
+
maxLod?: number;
|
|
159
|
+
/**
|
|
160
|
+
* `bytes` is a prefix of the file (a stream so far, or a `Range: bytes=0-N`
|
|
161
|
+
* read): decode the LODs it holds completely and stop. Default false: the
|
|
162
|
+
* bytes are the whole file, and every chunk must be inside them.
|
|
163
|
+
*/
|
|
164
|
+
partial?: boolean;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Reads a `.wvdb` file (or, with `partial`, a prefix of one) and decodes its
|
|
168
|
+
* LODs coarse to fine.
|
|
169
|
+
*/
|
|
170
|
+
export declare function readWvdb(input: Uint8Array | ArrayBuffer, opts?: ReadWvdbOptions): WvdbFile;
|
|
171
|
+
export interface WvdbLodEvent {
|
|
172
|
+
lod: number;
|
|
173
|
+
/**
|
|
174
|
+
* One level per grid, in header order. For a partial event these are the
|
|
175
|
+
* LOD's levels in progress: later pages fill the same objects, and
|
|
176
|
+
* `bricksDecoded` / `pointsDecoded` say how much is in.
|
|
177
|
+
*/
|
|
178
|
+
levels: WvdbLevel[];
|
|
179
|
+
/** True once every chunk of the LOD is decoded (always, unless `partialLods`). */
|
|
180
|
+
complete: boolean;
|
|
181
|
+
/** Partial events: the chunk just decoded (a page's bricks are `brickIndices[first .. first + count)`). */
|
|
182
|
+
chunk?: WvdbChunkInfo;
|
|
183
|
+
}
|
|
184
|
+
export interface WvdbStreamReaderOptions extends Omit<ReadWvdbOptions, "partial"> {
|
|
185
|
+
/**
|
|
186
|
+
* Also emit an event (`complete: false`) after every chunk of a LOD decodes,
|
|
187
|
+
* so a LOD can be shown before all its pages arrive (§12.2). Default false:
|
|
188
|
+
* one event per finished LOD.
|
|
189
|
+
*/
|
|
190
|
+
partialLods?: boolean;
|
|
191
|
+
/** Refuse a header longer than this many bytes before buffering it. Default 16 MiB. */
|
|
192
|
+
maxHeaderBytes?: number;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Largest compressed size accepted for a chunk that inflates to at most `n`
|
|
196
|
+
* bytes: zlib's `compressBound` is about `n + n/4096 + 13`; this allows
|
|
197
|
+
* `n + n/1024 + 1 KiB`, which any deflate encoder's output fits (stored blocks
|
|
198
|
+
* cost 5 bytes per 64 KiB). The stream reader holds one chunk's bytes at a
|
|
199
|
+
* time, so this is its memory bound.
|
|
200
|
+
*/
|
|
201
|
+
export declare function wvdbChunkByteLimit(inflatedBytes: number): number;
|
|
202
|
+
/**
|
|
203
|
+
* Push-style coarse-first decoder for a `.wvdb` download: feed it the bytes
|
|
204
|
+
* as they arrive; each `push` returns the LODs that became complete (and,
|
|
205
|
+
* with `partialLods`, the LODs that gained a page).
|
|
206
|
+
*
|
|
207
|
+
* const reader = new WvdbStreamReader({ partialLods: true });
|
|
208
|
+
* for await (const chunk of response.body) for (const e of reader.push(chunk)) show(e);
|
|
209
|
+
* reader.end();
|
|
210
|
+
*
|
|
211
|
+
* Chunks are decoded one at a time, in file order, as soon as their last byte
|
|
212
|
+
* arrives, so the reader holds at most one chunk's compressed bytes (plus the
|
|
213
|
+
* header until it parses) besides the decoded LODs: `peakBufferedBytes` is
|
|
214
|
+
* bounded by the largest chunk plus one pushed buffer. Each chunk's length is
|
|
215
|
+
* checked against {@link wvdbChunkByteLimit} when the header arrives. After an
|
|
216
|
+
* error, every later call throws the same error.
|
|
217
|
+
*/
|
|
218
|
+
export declare class WvdbStreamReader {
|
|
219
|
+
private readonly opts;
|
|
220
|
+
private buf;
|
|
221
|
+
/** Absolute file offset of `buf[0]`, and one past the last byte held. */
|
|
222
|
+
private bufStart;
|
|
223
|
+
private bufEnd;
|
|
224
|
+
private received;
|
|
225
|
+
private next;
|
|
226
|
+
private finalLod;
|
|
227
|
+
private chunks;
|
|
228
|
+
private ci;
|
|
229
|
+
private remaining;
|
|
230
|
+
private decoders;
|
|
231
|
+
private failure;
|
|
232
|
+
private peak;
|
|
233
|
+
info: WvdbHeaderInfo | null;
|
|
234
|
+
/** The decoded file so far (grids gain levels as LODs complete); null before the header. */
|
|
235
|
+
file: WvdbFile | null;
|
|
236
|
+
constructor(opts?: WvdbStreamReaderOptions);
|
|
237
|
+
get header(): WvdbHeader | null;
|
|
238
|
+
/** True when every LOD up to `maxLod` is decoded. */
|
|
239
|
+
get done(): boolean;
|
|
240
|
+
/** File bytes needed to finish (header known), or null before the header. */
|
|
241
|
+
get bytesTotal(): number | null;
|
|
242
|
+
/** File bytes pushed so far. */
|
|
243
|
+
get bytesReceived(): number;
|
|
244
|
+
/** Compressed bytes held now, and the most ever held. */
|
|
245
|
+
get bufferedBytes(): number;
|
|
246
|
+
get peakBufferedBytes(): number;
|
|
247
|
+
push(chunk: Uint8Array): WvdbLodEvent[];
|
|
248
|
+
/** Call when the stream ends: throws `WvdbFormatError` if a LOD up to `maxLod` is still missing. */
|
|
249
|
+
end(): void;
|
|
250
|
+
/** Absolute offset below which no byte is needed any more. */
|
|
251
|
+
private keepFrom;
|
|
252
|
+
/** Drops held bytes before `keepFrom()`. */
|
|
253
|
+
private compact;
|
|
254
|
+
private append;
|
|
255
|
+
private readHeader;
|
|
256
|
+
private decodersFor;
|
|
257
|
+
private decodeChunks;
|
|
258
|
+
private completeLods;
|
|
259
|
+
}
|
|
260
|
+
export {};
|