@pmndrs/vdb 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +727 -0
- package/LICENSE +21 -0
- package/README.md +496 -2
- package/THIRD_PARTY_NOTICES.md +315 -0
- package/dist/core/compute/atlas.d.ts +102 -0
- package/dist/core/compute/atlas.js +103 -0
- package/dist/core/compute/atlas.js.map +1 -0
- package/dist/core/compute/index.d.ts +13 -0
- package/dist/core/compute/index.js +9 -0
- package/dist/core/compute/index.js.map +1 -0
- package/dist/core/compute/majorant-build.d.ts +45 -0
- package/dist/core/compute/majorant-build.js +193 -0
- package/dist/core/compute/majorant-build.js.map +1 -0
- package/dist/core/compute/multi-scale.d.ts +155 -0
- package/dist/core/compute/multi-scale.js +684 -0
- package/dist/core/compute/multi-scale.js.map +1 -0
- package/dist/core/compute/pyramid.d.ts +120 -0
- package/dist/core/compute/pyramid.js +468 -0
- package/dist/core/compute/pyramid.js.map +1 -0
- package/dist/core/compute/shared.d.ts +116 -0
- package/dist/core/compute/shared.js +211 -0
- package/dist/core/compute/shared.js.map +1 -0
- package/dist/core/compute/stats.d.ts +78 -0
- package/dist/core/compute/stats.js +193 -0
- package/dist/core/compute/stats.js.map +1 -0
- package/dist/core/compute/value-transform.d.ts +30 -0
- package/dist/core/compute/value-transform.js +64 -0
- package/dist/core/compute/value-transform.js.map +1 -0
- package/dist/core/errors.d.ts +21 -0
- package/dist/core/errors.js +17 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/frame/emission.d.ts +85 -0
- package/dist/core/frame/emission.js +422 -0
- package/dist/core/frame/emission.js.map +1 -0
- package/dist/core/frame/environment.d.ts +47 -0
- package/dist/core/frame/environment.js +178 -0
- package/dist/core/frame/environment.js.map +1 -0
- package/dist/core/frame/index.d.ts +39 -0
- package/dist/core/frame/index.js +27 -0
- package/dist/core/frame/index.js.map +1 -0
- package/dist/core/frame/kernels.d.ts +115 -0
- package/dist/core/frame/kernels.js +496 -0
- package/dist/core/frame/kernels.js.map +1 -0
- package/dist/core/frame/limits.d.ts +67 -0
- package/dist/core/frame/limits.js +109 -0
- package/dist/core/frame/limits.js.map +1 -0
- package/dist/core/frame/phase.d.ts +17 -0
- package/dist/core/frame/phase.js +53 -0
- package/dist/core/frame/phase.js.map +1 -0
- package/dist/core/frame/pipelines.d.ts +49 -0
- package/dist/core/frame/pipelines.js +147 -0
- package/dist/core/frame/pipelines.js.map +1 -0
- package/dist/core/frame/renderer.d.ts +122 -0
- package/dist/core/frame/renderer.js +1712 -0
- package/dist/core/frame/renderer.js.map +1 -0
- package/dist/core/frame/resources.d.ts +71 -0
- package/dist/core/frame/resources.js +100 -0
- package/dist/core/frame/resources.js.map +1 -0
- package/dist/core/frame/scattering.d.ts +97 -0
- package/dist/core/frame/scattering.js +332 -0
- package/dist/core/frame/scattering.js.map +1 -0
- package/dist/core/frame/settings.d.ts +243 -0
- package/dist/core/frame/settings.js +67 -0
- package/dist/core/frame/settings.js.map +1 -0
- package/dist/core/frame/shadows.d.ts +55 -0
- package/dist/core/frame/shadows.js +460 -0
- package/dist/core/frame/shadows.js.map +1 -0
- package/dist/core/frame/types.d.ts +415 -0
- package/dist/core/frame/types.js +49 -0
- package/dist/core/frame/types.js.map +1 -0
- package/dist/core/frame/uniforms.d.ts +105 -0
- package/dist/core/frame/uniforms.js +276 -0
- package/dist/core/frame/uniforms.js.map +1 -0
- package/dist/core/frame/wgsl/chunks.d.ts +4 -0
- package/dist/core/frame/wgsl/chunks.js +728 -0
- package/dist/core/frame/wgsl/chunks.js.map +1 -0
- package/dist/core/frame/wgsl/emission.d.ts +82 -0
- package/dist/core/frame/wgsl/emission.js +353 -0
- package/dist/core/frame/wgsl/emission.js.map +1 -0
- package/dist/core/frame/wgsl/environment.d.ts +42 -0
- package/dist/core/frame/wgsl/environment.js +711 -0
- package/dist/core/frame/wgsl/environment.js.map +1 -0
- package/dist/core/frame/wgsl/gather.d.ts +55 -0
- package/dist/core/frame/wgsl/gather.js +850 -0
- package/dist/core/frame/wgsl/gather.js.map +1 -0
- package/dist/core/frame/wgsl/integrate.d.ts +78 -0
- package/dist/core/frame/wgsl/integrate.js +213 -0
- package/dist/core/frame/wgsl/integrate.js.map +1 -0
- package/dist/core/frame/wgsl/lighting.d.ts +103 -0
- package/dist/core/frame/wgsl/lighting.js +1636 -0
- package/dist/core/frame/wgsl/lighting.js.map +1 -0
- package/dist/core/frame/wgsl/occluders.d.ts +20 -0
- package/dist/core/frame/wgsl/occluders.js +95 -0
- package/dist/core/frame/wgsl/occluders.js.map +1 -0
- package/dist/core/frame/wgsl/resolve.d.ts +19 -0
- package/dist/core/frame/wgsl/resolve.js +205 -0
- package/dist/core/frame/wgsl/resolve.js.map +1 -0
- package/dist/core/frame/wgsl/shadows.d.ts +35 -0
- package/dist/core/frame/wgsl/shadows.js +328 -0
- package/dist/core/frame/wgsl/shadows.js.map +1 -0
- package/dist/core/half.d.ts +11 -0
- package/dist/core/half.js +22 -0
- package/dist/core/half.js.map +1 -0
- package/dist/core/index.d.ts +52 -0
- package/dist/core/index.js +46 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/internal.d.ts +31 -0
- package/dist/core/internal.js +32 -0
- package/dist/core/internal.js.map +1 -0
- package/dist/core/pool/affine.d.ts +34 -0
- package/dist/core/pool/affine.js +100 -0
- package/dist/core/pool/affine.js.map +1 -0
- package/dist/core/pool/allocator.d.ts +32 -0
- package/dist/core/pool/allocator.js +81 -0
- package/dist/core/pool/allocator.js.map +1 -0
- package/dist/core/pool/image-header.d.ts +93 -0
- package/dist/core/pool/image-header.js +194 -0
- package/dist/core/pool/image-header.js.map +1 -0
- package/dist/core/pool/layout.d.ts +198 -0
- package/dist/core/pool/layout.js +316 -0
- package/dist/core/pool/layout.js.map +1 -0
- package/dist/core/pool/limits.d.ts +41 -0
- package/dist/core/pool/limits.js +80 -0
- package/dist/core/pool/limits.js.map +1 -0
- package/dist/core/pool/pool.d.ts +384 -0
- package/dist/core/pool/pool.js +1184 -0
- package/dist/core/pool/pool.js.map +1 -0
- package/dist/core/reference/index.d.ts +6 -0
- package/dist/core/reference/index.js +7 -0
- package/dist/core/reference/index.js.map +1 -0
- package/dist/core/reference/renderer.d.ts +105 -0
- package/dist/core/reference/renderer.js +474 -0
- package/dist/core/reference/renderer.js.map +1 -0
- package/dist/core/reference/wgsl.d.ts +65 -0
- package/dist/core/reference/wgsl.js +803 -0
- package/dist/core/reference/wgsl.js.map +1 -0
- package/dist/core/sequence.d.ts +347 -0
- package/dist/core/sequence.js +548 -0
- package/dist/core/sequence.js.map +1 -0
- package/dist/core/source/brick-cache.d.ts +165 -0
- package/dist/core/source/brick-cache.js +627 -0
- package/dist/core/source/brick-cache.js.map +1 -0
- package/dist/core/source/dense-fill.d.ts +53 -0
- package/dist/core/source/dense-fill.js +377 -0
- package/dist/core/source/dense-fill.js.map +1 -0
- package/dist/core/source/dense.d.ts +50 -0
- package/dist/core/source/dense.js +384 -0
- package/dist/core/source/dense.js.map +1 -0
- package/dist/core/source/sparse-wgsl.d.ts +92 -0
- package/dist/core/source/sparse-wgsl.js +481 -0
- package/dist/core/source/sparse-wgsl.js.map +1 -0
- package/dist/core/source/sparse.d.ts +192 -0
- package/dist/core/source/sparse.js +762 -0
- package/dist/core/source/sparse.js.map +1 -0
- package/dist/core/source/types.d.ts +120 -0
- package/dist/core/source/types.js +9 -0
- package/dist/core/source/types.js.map +1 -0
- package/dist/core/surface/index.d.ts +10 -0
- package/dist/core/surface/index.js +9 -0
- package/dist/core/surface/index.js.map +1 -0
- package/dist/core/surface/level-set-pass.d.ts +140 -0
- package/dist/core/surface/level-set-pass.js +291 -0
- package/dist/core/surface/level-set-pass.js.map +1 -0
- package/dist/core/surface/level-set-wgsl.d.ts +46 -0
- package/dist/core/surface/level-set-wgsl.js +99 -0
- package/dist/core/surface/level-set-wgsl.js.map +1 -0
- package/dist/core/surface/points.d.ts +109 -0
- package/dist/core/surface/points.js +226 -0
- package/dist/core/surface/points.js.map +1 -0
- package/dist/core/types.d.ts +37 -0
- package/dist/core/types.js +32 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/wgsl/api.d.ts +65 -0
- package/dist/core/wgsl/api.js +546 -0
- package/dist/core/wgsl/api.js.map +1 -0
- package/dist/core/wgsl/generate.d.ts +90 -0
- package/dist/core/wgsl/generate.js +678 -0
- package/dist/core/wgsl/generate.js.map +1 -0
- package/dist/core/wgsl/lean.d.ts +50 -0
- package/dist/core/wgsl/lean.js +327 -0
- package/dist/core/wgsl/lean.js.map +1 -0
- package/dist/core/wgsl/level-set.d.ts +58 -0
- package/dist/core/wgsl/level-set.js +200 -0
- package/dist/core/wgsl/level-set.js.map +1 -0
- package/dist/core/wgsl/majorant.d.ts +62 -0
- package/dist/core/wgsl/majorant.js +381 -0
- package/dist/core/wgsl/majorant.js.map +1 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
- package/dist/core/wgsl/reserved.d.ts +9 -0
- package/dist/core/wgsl/reserved.js +26 -0
- package/dist/core/wgsl/reserved.js.map +1 -0
- package/dist/core/wgsl/types.d.ts +198 -0
- package/dist/core/wgsl/types.js +2 -0
- package/dist/core/wgsl/types.js.map +1 -0
- package/dist/three/coarse-first.d.ts +207 -0
- package/dist/three/coarse-first.js +205 -0
- package/dist/three/coarse-first.js.map +1 -0
- package/dist/three/compute.d.ts +73 -0
- package/dist/three/compute.js +66 -0
- package/dist/three/compute.js.map +1 -0
- package/dist/three/device.d.ts +66 -0
- package/dist/three/device.js +62 -0
- package/dist/three/device.js.map +1 -0
- package/dist/three/frame/core-environment.d.ts +38 -0
- package/dist/three/frame/core-environment.js +154 -0
- package/dist/three/frame/core-environment.js.map +1 -0
- package/dist/three/frame/core-integrate-material.d.ts +34 -0
- package/dist/three/frame/core-integrate-material.js +162 -0
- package/dist/three/frame/core-integrate-material.js.map +1 -0
- package/dist/three/frame/core-occluders.d.ts +53 -0
- package/dist/three/frame/core-occluders.js +193 -0
- package/dist/three/frame/core-occluders.js.map +1 -0
- package/dist/three/frame/core-structs.d.ts +34 -0
- package/dist/three/frame/core-structs.js +61 -0
- package/dist/three/frame/core-structs.js.map +1 -0
- package/dist/three/frame/core-textures.d.ts +41 -0
- package/dist/three/frame/core-textures.js +114 -0
- package/dist/three/frame/core-textures.js.map +1 -0
- package/dist/three/frame/emission-light.d.ts +117 -0
- package/dist/three/frame/emission-light.js +276 -0
- package/dist/three/frame/emission-light.js.map +1 -0
- package/dist/three/frame/index.d.ts +19 -0
- package/dist/three/frame/index.js +15 -0
- package/dist/three/frame/index.js.map +1 -0
- package/dist/three/frame/medium.d.ts +33 -0
- package/dist/three/frame/medium.js +29 -0
- package/dist/three/frame/medium.js.map +1 -0
- package/dist/three/frame/renderer.d.ts +97 -0
- package/dist/three/frame/renderer.js +480 -0
- package/dist/three/frame/renderer.js.map +1 -0
- package/dist/three/frame/spectrum.d.ts +4 -0
- package/dist/three/frame/spectrum.js +15 -0
- package/dist/three/frame/spectrum.js.map +1 -0
- package/dist/three/frame/three-internals.d.ts +60 -0
- package/dist/three/frame/three-internals.js +152 -0
- package/dist/three/frame/three-internals.js.map +1 -0
- package/dist/three/frame/volume-shadows.d.ts +139 -0
- package/dist/three/frame/volume-shadows.js +403 -0
- package/dist/three/frame/volume-shadows.js.map +1 -0
- package/dist/three/frame/volume.d.ts +230 -0
- package/dist/three/frame/volume.js +268 -0
- package/dist/three/frame/volume.js.map +1 -0
- package/dist/three/grid-node.d.ts +229 -0
- package/dist/three/grid-node.js +545 -0
- package/dist/three/grid-node.js.map +1 -0
- package/dist/three/index.d.ts +52 -0
- package/dist/three/index.js +58 -0
- package/dist/three/index.js.map +1 -0
- package/dist/three/internal.d.ts +20 -0
- package/dist/three/internal.js +18 -0
- package/dist/three/internal.js.map +1 -0
- package/dist/three/level-set-material.d.ts +185 -0
- package/dist/three/level-set-material.js +241 -0
- package/dist/three/level-set-material.js.map +1 -0
- package/dist/three/level-set-physical-material.d.ts +154 -0
- package/dist/three/level-set-physical-material.js +253 -0
- package/dist/three/level-set-physical-material.js.map +1 -0
- package/dist/three/level-set-velocity.d.ts +94 -0
- package/dist/three/level-set-velocity.js +208 -0
- package/dist/three/level-set-velocity.js.map +1 -0
- package/dist/three/material.d.ts +324 -0
- package/dist/three/material.js +502 -0
- package/dist/three/material.js.map +1 -0
- package/dist/three/points.d.ts +140 -0
- package/dist/three/points.js +261 -0
- package/dist/three/points.js.map +1 -0
- package/dist/three/sparse-source.d.ts +165 -0
- package/dist/three/sparse-source.js +405 -0
- package/dist/three/sparse-source.js.map +1 -0
- package/dist/three/volume-source.d.ts +22 -0
- package/dist/three/volume-source.js +110 -0
- package/dist/three/volume-source.js.map +1 -0
- package/dist/tools/cpu/brick-atlas.d.ts +36 -0
- package/dist/tools/cpu/brick-atlas.js +129 -0
- package/dist/tools/cpu/brick-atlas.js.map +1 -0
- package/dist/tools/cpu/compute.d.ts +116 -0
- package/dist/tools/cpu/compute.js +239 -0
- package/dist/tools/cpu/compute.js.map +1 -0
- package/dist/tools/cpu/lean-reads.d.ts +81 -0
- package/dist/tools/cpu/lean-reads.js +262 -0
- package/dist/tools/cpu/lean-reads.js.map +1 -0
- package/dist/tools/cpu/level-set.d.ts +111 -0
- package/dist/tools/cpu/level-set.js +313 -0
- package/dist/tools/cpu/level-set.js.map +1 -0
- package/dist/tools/cpu/majorant.d.ts +265 -0
- package/dist/tools/cpu/majorant.js +541 -0
- package/dist/tools/cpu/majorant.js.map +1 -0
- package/dist/tools/cpu/march.d.ts +297 -0
- package/dist/tools/cpu/march.js +726 -0
- package/dist/tools/cpu/march.js.map +1 -0
- package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
- package/dist/tools/cpu/mesh-decimate.js +1225 -0
- package/dist/tools/cpu/mesh-decimate.js.map +1 -0
- package/dist/tools/cpu/points.d.ts +29 -0
- package/dist/tools/cpu/points.js +38 -0
- package/dist/tools/cpu/points.js.map +1 -0
- package/dist/tools/cpu/probe-coords.d.ts +70 -0
- package/dist/tools/cpu/probe-coords.js +116 -0
- package/dist/tools/cpu/probe-coords.js.map +1 -0
- package/dist/tools/cpu/read-value.d.ts +44 -0
- package/dist/tools/cpu/read-value.js +351 -0
- package/dist/tools/cpu/read-value.js.map +1 -0
- package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
- package/dist/tools/cpu/sample-trilinear.js +168 -0
- package/dist/tools/cpu/sample-trilinear.js.map +1 -0
- package/dist/tools/cpu/stride-tables.d.ts +56 -0
- package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
- package/dist/tools/cpu/stride-tables.generated.js +1267 -0
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
- package/dist/tools/cpu/stride-tables.js +78 -0
- package/dist/tools/cpu/stride-tables.js.map +1 -0
- package/dist/tools/cpu/surface-nets.d.ts +90 -0
- package/dist/tools/cpu/surface-nets.js +597 -0
- package/dist/tools/cpu/surface-nets.js.map +1 -0
- package/dist/tools/errors.d.ts +66 -0
- package/dist/tools/errors.js +67 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/frame/ambient.d.ts +98 -0
- package/dist/tools/frame/ambient.js +274 -0
- package/dist/tools/frame/ambient.js.map +1 -0
- package/dist/tools/frame/blackbody.d.ts +57 -0
- package/dist/tools/frame/blackbody.js +151 -0
- package/dist/tools/frame/blackbody.js.map +1 -0
- package/dist/tools/frame/brick-cache.d.ts +165 -0
- package/dist/tools/frame/brick-cache.js +326 -0
- package/dist/tools/frame/brick-cache.js.map +1 -0
- package/dist/tools/frame/emission.d.ts +137 -0
- package/dist/tools/frame/emission.js +290 -0
- package/dist/tools/frame/emission.js.map +1 -0
- package/dist/tools/frame/environment-gpu.d.ts +111 -0
- package/dist/tools/frame/environment-gpu.js +280 -0
- package/dist/tools/frame/environment-gpu.js.map +1 -0
- package/dist/tools/frame/environment.d.ts +106 -0
- package/dist/tools/frame/environment.js +272 -0
- package/dist/tools/frame/environment.js.map +1 -0
- package/dist/tools/frame/froxel.d.ts +58 -0
- package/dist/tools/frame/froxel.js +115 -0
- package/dist/tools/frame/froxel.js.map +1 -0
- package/dist/tools/frame/grid.d.ts +392 -0
- package/dist/tools/frame/grid.js +802 -0
- package/dist/tools/frame/grid.js.map +1 -0
- package/dist/tools/frame/index.d.ts +150 -0
- package/dist/tools/frame/index.js +389 -0
- package/dist/tools/frame/index.js.map +1 -0
- package/dist/tools/frame/medium.d.ts +77 -0
- package/dist/tools/frame/medium.js +101 -0
- package/dist/tools/frame/medium.js.map +1 -0
- package/dist/tools/frame/mie-table.d.ts +6 -0
- package/dist/tools/frame/mie-table.js +16 -0
- package/dist/tools/frame/mie-table.js.map +1 -0
- package/dist/tools/frame/mie.d.ts +63 -0
- package/dist/tools/frame/mie.js +194 -0
- package/dist/tools/frame/mie.js.map +1 -0
- package/dist/tools/frame/mlp-nn.d.ts +36 -0
- package/dist/tools/frame/mlp-nn.js +159 -0
- package/dist/tools/frame/mlp-nn.js.map +1 -0
- package/dist/tools/frame/mlp-tza.d.ts +29 -0
- package/dist/tools/frame/mlp-tza.js +186 -0
- package/dist/tools/frame/mlp-tza.js.map +1 -0
- package/dist/tools/frame/mlp.d.ts +183 -0
- package/dist/tools/frame/mlp.js +434 -0
- package/dist/tools/frame/mlp.js.map +1 -0
- package/dist/tools/frame/ms-exit.d.ts +42 -0
- package/dist/tools/frame/ms-exit.js +90 -0
- package/dist/tools/frame/ms-exit.js.map +1 -0
- package/dist/tools/frame/multi-scale.d.ts +152 -0
- package/dist/tools/frame/multi-scale.js +302 -0
- package/dist/tools/frame/multi-scale.js.map +1 -0
- package/dist/tools/frame/neural-weights.d.ts +10 -0
- package/dist/tools/frame/neural-weights.js +244 -0
- package/dist/tools/frame/neural-weights.js.map +1 -0
- package/dist/tools/frame/neural.d.ts +80 -0
- package/dist/tools/frame/neural.js +150 -0
- package/dist/tools/frame/neural.js.map +1 -0
- package/dist/tools/frame/occluders.d.ts +51 -0
- package/dist/tools/frame/occluders.js +72 -0
- package/dist/tools/frame/occluders.js.map +1 -0
- package/dist/tools/frame/pyramid-layout.d.ts +55 -0
- package/dist/tools/frame/pyramid-layout.js +100 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -0
- package/dist/tools/frame/shadows.d.ts +190 -0
- package/dist/tools/frame/shadows.js +468 -0
- package/dist/tools/frame/shadows.js.map +1 -0
- package/dist/tools/frame/sparse.d.ts +147 -0
- package/dist/tools/frame/sparse.js +432 -0
- package/dist/tools/frame/sparse.js.map +1 -0
- package/dist/tools/frame/spectral-stack.d.ts +159 -0
- package/dist/tools/frame/spectral-stack.js +391 -0
- package/dist/tools/frame/spectral-stack.js.map +1 -0
- package/dist/tools/frame/spectral.d.ts +222 -0
- package/dist/tools/frame/spectral.js +572 -0
- package/dist/tools/frame/spectral.js.map +1 -0
- package/dist/tools/frame/stack.d.ts +115 -0
- package/dist/tools/frame/stack.js +290 -0
- package/dist/tools/frame/stack.js.map +1 -0
- package/dist/tools/frame/view.d.ts +131 -0
- package/dist/tools/frame/view.js +337 -0
- package/dist/tools/frame/view.js.map +1 -0
- package/dist/tools/index.d.ts +157 -0
- package/dist/tools/index.js +132 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internal.d.ts +87 -0
- package/dist/tools/internal.js +85 -0
- package/dist/tools/internal.js.map +1 -0
- package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
- package/dist/tools/nanovdb/build-from-vdb.js +100 -0
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
- package/dist/tools/nanovdb/bytes.d.ts +233 -0
- package/dist/tools/nanovdb/bytes.js +388 -0
- package/dist/tools/nanovdb/bytes.js.map +1 -0
- package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
- package/dist/tools/nanovdb/coarse-first.js +92 -0
- package/dist/tools/nanovdb/coarse-first.js.map +1 -0
- package/dist/tools/nanovdb/half.d.ts +22 -0
- package/dist/tools/nanovdb/half.js +73 -0
- package/dist/tools/nanovdb/half.js.map +1 -0
- package/dist/tools/nanovdb/index.d.ts +34 -0
- package/dist/tools/nanovdb/index.js +25 -0
- package/dist/tools/nanovdb/index.js.map +1 -0
- package/dist/tools/nanovdb/inspect.d.ts +33 -0
- package/dist/tools/nanovdb/inspect.js +70 -0
- package/dist/tools/nanovdb/inspect.js.map +1 -0
- package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
- package/dist/tools/nanovdb/leaf-codec.js +356 -0
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
- package/dist/tools/nanovdb/quantize.d.ts +72 -0
- package/dist/tools/nanovdb/quantize.js +329 -0
- package/dist/tools/nanovdb/quantize.js.map +1 -0
- package/dist/tools/nanovdb/resample.d.ts +177 -0
- package/dist/tools/nanovdb/resample.js +692 -0
- package/dist/tools/nanovdb/resample.js.map +1 -0
- package/dist/tools/nanovdb/serialize.d.ts +176 -0
- package/dist/tools/nanovdb/serialize.js +439 -0
- package/dist/tools/nanovdb/serialize.js.map +1 -0
- package/dist/tools/nanovdb/stats.d.ts +87 -0
- package/dist/tools/nanovdb/stats.js +225 -0
- package/dist/tools/nanovdb/stats.js.map +1 -0
- package/dist/tools/nanovdb/transform.d.ts +30 -0
- package/dist/tools/nanovdb/transform.js +94 -0
- package/dist/tools/nanovdb/transform.js.map +1 -0
- package/dist/tools/nanovdb/tree.d.ts +186 -0
- package/dist/tools/nanovdb/tree.js +530 -0
- package/dist/tools/nanovdb/tree.js.map +1 -0
- package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
- package/dist/tools/nanovdb/write-nvdb.js +290 -0
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
- package/dist/tools/nvdb-file.d.ts +265 -0
- package/dist/tools/nvdb-file.js +763 -0
- package/dist/tools/nvdb-file.js.map +1 -0
- package/dist/tools/nvdb-stream.d.ts +154 -0
- package/dist/tools/nvdb-stream.js +409 -0
- package/dist/tools/nvdb-stream.js.map +1 -0
- package/dist/tools/reference/analytic.d.ts +41 -0
- package/dist/tools/reference/analytic.js +95 -0
- package/dist/tools/reference/analytic.js.map +1 -0
- package/dist/tools/reference/environment.d.ts +62 -0
- package/dist/tools/reference/environment.js +154 -0
- package/dist/tools/reference/environment.js.map +1 -0
- package/dist/tools/reference/index.d.ts +12 -0
- package/dist/tools/reference/index.js +13 -0
- package/dist/tools/reference/index.js.map +1 -0
- package/dist/tools/reference/media.d.ts +14 -0
- package/dist/tools/reference/media.js +30 -0
- package/dist/tools/reference/media.js.map +1 -0
- package/dist/tools/reference/rng.d.ts +20 -0
- package/dist/tools/reference/rng.js +30 -0
- package/dist/tools/reference/rng.js.map +1 -0
- package/dist/tools/reference/scene.d.ts +312 -0
- package/dist/tools/reference/scene.js +169 -0
- package/dist/tools/reference/scene.js.map +1 -0
- package/dist/tools/reference/tables.d.ts +98 -0
- package/dist/tools/reference/tables.js +264 -0
- package/dist/tools/reference/tables.js.map +1 -0
- package/dist/tools/reference/trace.d.ts +160 -0
- package/dist/tools/reference/trace.js +497 -0
- package/dist/tools/reference/trace.js.map +1 -0
- package/dist/tools/vdb/bit-utils.d.ts +20 -0
- package/dist/tools/vdb/bit-utils.js +42 -0
- package/dist/tools/vdb/bit-utils.js.map +1 -0
- package/dist/tools/vdb/blosc-write.d.ts +43 -0
- package/dist/tools/vdb/blosc-write.js +197 -0
- package/dist/tools/vdb/blosc-write.js.map +1 -0
- package/dist/tools/vdb/blosc.d.ts +86 -0
- package/dist/tools/vdb/blosc.js +287 -0
- package/dist/tools/vdb/blosc.js.map +1 -0
- package/dist/tools/vdb/blosclz.d.ts +33 -0
- package/dist/tools/vdb/blosclz.js +112 -0
- package/dist/tools/vdb/blosclz.js.map +1 -0
- package/dist/tools/vdb/byte-reader.d.ts +50 -0
- package/dist/tools/vdb/byte-reader.js +161 -0
- package/dist/tools/vdb/byte-reader.js.map +1 -0
- package/dist/tools/vdb/compression.d.ts +81 -0
- package/dist/tools/vdb/compression.js +260 -0
- package/dist/tools/vdb/compression.js.map +1 -0
- package/dist/tools/vdb/errors.d.ts +10 -0
- package/dist/tools/vdb/errors.js +11 -0
- package/dist/tools/vdb/errors.js.map +1 -0
- package/dist/tools/vdb/grid.d.ts +37 -0
- package/dist/tools/vdb/grid.js +153 -0
- package/dist/tools/vdb/grid.js.map +1 -0
- package/dist/tools/vdb/half-float.d.ts +9 -0
- package/dist/tools/vdb/half-float.js +24 -0
- package/dist/tools/vdb/half-float.js.map +1 -0
- package/dist/tools/vdb/index.d.ts +4 -0
- package/dist/tools/vdb/index.js +3 -0
- package/dist/tools/vdb/index.js.map +1 -0
- package/dist/tools/vdb/inflate.d.ts +24 -0
- package/dist/tools/vdb/inflate.js +334 -0
- package/dist/tools/vdb/inflate.js.map +1 -0
- package/dist/tools/vdb/lz4.d.ts +30 -0
- package/dist/tools/vdb/lz4.js +228 -0
- package/dist/tools/vdb/lz4.js.map +1 -0
- package/dist/tools/vdb/metadata.d.ts +17 -0
- package/dist/tools/vdb/metadata.js +72 -0
- package/dist/tools/vdb/metadata.js.map +1 -0
- package/dist/tools/vdb/parse.d.ts +47 -0
- package/dist/tools/vdb/parse.js +241 -0
- package/dist/tools/vdb/parse.js.map +1 -0
- package/dist/tools/vdb/point-render-data.d.ts +79 -0
- package/dist/tools/vdb/point-render-data.js +137 -0
- package/dist/tools/vdb/point-render-data.js.map +1 -0
- package/dist/tools/vdb/points.d.ts +186 -0
- package/dist/tools/vdb/points.js +835 -0
- package/dist/tools/vdb/points.js.map +1 -0
- package/dist/tools/vdb/transform.d.ts +23 -0
- package/dist/tools/vdb/transform.js +54 -0
- package/dist/tools/vdb/transform.js.map +1 -0
- package/dist/tools/vdb/tree.d.ts +111 -0
- package/dist/tools/vdb/tree.js +228 -0
- package/dist/tools/vdb/tree.js.map +1 -0
- package/dist/tools/vdb/types.d.ts +195 -0
- package/dist/tools/vdb/types.js +3 -0
- package/dist/tools/vdb/types.js.map +1 -0
- package/dist/tools/wvdb/bake.d.ts +145 -0
- package/dist/tools/wvdb/bake.js +361 -0
- package/dist/tools/wvdb/bake.js.map +1 -0
- package/dist/tools/wvdb/dense.d.ts +191 -0
- package/dist/tools/wvdb/dense.js +368 -0
- package/dist/tools/wvdb/dense.js.map +1 -0
- package/dist/tools/wvdb/format.d.ts +220 -0
- package/dist/tools/wvdb/format.js +306 -0
- package/dist/tools/wvdb/format.js.map +1 -0
- package/dist/tools/wvdb/index.d.ts +14 -0
- package/dist/tools/wvdb/index.js +15 -0
- package/dist/tools/wvdb/index.js.map +1 -0
- package/dist/tools/wvdb/level-set.d.ts +56 -0
- package/dist/tools/wvdb/level-set.js +153 -0
- package/dist/tools/wvdb/level-set.js.map +1 -0
- package/dist/tools/wvdb/nanovdb.d.ts +59 -0
- package/dist/tools/wvdb/nanovdb.js +64 -0
- package/dist/tools/wvdb/nanovdb.js.map +1 -0
- package/dist/tools/wvdb/partial.d.ts +74 -0
- package/dist/tools/wvdb/partial.js +233 -0
- package/dist/tools/wvdb/partial.js.map +1 -0
- package/dist/tools/wvdb/read.d.ts +336 -0
- package/dist/tools/wvdb/read.js +766 -0
- package/dist/tools/wvdb/read.js.map +1 -0
- package/dist/tools/wvdb/sha256.d.ts +7 -0
- package/dist/tools/wvdb/sha256.js +76 -0
- package/dist/tools/wvdb/sha256.js.map +1 -0
- package/dist/tools/wvdb/write.d.ts +149 -0
- package/dist/tools/wvdb/write.js +403 -0
- package/dist/tools/wvdb/write.js.map +1 -0
- package/package.json +83 -4
- package/vendor/LICENSE +201 -0
- package/vendor/NOTICE +19 -0
- package/vendor/VENDOR.md +100 -0
- package/vendor/pnanovdb.wgsl +1577 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* serialize.ts — lays a {@link BuiltTree} out into a complete, valid NanoVDB
|
|
3
|
+
* FLOAT grid image (a flat little-endian u32 array), and the public
|
|
4
|
+
* `vdbBuildFromDense` entry point.
|
|
5
|
+
*
|
|
6
|
+
* ## Memory layout (32-byte aligned throughout)
|
|
7
|
+
*
|
|
8
|
+
* [GridData 672][TreeData 64][RootData 64 + tiles*32][uppers][lowers][leaves]
|
|
9
|
+
*
|
|
10
|
+
* Every block size is a multiple of 32 (GridData 672, TreeData 64, RootData
|
|
11
|
+
* 64 + 32/tile, upper 270400, lower 33856, leaf 2144), so concatenating from a
|
|
12
|
+
* 32-aligned base keeps every block 32-aligned with no interior padding — this
|
|
13
|
+
* matches the layout native `nanovdb_convert` emits (verified against
|
|
14
|
+
* `sphere_fog_float.nvdb`: tree@672, root@736 (offset 64 from tree), uppers
|
|
15
|
+
* after the root table, etc.).
|
|
16
|
+
*
|
|
17
|
+
* ## Build order
|
|
18
|
+
*
|
|
19
|
+
* 1. buildTree() — voxels -> leaves (value mask + values) -> lower nodes
|
|
20
|
+
* (child leaves + background tiles) -> upper nodes -> root tiles; stats and
|
|
21
|
+
* per-node bbox aggregated bottom-up in that pass.
|
|
22
|
+
* 2. Compute block offsets, allocate the image.
|
|
23
|
+
* 3. Write nodes leaf-first is unnecessary — offsets are known up front, so we
|
|
24
|
+
* write GridData, TreeData, RootData+tiles, uppers, lowers, leaves, patching
|
|
25
|
+
* child offsets (relative to the containing node) as we go.
|
|
26
|
+
*
|
|
27
|
+
* ## nanovdb_convert byte-parity (DEFERRED — needs native tools)
|
|
28
|
+
*
|
|
29
|
+
* This wave's correctness bar is *value* parity through the repo's proven CPU
|
|
30
|
+
* (`read-value.ts`) and WGSL readers, plus structural conformance, NOT byte
|
|
31
|
+
* identity with `nanovdb_convert`. Three things differ from a native encode and
|
|
32
|
+
* are intentionally out of scope here: (a) tile topology: `vdbBuildFromDense`
|
|
33
|
+
* collapses uniform regions into tiles (K4.6, `collapse`), and the leaf path
|
|
34
|
+
* keeps the source's tiles as they are (K4.1), (b) the real Full/Partial CRC checksum (we write the
|
|
35
|
+
* "disabled" sentinel — see bytes.ts), and (c) native's trailing grid padding.
|
|
36
|
+
* All three are tracked for the byte-parity follow-up; none affects any value a
|
|
37
|
+
* reader returns.
|
|
38
|
+
*/
|
|
39
|
+
import { VDBToolsError } from "../errors.js";
|
|
40
|
+
import { CHECKSUM_DISABLED, GRID_CLASS_FOG_VOLUME, GRID_CLASS_LEVEL_SET, GRID_CLASS_STAGGERED, GRID_FLAGS_STATS_BBOX_BREADTH_FIRST, GRID_TYPE_HALF, GRID_NAME_MAX, GRID_OFF_BLIND_METADATA_COUNT, GRID_OFF_BLIND_METADATA_OFFSET, GRID_OFF_CHECKSUM, GRID_OFF_DATA0, GRID_OFF_DATA1, GRID_OFF_DATA2, GRID_OFF_FLAGS, GRID_OFF_GRID_CLASS, GRID_OFF_GRID_COUNT, GRID_OFF_GRID_INDEX, GRID_OFF_GRID_NAME, GRID_OFF_GRID_SIZE, GRID_OFF_GRID_TYPE, GRID_OFF_MAGIC, GRID_OFF_MAP, GRID_OFF_VERSION, GRID_OFF_VOXEL_SIZE, GRID_OFF_WORLD_BBOX, GRID_SIZE, GridImageWriter, LOWER_OFF_CHILD_MASK, LOWER_TABLE_COUNT, MAGIC_GRID, MAP_OFF_INVMATD, MAP_OFF_INVMATF, MAP_OFF_MATD, MAP_OFF_MATF, MAP_OFF_TAPERD, MAP_OFF_TAPERF, MAP_OFF_VECD, MAP_OFF_VECF, NODE_FLAG_STATS, NODE_OFF_BBOX_MAX, NODE_OFF_BBOX_MIN, NODE_OFF_FLAGS, NODE_OFF_VALUE_MASK, ROOT_OFF_BBOX_MAX, ROOT_OFF_BBOX_MIN, ROOT_OFF_TABLE_SIZE, ROOT_TILE_OFF_CHILD, ROOT_TILE_OFF_KEY, ROOT_TILE_OFF_STATE, TREE_OFF_NODE_COUNT_LEAF, TREE_OFF_NODE_COUNT_LOWER, TREE_OFF_NODE_COUNT_UPPER, TREE_OFF_NODE_OFFSET_LEAF, TREE_OFF_NODE_OFFSET_LOWER, TREE_OFF_NODE_OFFSET_ROOT, TREE_OFF_NODE_OFFSET_UPPER, TREE_OFF_TILE_COUNT_LOWER, TREE_OFF_TILE_COUNT_ROOT, TREE_OFF_TILE_COUNT_UPPER, TREE_OFF_VOXEL_COUNT, TREE_SIZE, UPPER_OFF_CHILD_MASK, UPPER_TABLE_COUNT, VERSION_PACKED, } from "./bytes.js";
|
|
41
|
+
import { VDB_FLOAT_LEAF_CODEC, writeVec3StatsBlock } from "./leaf-codec.js";
|
|
42
|
+
import { STATS_FLOAT_MAX, STATS_HALF_MAX, StatsAccumulator } from "./stats.js";
|
|
43
|
+
import { buildTree, buildTreeFromLeaves, } from "./tree.js";
|
|
44
|
+
const GRID_CLASS_ID = {
|
|
45
|
+
FogVolume: GRID_CLASS_FOG_VOLUME,
|
|
46
|
+
LevelSet: GRID_CLASS_LEVEL_SET,
|
|
47
|
+
Staggered: GRID_CLASS_STAGGERED,
|
|
48
|
+
Unknown: 0,
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Builds a complete FLOAT NanoVDB grid image from a dense array of shape
|
|
52
|
+
* `[nx,ny,nz]` (x-major: idx = (x*ny + y)*nz + z; `layout: 'x-fastest'` reads
|
|
53
|
+
* idx = x + nx*(y + ny*z) instead). With `collapse` (the default) an 8^3 block
|
|
54
|
+
* of one value becomes a tile of its lower node, not a leaf.
|
|
55
|
+
*
|
|
56
|
+
* @param values The dense values, `nx * ny * nz` of them.
|
|
57
|
+
* @param dims Voxels per axis `[nx, ny, nz]`.
|
|
58
|
+
* @param opts Origin, voxel size, background, activity rule, name, class, collapsing and the array layout.
|
|
59
|
+
*/
|
|
60
|
+
export function vdbBuildFromDense(values, dims, opts = {}) {
|
|
61
|
+
return vdbBuildFromDenseDetailed(values, dims, opts).image;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* As `vdbBuildFromDense`, but also returns computed metadata (used by writeNvdb).
|
|
65
|
+
*
|
|
66
|
+
* @param values The dense values, `nx * ny * nz` of them.
|
|
67
|
+
* @param dims Voxels per axis `[nx, ny, nz]`.
|
|
68
|
+
* @param opts Origin, voxel size, background, activity rule, name, class and collapsing.
|
|
69
|
+
*/
|
|
70
|
+
export function vdbBuildFromDenseDetailed(values, dims, opts = {}) {
|
|
71
|
+
const [nx, ny, nz] = dims;
|
|
72
|
+
if (nx < 0 || ny < 0 || nz < 0 || !Number.isInteger(nx) || !Number.isInteger(ny) || !Number.isInteger(nz)) {
|
|
73
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `vdbBuildFromDense: dims must be non-negative integers, got [${nx},${ny},${nz}]`);
|
|
74
|
+
}
|
|
75
|
+
if (values.length !== nx * ny * nz) {
|
|
76
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `vdbBuildFromDense: values.length ${values.length} !== nx*ny*nz (${nx}*${ny}*${nz} = ${nx * ny * nz})`);
|
|
77
|
+
}
|
|
78
|
+
const layout = opts.layout ?? "x-major";
|
|
79
|
+
if (layout !== "x-major" && layout !== "x-fastest") {
|
|
80
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `vdbBuildFromDense: unknown layout "${String(layout)}" (expected "x-major" or "x-fastest")`);
|
|
81
|
+
}
|
|
82
|
+
const origin = opts.origin ?? [0, 0, 0];
|
|
83
|
+
const voxelSizeXYZ = voxelSizeVec3(opts.voxelSize, "vdbBuildFromDense");
|
|
84
|
+
const background = opts.background ?? 0;
|
|
85
|
+
const gridName = opts.gridName ?? "dense";
|
|
86
|
+
const gridClassId = GRID_CLASS_ID[opts.gridClass ?? "FogVolume"];
|
|
87
|
+
const worldOrigin = opts.worldOrigin ?? [origin[0] * voxelSizeXYZ[0], origin[1] * voxelSizeXYZ[1], origin[2] * voxelSizeXYZ[2]];
|
|
88
|
+
const nameBytes = new TextEncoder().encode(gridName);
|
|
89
|
+
if (nameBytes.length + 1 > GRID_NAME_MAX) {
|
|
90
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `vdbBuildFromDense: gridName is ${nameBytes.length} bytes; must be < ${GRID_NAME_MAX} (incl. NUL). ` +
|
|
91
|
+
`Long grid names (HasLongGridName + blind metadata) are not supported in v1.`);
|
|
92
|
+
}
|
|
93
|
+
const codec = VDB_FLOAT_LEAF_CODEC;
|
|
94
|
+
const tree = buildTree(values, dims, {
|
|
95
|
+
origin,
|
|
96
|
+
background,
|
|
97
|
+
activeThreshold: opts.activeThreshold,
|
|
98
|
+
collapse: opts.collapse ?? true,
|
|
99
|
+
layout,
|
|
100
|
+
});
|
|
101
|
+
const image = layoutGrid(tree, codec, {
|
|
102
|
+
gridName,
|
|
103
|
+
nameBytes,
|
|
104
|
+
gridClassId,
|
|
105
|
+
voxelSize: voxelSizeXYZ,
|
|
106
|
+
worldOrigin,
|
|
107
|
+
origin,
|
|
108
|
+
background,
|
|
109
|
+
});
|
|
110
|
+
const indexBBox = bboxOrEmpty(tree.root);
|
|
111
|
+
const worldBBox = worldBBoxFromIndex(indexBBox, voxelSizeXYZ, worldOrigin, origin);
|
|
112
|
+
return {
|
|
113
|
+
image,
|
|
114
|
+
gridName,
|
|
115
|
+
voxelCount: tree.activeVoxelCount,
|
|
116
|
+
indexBBox,
|
|
117
|
+
worldBBox,
|
|
118
|
+
voxelSize: voxelSizeXYZ[0],
|
|
119
|
+
voxelSizeXYZ,
|
|
120
|
+
nodeCounts: { leaf: tree.leaves.length, lower: tree.lowers.length, upper: tree.uppers.length },
|
|
121
|
+
tileCounts: { ...tree.tileCounts },
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** A `voxelSize` option (number or `[x, y, z]`, default 1) as a validated per-axis vector. */
|
|
125
|
+
function voxelSizeVec3(vs, fn) {
|
|
126
|
+
const v = vs ?? 1;
|
|
127
|
+
const xyz = typeof v === "number" ? [v, v, v] : [v[0], v[1], v[2]];
|
|
128
|
+
if ((typeof v !== "number" && v.length !== 3) || !xyz.every((c) => Number.isFinite(c) && c > 0)) {
|
|
129
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `${fn}: voxelSize must be positive and finite (a number or [x, y, z]), got ${JSON.stringify(vs)}`);
|
|
130
|
+
}
|
|
131
|
+
return xyz;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Builds a complete NanoVDB grid image from an iterator of already-materialised
|
|
135
|
+
* leaves (each carrying its 8-aligned origin, all 512 values and a 512-bit value
|
|
136
|
+
* mask), using the given {@link VDBLeafCodec}. This is the memory-frugal path —
|
|
137
|
+
* leaves stream in, no dense array is ever allocated — that backs `buildFromVdb`
|
|
138
|
+
* (parser leaves -> FLOAT) and `quantize` (an existing grid's leaves -> Fp8/FpN).
|
|
139
|
+
*
|
|
140
|
+
* @param leaves The leaves, in any order.
|
|
141
|
+
* @param codec Encodes the leaves and constants (e.g. `VDB_FP8_LEAF_CODEC`).
|
|
142
|
+
* @param opts Voxel size, origin, background, name, class, tiles and collapsing.
|
|
143
|
+
*/
|
|
144
|
+
export function vdbBuildFromLeavesDetailed(leaves, codec, opts = {}) {
|
|
145
|
+
const voxelSizeXYZ = voxelSizeVec3(opts.voxelSize, "buildFromLeaves");
|
|
146
|
+
const components = codec.components ?? 1;
|
|
147
|
+
const background = opts.background ?? (components === 3 ? [0, 0, 0] : 0);
|
|
148
|
+
if ((typeof background === "number") !== (components === 1)) {
|
|
149
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `buildFromLeaves: background must have ${components} component(s) for this codec`);
|
|
150
|
+
}
|
|
151
|
+
const gridName = opts.gridName ?? "grid";
|
|
152
|
+
const gridClassId = GRID_CLASS_ID[opts.gridClass ?? "FogVolume"];
|
|
153
|
+
const worldOrigin = opts.worldOrigin ?? [0, 0, 0];
|
|
154
|
+
const nameBytes = new TextEncoder().encode(gridName);
|
|
155
|
+
if (nameBytes.length + 1 > GRID_NAME_MAX) {
|
|
156
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `buildFromLeaves: gridName is ${nameBytes.length} bytes; must be < ${GRID_NAME_MAX} (incl. NUL). ` +
|
|
157
|
+
`Long grid names (HasLongGridName + blind metadata) are not supported in v1.`);
|
|
158
|
+
}
|
|
159
|
+
const round = components === 1 ? codec.roundValue : undefined;
|
|
160
|
+
const tree = round
|
|
161
|
+
? buildTreeFromLeaves(roundLeaves(leaves, round), roundTiles(opts.tiles, round), components, {
|
|
162
|
+
collapse: opts.collapse === true,
|
|
163
|
+
background: round(background),
|
|
164
|
+
})
|
|
165
|
+
: buildTreeFromLeaves(leaves, opts.tiles, components, { collapse: opts.collapse === true, background });
|
|
166
|
+
const image = layoutGrid(tree, codec, {
|
|
167
|
+
gridName,
|
|
168
|
+
nameBytes,
|
|
169
|
+
gridClassId,
|
|
170
|
+
voxelSize: voxelSizeXYZ,
|
|
171
|
+
worldOrigin,
|
|
172
|
+
origin: [0, 0, 0],
|
|
173
|
+
background,
|
|
174
|
+
});
|
|
175
|
+
const indexBBox = bboxOrEmpty(tree.root);
|
|
176
|
+
const worldBBox = worldBBoxFromIndex(indexBBox, voxelSizeXYZ, worldOrigin, [0, 0, 0]);
|
|
177
|
+
return {
|
|
178
|
+
image,
|
|
179
|
+
gridName,
|
|
180
|
+
voxelCount: tree.activeVoxelCount,
|
|
181
|
+
indexBBox,
|
|
182
|
+
worldBBox,
|
|
183
|
+
voxelSize: voxelSizeXYZ[0],
|
|
184
|
+
voxelSizeXYZ,
|
|
185
|
+
nodeCounts: { leaf: tree.leaves.length, lower: tree.lowers.length, upper: tree.uppers.length },
|
|
186
|
+
tileCounts: { ...tree.tileCounts },
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/** Leaves with every value passed through the codec's `roundValue` (a copy; the input is not touched). */
|
|
190
|
+
function* roundLeaves(leaves, round) {
|
|
191
|
+
for (const leaf of leaves) {
|
|
192
|
+
const values = new Float32Array(leaf.values.length);
|
|
193
|
+
for (let n = 0; n < values.length; n++)
|
|
194
|
+
values[n] = round(leaf.values[n]);
|
|
195
|
+
yield { ...leaf, values };
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function roundTiles(tiles, round) {
|
|
199
|
+
if (tiles === undefined)
|
|
200
|
+
return undefined;
|
|
201
|
+
return [...tiles].map((t) => ({ ...t, value: typeof t.value === "number" ? round(t.value) : t.value }));
|
|
202
|
+
}
|
|
203
|
+
function layoutGrid(tree, codec, p) {
|
|
204
|
+
const L = codec.layout;
|
|
205
|
+
const nTiles = tree.rootTiles.length;
|
|
206
|
+
const nUpper = tree.uppers.length;
|
|
207
|
+
const nLower = tree.lowers.length;
|
|
208
|
+
const nLeaf = tree.leaves.length;
|
|
209
|
+
// Block base offsets (all multiples of 32).
|
|
210
|
+
const treeOff = GRID_SIZE; // 672
|
|
211
|
+
const rootOff = treeOff + TREE_SIZE; // 736
|
|
212
|
+
const rootBlockSize = L.rootSize + nTiles * L.rootTileSize;
|
|
213
|
+
const upperOff = rootOff + rootBlockSize;
|
|
214
|
+
const lowerOff = upperOff + nUpper * L.upperSize;
|
|
215
|
+
const leafOff = lowerOff + nLower * L.lowerSize;
|
|
216
|
+
// Per-leaf plans + cumulative offsets. FLOAT/Fp8 leaves are fixed-size; FpN
|
|
217
|
+
// leaves vary (96 + bitWidth*64), so the block is not a uniform stride.
|
|
218
|
+
const leafPlans = tree.leaves.map((leaf) => codec.planLeaf(leaf.values));
|
|
219
|
+
const leafByteOffset = new Array(nLeaf);
|
|
220
|
+
let leafAcc = 0;
|
|
221
|
+
for (let i = 0; i < nLeaf; i++) {
|
|
222
|
+
leafByteOffset[i] = leafAcc;
|
|
223
|
+
leafAcc += leafPlans[i].byteSize;
|
|
224
|
+
}
|
|
225
|
+
const total = leafOff + leafAcc;
|
|
226
|
+
const w = new GridImageWriter(total);
|
|
227
|
+
const upperAbs = (i) => upperOff + i * L.upperSize;
|
|
228
|
+
const lowerAbs = (i) => lowerOff + i * L.lowerSize;
|
|
229
|
+
const leafAbs = (i) => leafOff + leafByteOffset[i];
|
|
230
|
+
// ---- GridData ----------------------------------------------------------
|
|
231
|
+
writeGridData(w, tree, codec, p, total);
|
|
232
|
+
// ---- TreeData ----------------------------------------------------------
|
|
233
|
+
w.setU64(treeOff + TREE_OFF_NODE_OFFSET_LEAF, BigInt(leafOff - treeOff));
|
|
234
|
+
w.setU64(treeOff + TREE_OFF_NODE_OFFSET_LOWER, BigInt(lowerOff - treeOff));
|
|
235
|
+
w.setU64(treeOff + TREE_OFF_NODE_OFFSET_UPPER, BigInt(upperOff - treeOff));
|
|
236
|
+
w.setU64(treeOff + TREE_OFF_NODE_OFFSET_ROOT, BigInt(rootOff - treeOff));
|
|
237
|
+
w.setU32(treeOff + TREE_OFF_NODE_COUNT_LEAF, nLeaf);
|
|
238
|
+
w.setU32(treeOff + TREE_OFF_NODE_COUNT_LOWER, nLower);
|
|
239
|
+
w.setU32(treeOff + TREE_OFF_NODE_COUNT_UPPER, nUpper);
|
|
240
|
+
// Active tiles exist only when the leaf-path source supplied them (K4.1).
|
|
241
|
+
w.setU32(treeOff + TREE_OFF_TILE_COUNT_LOWER, tree.tileCounts.lower);
|
|
242
|
+
w.setU32(treeOff + TREE_OFF_TILE_COUNT_UPPER, tree.tileCounts.upper);
|
|
243
|
+
w.setU32(treeOff + TREE_OFF_TILE_COUNT_ROOT, tree.tileCounts.root);
|
|
244
|
+
w.setU64(treeOff + TREE_OFF_VOXEL_COUNT, BigInt(tree.activeVoxelCount));
|
|
245
|
+
// ---- RootData + tiles --------------------------------------------------
|
|
246
|
+
const ibox = bboxOrEmpty(tree.root);
|
|
247
|
+
writeCoord(w, rootOff + ROOT_OFF_BBOX_MIN, ibox.min);
|
|
248
|
+
writeCoord(w, rootOff + ROOT_OFF_BBOX_MAX, ibox.max);
|
|
249
|
+
w.setU32(rootOff + ROOT_OFF_TABLE_SIZE, nTiles);
|
|
250
|
+
codec.writeConstant(w, rootOff + L.rootOffBackground, p.background);
|
|
251
|
+
writeStats(w, codec, rootOff, L.rootOffMin, L.rootOffMax, L.rootOffAve, L.rootOffStdDev, tree.root);
|
|
252
|
+
tree.rootTiles.forEach((tile, i) => {
|
|
253
|
+
const tileOff = rootOff + L.rootSize + i * L.rootTileSize;
|
|
254
|
+
w.setU64(tileOff + ROOT_TILE_OFF_KEY, tile.key);
|
|
255
|
+
if (tile.child) {
|
|
256
|
+
w.setI64(tileOff + ROOT_TILE_OFF_CHILD, BigInt(upperAbs(tile.child.memIndex) - rootOff));
|
|
257
|
+
w.setU32(tileOff + ROOT_TILE_OFF_STATE, 0);
|
|
258
|
+
// Child slot: the value field stays zero (the image is zero-filled).
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
// Root tile: no child (offset 0), state on (active) or off (inactive), the tile's value.
|
|
262
|
+
w.setI64(tileOff + ROOT_TILE_OFF_CHILD, 0n);
|
|
263
|
+
w.setU32(tileOff + ROOT_TILE_OFF_STATE, tile.active ? 1 : 0);
|
|
264
|
+
codec.writeConstant(w, tileOff + L.rootTileOffValue, tile.value);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
// ---- Upper nodes -------------------------------------------------------
|
|
268
|
+
for (const upper of tree.uppers) {
|
|
269
|
+
writeInternalNode(w, upperAbs(upper.memIndex), upper, {
|
|
270
|
+
tableCount: UPPER_TABLE_COUNT,
|
|
271
|
+
childMaskOff: UPPER_OFF_CHILD_MASK,
|
|
272
|
+
tableOff: L.upperOffTable,
|
|
273
|
+
tableStride: L.tableStride,
|
|
274
|
+
offMin: L.upperOffMin,
|
|
275
|
+
offMax: L.upperOffMax,
|
|
276
|
+
offAve: L.upperOffAve,
|
|
277
|
+
offStdDev: L.upperOffStdDev,
|
|
278
|
+
background: p.background,
|
|
279
|
+
codec,
|
|
280
|
+
childAbs: lowerAbs,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
// ---- Lower nodes -------------------------------------------------------
|
|
284
|
+
for (const lower of tree.lowers) {
|
|
285
|
+
writeInternalNode(w, lowerAbs(lower.memIndex), lower, {
|
|
286
|
+
tableCount: LOWER_TABLE_COUNT,
|
|
287
|
+
childMaskOff: LOWER_OFF_CHILD_MASK,
|
|
288
|
+
tableOff: L.lowerOffTable,
|
|
289
|
+
tableStride: L.tableStride,
|
|
290
|
+
offMin: L.lowerOffMin,
|
|
291
|
+
offMax: L.lowerOffMax,
|
|
292
|
+
offAve: L.lowerOffAve,
|
|
293
|
+
offStdDev: L.lowerOffStdDev,
|
|
294
|
+
background: p.background,
|
|
295
|
+
codec,
|
|
296
|
+
childAbs: leafAbs,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
// ---- Leaf nodes --------------------------------------------------------
|
|
300
|
+
for (const leaf of tree.leaves) {
|
|
301
|
+
codec.encodeLeaf(w, leafAbs(leaf.memIndex), leaf, leafPlans[leaf.memIndex]);
|
|
302
|
+
}
|
|
303
|
+
return w.u32;
|
|
304
|
+
}
|
|
305
|
+
function writeInternalNode(w, nodeOff, node, p) {
|
|
306
|
+
const s = node.stats;
|
|
307
|
+
const bmin = s.isEmpty ? node.origin : s.bboxMin;
|
|
308
|
+
const bmax = s.isEmpty ? node.origin : s.bboxMax;
|
|
309
|
+
writeCoord(w, nodeOff + NODE_OFF_BBOX_MIN, bmin);
|
|
310
|
+
writeCoord(w, nodeOff + NODE_OFF_BBOX_MAX, bmax);
|
|
311
|
+
w.setU64(nodeOff + NODE_OFF_FLAGS, BigInt(NODE_FLAG_STATS));
|
|
312
|
+
writeStats(w, p.codec, nodeOff, p.offMin, p.offMax, p.offAve, p.offStdDev, s);
|
|
313
|
+
// Table: child slots hold an i64 offset (relative to this node); active
|
|
314
|
+
// tiles set their value-mask bit and hold the tile value; every other slot
|
|
315
|
+
// is an inactive background tile carrying the background value.
|
|
316
|
+
const childSlots = node.children;
|
|
317
|
+
const tiles = node.tiles;
|
|
318
|
+
const inactiveTiles = node.inactiveTiles;
|
|
319
|
+
const backgroundIsZero = typeof p.background === "number" ? p.background === 0 : p.background.every((c) => c === 0);
|
|
320
|
+
for (let n = 0; n < p.tableCount; n++) {
|
|
321
|
+
const slotOff = nodeOff + p.tableOff + n * p.tableStride;
|
|
322
|
+
const child = childSlots.get(n);
|
|
323
|
+
const tileValue = tiles.size > 0 ? tiles.get(n) : undefined;
|
|
324
|
+
if (child !== undefined) {
|
|
325
|
+
w.setMaskBit(nodeOff + p.childMaskOff, n);
|
|
326
|
+
w.setI64(slotOff, BigInt(p.childAbs(child.memIndex) - nodeOff));
|
|
327
|
+
}
|
|
328
|
+
else if (tileValue !== undefined) {
|
|
329
|
+
w.setMaskBit(nodeOff + NODE_OFF_VALUE_MASK, n);
|
|
330
|
+
p.codec.writeConstant(w, slotOff, tileValue);
|
|
331
|
+
}
|
|
332
|
+
else if (inactiveTiles.size > 0 && inactiveTiles.has(n)) {
|
|
333
|
+
p.codec.writeConstant(w, slotOff, inactiveTiles.get(n));
|
|
334
|
+
}
|
|
335
|
+
else if (!backgroundIsZero) {
|
|
336
|
+
// Skip when background is 0: the buffer is already zero-filled.
|
|
337
|
+
p.codec.writeConstant(w, slotOff, p.background);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function writeStats(w, codec, base, offMin, offMax, offAve, offStdDev, s) {
|
|
342
|
+
if (codec.components === 3) {
|
|
343
|
+
writeVec3StatsBlock(w, base, offMin, offMax, offAve, offStdDev, s);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
// Min/max have the grid's value type (f32, or binary16 for Half); ave/stddev are f32.
|
|
347
|
+
// Extrema's start value (the type's largest finite) stays when a node holds only +-inf (K7.H1).
|
|
348
|
+
const finiteMax = codec.layout.gridType === GRID_TYPE_HALF ? STATS_HALF_MAX : STATS_FLOAT_MAX;
|
|
349
|
+
codec.writeConstant(w, base + offMin, s.storedMin(finiteMax));
|
|
350
|
+
codec.writeConstant(w, base + offMax, s.storedMax(finiteMax));
|
|
351
|
+
w.setF32(base + offAve, s.average);
|
|
352
|
+
w.setF32(base + offStdDev, s.stdDev);
|
|
353
|
+
}
|
|
354
|
+
function writeGridData(w, tree, codec, p, total) {
|
|
355
|
+
w.setU64(GRID_OFF_MAGIC, MAGIC_GRID);
|
|
356
|
+
w.setU64(GRID_OFF_CHECKSUM, CHECKSUM_DISABLED);
|
|
357
|
+
w.setU32(GRID_OFF_VERSION, VERSION_PACKED);
|
|
358
|
+
w.setU32(GRID_OFF_FLAGS, GRID_FLAGS_STATS_BBOX_BREADTH_FIRST);
|
|
359
|
+
w.setU32(GRID_OFF_GRID_INDEX, 0);
|
|
360
|
+
w.setU32(GRID_OFF_GRID_COUNT, 1);
|
|
361
|
+
w.setU64(GRID_OFF_GRID_SIZE, BigInt(total));
|
|
362
|
+
// Grid name: C string in the fixed 256-byte inline field.
|
|
363
|
+
w.setBytes(GRID_OFF_GRID_NAME, p.nameBytes); // NUL terminator already zero
|
|
364
|
+
writeMap(w, p);
|
|
365
|
+
writeWorldBBox(w, tree, p);
|
|
366
|
+
const vs = p.voxelSize;
|
|
367
|
+
w.setF64(GRID_OFF_VOXEL_SIZE, vs[0]);
|
|
368
|
+
w.setF64(GRID_OFF_VOXEL_SIZE + 8, vs[1]);
|
|
369
|
+
w.setF64(GRID_OFF_VOXEL_SIZE + 16, vs[2]);
|
|
370
|
+
w.setU32(GRID_OFF_GRID_CLASS, p.gridClassId);
|
|
371
|
+
w.setU32(GRID_OFF_GRID_TYPE, codec.layout.gridType);
|
|
372
|
+
// No blind metadata: offset points at end-of-grid, count 0 (native
|
|
373
|
+
// convention, verified on sphere_fog_float.nvdb).
|
|
374
|
+
w.setU64(GRID_OFF_BLIND_METADATA_OFFSET, BigInt(total));
|
|
375
|
+
w.setU32(GRID_OFF_BLIND_METADATA_COUNT, 0);
|
|
376
|
+
w.setU32(GRID_OFF_DATA0, 0);
|
|
377
|
+
w.setU64(GRID_OFF_DATA1, 0n);
|
|
378
|
+
w.setU64(GRID_OFF_DATA2, 0n);
|
|
379
|
+
}
|
|
380
|
+
function writeMap(w, p) {
|
|
381
|
+
const s = p.voxelSize;
|
|
382
|
+
const t = [
|
|
383
|
+
p.worldOrigin[0] - p.origin[0] * s[0],
|
|
384
|
+
p.worldOrigin[1] - p.origin[1] * s[1],
|
|
385
|
+
p.worldOrigin[2] - p.origin[2] * s[2],
|
|
386
|
+
];
|
|
387
|
+
const mat = [s[0], 0, 0, 0, s[1], 0, 0, 0, s[2]];
|
|
388
|
+
const invMat = [1 / s[0], 0, 0, 0, 1 / s[1], 0, 0, 0, 1 / s[2]];
|
|
389
|
+
const mapBase = GRID_OFF_MAP;
|
|
390
|
+
for (let i = 0; i < 9; i++) {
|
|
391
|
+
w.setF32(mapBase + MAP_OFF_MATF + i * 4, mat[i]);
|
|
392
|
+
w.setF32(mapBase + MAP_OFF_INVMATF + i * 4, invMat[i]);
|
|
393
|
+
w.setF64(mapBase + MAP_OFF_MATD + i * 8, mat[i]);
|
|
394
|
+
w.setF64(mapBase + MAP_OFF_INVMATD + i * 8, invMat[i]);
|
|
395
|
+
}
|
|
396
|
+
for (let i = 0; i < 3; i++) {
|
|
397
|
+
w.setF32(mapBase + MAP_OFF_VECF + i * 4, t[i]);
|
|
398
|
+
w.setF64(mapBase + MAP_OFF_VECD + i * 8, t[i]);
|
|
399
|
+
}
|
|
400
|
+
w.setF32(mapBase + MAP_OFF_TAPERF, 1);
|
|
401
|
+
w.setF64(mapBase + MAP_OFF_TAPERD, 1);
|
|
402
|
+
}
|
|
403
|
+
function writeWorldBBox(w, tree, p) {
|
|
404
|
+
const ibox = bboxOrEmpty(tree.root);
|
|
405
|
+
const wb = worldBBoxFromIndex(ibox, p.voxelSize, p.worldOrigin, p.origin);
|
|
406
|
+
for (let a = 0; a < 3; a++)
|
|
407
|
+
w.setF64(GRID_OFF_WORLD_BBOX + a * 8, wb.min[a]);
|
|
408
|
+
for (let a = 0; a < 3; a++)
|
|
409
|
+
w.setF64(GRID_OFF_WORLD_BBOX + 24 + a * 8, wb.max[a]);
|
|
410
|
+
}
|
|
411
|
+
// ---------------------------------------------------------------------------
|
|
412
|
+
// Small helpers
|
|
413
|
+
// ---------------------------------------------------------------------------
|
|
414
|
+
function writeCoord(w, off, c) {
|
|
415
|
+
w.setI32(off, c[0]);
|
|
416
|
+
w.setI32(off + 4, c[1]);
|
|
417
|
+
w.setI32(off + 8, c[2]);
|
|
418
|
+
}
|
|
419
|
+
function bboxOrEmpty(s) {
|
|
420
|
+
if (s.isEmpty)
|
|
421
|
+
return { min: [0, 0, 0], max: [-1, -1, -1] };
|
|
422
|
+
return { min: [...s.bboxMin], max: [...s.bboxMax] };
|
|
423
|
+
}
|
|
424
|
+
function worldBBoxFromIndex(ibox, voxelSize, worldOrigin, origin) {
|
|
425
|
+
const t = [
|
|
426
|
+
worldOrigin[0] - origin[0] * voxelSize[0],
|
|
427
|
+
worldOrigin[1] - origin[1] * voxelSize[1],
|
|
428
|
+
worldOrigin[2] - origin[2] * voxelSize[2],
|
|
429
|
+
];
|
|
430
|
+
const min = [0, 0, 0];
|
|
431
|
+
const max = [0, 0, 0];
|
|
432
|
+
for (let a = 0; a < 3; a++) {
|
|
433
|
+
min[a] = ibox.min[a] * voxelSize[a] + t[a];
|
|
434
|
+
// "+ one voxel" convention: world max corner is (indexMax + 1) * voxelSize.
|
|
435
|
+
max[a] = (ibox.max[a] + 1) * voxelSize[a] + t[a];
|
|
436
|
+
}
|
|
437
|
+
return { min, max };
|
|
438
|
+
}
|
|
439
|
+
//# sourceMappingURL=serialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/serialize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,mCAAmC,EACnC,cAAc,EACd,aAAa,EACb,6BAA6B,EAC7B,8BAA8B,EAC9B,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACn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,CACzB,IAAsE,EACtE,SAAmC,EACnC,WAAqC,EACrC,MAAgC;IAEhC,MAAM,CAAC,GAAG;QACR,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;QACzC,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;QACzC,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;KAC1C,CAAC;IACF,MAAM,GAAG,GAA6B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChD,MAAM,GAAG,GAA6B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAE,GAAG,SAAS,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;QAC9C,4EAA4E;QAC5E,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;IACtD,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACtB,CAAC","sourcesContent":["/**\n * serialize.ts — lays a {@link BuiltTree} out into a complete, valid NanoVDB\n * FLOAT grid image (a flat little-endian u32 array), and the public\n * `vdbBuildFromDense` entry point.\n *\n * ## Memory layout (32-byte aligned throughout)\n *\n * [GridData 672][TreeData 64][RootData 64 + tiles*32][uppers][lowers][leaves]\n *\n * Every block size is a multiple of 32 (GridData 672, TreeData 64, RootData\n * 64 + 32/tile, upper 270400, lower 33856, leaf 2144), so concatenating from a\n * 32-aligned base keeps every block 32-aligned with no interior padding — this\n * matches the layout native `nanovdb_convert` emits (verified against\n * `sphere_fog_float.nvdb`: tree@672, root@736 (offset 64 from tree), uppers\n * after the root table, etc.).\n *\n * ## Build order\n *\n * 1. buildTree() — voxels -> leaves (value mask + values) -> lower nodes\n * (child leaves + background tiles) -> upper nodes -> root tiles; stats and\n * per-node bbox aggregated bottom-up in that pass.\n * 2. Compute block offsets, allocate the image.\n * 3. Write nodes leaf-first is unnecessary — offsets are known up front, so we\n * write GridData, TreeData, RootData+tiles, uppers, lowers, leaves, patching\n * child offsets (relative to the containing node) as we go.\n *\n * ## nanovdb_convert byte-parity (DEFERRED — needs native tools)\n *\n * This wave's correctness bar is *value* parity through the repo's proven CPU\n * (`read-value.ts`) and WGSL readers, plus structural conformance, NOT byte\n * identity with `nanovdb_convert`. Three things differ from a native encode and\n * are intentionally out of scope here: (a) tile topology: `vdbBuildFromDense`\n * collapses uniform regions into tiles (K4.6, `collapse`), and the leaf path\n * keeps the source's tiles as they are (K4.1), (b) the real Full/Partial CRC checksum (we write the\n * \"disabled\" sentinel — see bytes.ts), and (c) native's trailing grid padding.\n * All three are tracked for the byte-parity follow-up; none affects any value a\n * reader returns.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport {\n CHECKSUM_DISABLED,\n GRID_CLASS_FOG_VOLUME,\n GRID_CLASS_LEVEL_SET,\n GRID_CLASS_STAGGERED,\n GRID_FLAGS_STATS_BBOX_BREADTH_FIRST,\n GRID_TYPE_HALF,\n GRID_NAME_MAX,\n GRID_OFF_BLIND_METADATA_COUNT,\n GRID_OFF_BLIND_METADATA_OFFSET,\n GRID_OFF_CHECKSUM,\n GRID_OFF_DATA0,\n GRID_OFF_DATA1,\n GRID_OFF_DATA2,\n GRID_OFF_FLAGS,\n GRID_OFF_GRID_CLASS,\n GRID_OFF_GRID_COUNT,\n GRID_OFF_GRID_INDEX,\n GRID_OFF_GRID_NAME,\n GRID_OFF_GRID_SIZE,\n GRID_OFF_GRID_TYPE,\n GRID_OFF_MAGIC,\n GRID_OFF_MAP,\n GRID_OFF_VERSION,\n GRID_OFF_VOXEL_SIZE,\n GRID_OFF_WORLD_BBOX,\n GRID_SIZE,\n GridImageWriter,\n LOWER_OFF_CHILD_MASK,\n LOWER_TABLE_COUNT,\n MAGIC_GRID,\n MAP_OFF_INVMATD,\n MAP_OFF_INVMATF,\n MAP_OFF_MATD,\n MAP_OFF_MATF,\n MAP_OFF_TAPERD,\n MAP_OFF_TAPERF,\n MAP_OFF_VECD,\n MAP_OFF_VECF,\n NODE_FLAG_STATS,\n NODE_OFF_BBOX_MAX,\n NODE_OFF_BBOX_MIN,\n NODE_OFF_FLAGS,\n NODE_OFF_VALUE_MASK,\n ROOT_OFF_BBOX_MAX,\n ROOT_OFF_BBOX_MIN,\n ROOT_OFF_TABLE_SIZE,\n ROOT_TILE_OFF_CHILD,\n ROOT_TILE_OFF_KEY,\n ROOT_TILE_OFF_STATE,\n TREE_OFF_NODE_COUNT_LEAF,\n TREE_OFF_NODE_COUNT_LOWER,\n TREE_OFF_NODE_COUNT_UPPER,\n TREE_OFF_NODE_OFFSET_LEAF,\n TREE_OFF_NODE_OFFSET_LOWER,\n TREE_OFF_NODE_OFFSET_ROOT,\n TREE_OFF_NODE_OFFSET_UPPER,\n TREE_OFF_TILE_COUNT_LOWER,\n TREE_OFF_TILE_COUNT_ROOT,\n TREE_OFF_TILE_COUNT_UPPER,\n TREE_OFF_VOXEL_COUNT,\n TREE_SIZE,\n UPPER_OFF_CHILD_MASK,\n UPPER_TABLE_COUNT,\n VERSION_PACKED,\n} from \"./bytes.js\";\nimport { VDB_FLOAT_LEAF_CODEC, type VDBLeafCodec, writeVec3StatsBlock } from \"./leaf-codec.js\";\nimport { STATS_FLOAT_MAX, STATS_HALF_MAX, StatsAccumulator } from \"./stats.js\";\nimport {\n buildTree,\n buildTreeFromLeaves,\n type BuiltTree,\n type LeafInput,\n type LowerNode,\n type TileInput,\n type TileValue,\n type UpperNode,\n type VDBDenseLayout,\n} from \"./tree.js\";\n\n/** Options of {@link vdbBuildFromDense}. */\nexport interface VDBBuildFromDenseOptions {\n /** Index-space min corner of the dense block. Default [0,0,0]. */\n origin?: [number, number, number];\n /**\n * Voxel size in world units: a number (uniform), or `[x, y, z]` for an\n * anisotropic, axis-aligned Map (diagonal scale, as `vdbResampleGrid`\n * writes). Default 1.\n */\n voxelSize?: number | [number, number, number];\n /** World-space position of index coord `origin`. Default `origin * voxelSize` (per axis). */\n worldOrigin?: [number, number, number];\n /** Background (inactive) value. Default 0. */\n background?: number;\n /**\n * Active predicate. Omitted: active iff `value !== background` (exact).\n * Given: active iff `|value - background| > activeThreshold`.\n */\n activeThreshold?: number;\n /** Grid name (<256 bytes incl. NUL). Default \"dense\". */\n gridName?: string;\n /** Grid class. Default \"FogVolume\". */\n gridClass?: GridClassName;\n /**\n * Collapse uniform regions into tiles, as OpenVDB `tools::prune` at\n * tolerance 0 (K4.6): a leaf whose voxels are all active (or all inactive)\n * with one value becomes a lower-node tile, a lower node made only of equal\n * tiles an upper-node tile, and so on. Values read back identically.\n * Default true: a dense build has no native topology to keep.\n */\n collapse?: boolean;\n /**\n * How `values` is laid out (P1.17). `'x-major'` (default): `idx = (x * ny + y) * nz + z`, z fastest.\n * `'x-fastest'`: `idx = x + nx * (y + ny * z)`, the order of a 3D texture and of most simulation arrays; the\n * array is read in place (no transposed copy) and the image equals the one built from the transposed array, byte\n * for byte.\n */\n layout?: VDBDenseLayout;\n}\n\n/** Grid classes the serializer writes (NanoVDB `GridClass`). */\nexport type GridClassName = \"FogVolume\" | \"LevelSet\" | \"Staggered\" | \"Unknown\";\n\n/** Result of a build, exposing metadata alongside the raw image. */\nexport interface VDBBuiltGrid {\n /** The grid image (little-endian u32 words, `GridData` at word 0). */\n image: Uint32Array;\n /** The grid's name. */\n gridName: string;\n /** Active voxel count. */\n voxelCount: number;\n /** Inclusive index-space box of the active voxels. */\n indexBBox: { min: [number, number, number]; max: [number, number, number] };\n /** World-space box (its max is one voxel beyond the max voxel's centre). */\n worldBBox: { min: [number, number, number]; max: [number, number, number] };\n /** Voxel size along x: the voxel size of a uniform grid. See {@link VDBBuiltGrid.voxelSizeXYZ} for all three. */\n voxelSize: number;\n /** Voxel size per axis (equal for a uniform grid; an anisotropic grid has a diagonal, non-uniform Map). */\n voxelSizeXYZ: [number, number, number];\n /** Number of nodes per level. */\n nodeCounts: { leaf: number; lower: number; upper: number };\n /** Active tiles per level (all 0 unless the source had active tiles). */\n tileCounts: { lower: number; upper: number; root: number };\n}\n\nconst GRID_CLASS_ID: Record<GridClassName, number> = {\n FogVolume: GRID_CLASS_FOG_VOLUME,\n LevelSet: GRID_CLASS_LEVEL_SET,\n Staggered: GRID_CLASS_STAGGERED,\n Unknown: 0,\n};\n\n/**\n * Builds a complete FLOAT NanoVDB grid image from a dense array of shape\n * `[nx,ny,nz]` (x-major: idx = (x*ny + y)*nz + z; `layout: 'x-fastest'` reads\n * idx = x + nx*(y + ny*z) instead). With `collapse` (the default) an 8^3 block\n * of one value becomes a tile of its lower node, not a leaf.\n *\n * @param values The dense values, `nx * ny * nz` of them.\n * @param dims Voxels per axis `[nx, ny, nz]`.\n * @param opts Origin, voxel size, background, activity rule, name, class, collapsing and the array layout.\n */\nexport function vdbBuildFromDense(\n values: Float32Array,\n dims: [number, number, number],\n opts: VDBBuildFromDenseOptions = {},\n): Uint32Array {\n return vdbBuildFromDenseDetailed(values, dims, opts).image;\n}\n\n/**\n * As `vdbBuildFromDense`, but also returns computed metadata (used by writeNvdb).\n *\n * @param values The dense values, `nx * ny * nz` of them.\n * @param dims Voxels per axis `[nx, ny, nz]`.\n * @param opts Origin, voxel size, background, activity rule, name, class and collapsing.\n */\nexport function vdbBuildFromDenseDetailed(\n values: Float32Array,\n dims: [number, number, number],\n opts: VDBBuildFromDenseOptions = {},\n): VDBBuiltGrid {\n const [nx, ny, nz] = dims;\n if (nx < 0 || ny < 0 || nz < 0 || !Number.isInteger(nx) || !Number.isInteger(ny) || !Number.isInteger(nz)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `vdbBuildFromDense: dims must be non-negative integers, got [${nx},${ny},${nz}]`);\n }\n if (values.length !== nx * ny * nz) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `vdbBuildFromDense: values.length ${values.length} !== nx*ny*nz (${nx}*${ny}*${nz} = ${nx * ny * nz})`,\n );\n }\n\n const layout = opts.layout ?? \"x-major\";\n if (layout !== \"x-major\" && layout !== \"x-fastest\") {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `vdbBuildFromDense: unknown layout \"${String(layout)}\" (expected \"x-major\" or \"x-fastest\")`);\n }\n const origin = opts.origin ?? [0, 0, 0];\n const voxelSizeXYZ = voxelSizeVec3(opts.voxelSize, \"vdbBuildFromDense\");\n const background = opts.background ?? 0;\n const gridName = opts.gridName ?? \"dense\";\n const gridClassId = GRID_CLASS_ID[opts.gridClass ?? \"FogVolume\"];\n const worldOrigin: [number, number, number] =\n opts.worldOrigin ?? [origin[0] * voxelSizeXYZ[0], origin[1] * voxelSizeXYZ[1], origin[2] * voxelSizeXYZ[2]];\n\n const nameBytes = new TextEncoder().encode(gridName);\n if (nameBytes.length + 1 > GRID_NAME_MAX) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `vdbBuildFromDense: gridName is ${nameBytes.length} bytes; must be < ${GRID_NAME_MAX} (incl. NUL). ` +\n `Long grid names (HasLongGridName + blind metadata) are not supported in v1.`,\n );\n }\n\n const codec = VDB_FLOAT_LEAF_CODEC;\n const tree = buildTree(values, dims, {\n origin,\n background,\n activeThreshold: opts.activeThreshold,\n collapse: opts.collapse ?? true,\n layout,\n });\n\n const image = layoutGrid(tree, codec, {\n gridName,\n nameBytes,\n gridClassId,\n voxelSize: voxelSizeXYZ,\n worldOrigin,\n origin,\n background,\n });\n\n const indexBBox = bboxOrEmpty(tree.root);\n const worldBBox = worldBBoxFromIndex(indexBBox, voxelSizeXYZ, worldOrigin, origin);\n\n return {\n image,\n gridName,\n voxelCount: tree.activeVoxelCount,\n indexBBox,\n worldBBox,\n voxelSize: voxelSizeXYZ[0],\n voxelSizeXYZ,\n nodeCounts: { leaf: tree.leaves.length, lower: tree.lowers.length, upper: tree.uppers.length },\n tileCounts: { ...tree.tileCounts },\n };\n}\n\n/** A `voxelSize` option (number or `[x, y, z]`, default 1) as a validated per-axis vector. */\nfunction voxelSizeVec3(vs: number | readonly number[] | undefined, fn: string): [number, number, number] {\n const v = vs ?? 1;\n const xyz: [number, number, number] = typeof v === \"number\" ? [v, v, v] : [v[0]!, v[1]!, v[2]!];\n if ((typeof v !== \"number\" && v.length !== 3) || !xyz.every((c) => Number.isFinite(c) && c > 0)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `${fn}: voxelSize must be positive and finite (a number or [x, y, z]), got ${JSON.stringify(vs)}`);\n }\n return xyz;\n}\n\n/** Options of {@link vdbBuildFromLeavesDetailed}. */\nexport interface VDBBuildFromLeavesOptions {\n /**\n * Voxel size in world units: a number (uniform), or `[x, y, z]` for an\n * anisotropic, axis-aligned Map (diagonal scale). Default 1.\n */\n voxelSize?: number | [number, number, number];\n /** World-space translation (the NanoVDB Map's vec / index-origin world pos). Default [0,0,0]. */\n worldOrigin?: [number, number, number];\n /** Background (inactive) value: a number, or `[x, y, z]` for a Vec3f codec. Default 0. */\n background?: TileValue;\n /** Grid name (<256 bytes incl. NUL). Default \"grid\". */\n gridName?: string;\n /** Grid class. Default \"FogVolume\". */\n gridClass?: GridClassName;\n /**\n * Active tiles above leaf level (8^3 lower-node, 128^3 upper-node and 4096^3\n * root tiles), written as NanoVDB tiles rather than expanded into leaves. A\n * tile may not share a slot with a leaf or child node. Default: none.\n */\n tiles?: Iterable<TileInput>;\n /**\n * Collapse uniform leaves and nodes into tiles (OpenVDB `prune`, tolerance 0;\n * K4.6). Default false: this is the re-encoding path (`quantize`,\n * `buildFromVdb`), which keeps the source's topology so an image of a native\n * input keeps native's node counts and sizes.\n */\n collapse?: boolean;\n}\n\n/**\n * Builds a complete NanoVDB grid image from an iterator of already-materialised\n * leaves (each carrying its 8-aligned origin, all 512 values and a 512-bit value\n * mask), using the given {@link VDBLeafCodec}. This is the memory-frugal path —\n * leaves stream in, no dense array is ever allocated — that backs `buildFromVdb`\n * (parser leaves -> FLOAT) and `quantize` (an existing grid's leaves -> Fp8/FpN).\n *\n * @param leaves The leaves, in any order.\n * @param codec Encodes the leaves and constants (e.g. `VDB_FP8_LEAF_CODEC`).\n * @param opts Voxel size, origin, background, name, class, tiles and collapsing.\n */\nexport function vdbBuildFromLeavesDetailed(\n leaves: Iterable<LeafInput>,\n codec: VDBLeafCodec,\n opts: VDBBuildFromLeavesOptions = {},\n): VDBBuiltGrid {\n const voxelSizeXYZ = voxelSizeVec3(opts.voxelSize, \"buildFromLeaves\");\n const components = codec.components ?? 1;\n const background: TileValue = opts.background ?? (components === 3 ? [0, 0, 0] : 0);\n if ((typeof background === \"number\") !== (components === 1)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `buildFromLeaves: background must have ${components} component(s) for this codec`);\n }\n const gridName = opts.gridName ?? \"grid\";\n const gridClassId = GRID_CLASS_ID[opts.gridClass ?? \"FogVolume\"];\n const worldOrigin = opts.worldOrigin ?? [0, 0, 0];\n\n const nameBytes = new TextEncoder().encode(gridName);\n if (nameBytes.length + 1 > GRID_NAME_MAX) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `buildFromLeaves: gridName is ${nameBytes.length} bytes; must be < ${GRID_NAME_MAX} (incl. NUL). ` +\n `Long grid names (HasLongGridName + blind metadata) are not supported in v1.`,\n );\n }\n\n const round = components === 1 ? codec.roundValue : undefined;\n const tree = round\n ? buildTreeFromLeaves(roundLeaves(leaves, round), roundTiles(opts.tiles, round), components, {\n collapse: opts.collapse === true,\n background: round(background as number),\n })\n : buildTreeFromLeaves(leaves, opts.tiles, components, { collapse: opts.collapse === true, background });\n const image = layoutGrid(tree, codec, {\n gridName,\n nameBytes,\n gridClassId,\n voxelSize: voxelSizeXYZ,\n worldOrigin,\n origin: [0, 0, 0],\n background,\n });\n\n const indexBBox = bboxOrEmpty(tree.root);\n const worldBBox = worldBBoxFromIndex(indexBBox, voxelSizeXYZ, worldOrigin, [0, 0, 0]);\n\n return {\n image,\n gridName,\n voxelCount: tree.activeVoxelCount,\n indexBBox,\n worldBBox,\n voxelSize: voxelSizeXYZ[0],\n voxelSizeXYZ,\n nodeCounts: { leaf: tree.leaves.length, lower: tree.lowers.length, upper: tree.uppers.length },\n tileCounts: { ...tree.tileCounts },\n };\n}\n\n/** Leaves with every value passed through the codec's `roundValue` (a copy; the input is not touched). */\nfunction* roundLeaves(leaves: Iterable<LeafInput>, round: (v: number) => number): Iterable<LeafInput> {\n for (const leaf of leaves) {\n const values = new Float32Array(leaf.values.length);\n for (let n = 0; n < values.length; n++) values[n] = round(leaf.values[n]!);\n yield { ...leaf, values };\n }\n}\n\nfunction roundTiles(tiles: Iterable<TileInput> | undefined, round: (v: number) => number): TileInput[] | undefined {\n if (tiles === undefined) return undefined;\n return [...tiles].map((t) => ({ ...t, value: typeof t.value === \"number\" ? round(t.value) : t.value }));\n}\n\ninterface LayoutParams {\n gridName: string;\n nameBytes: Uint8Array;\n gridClassId: number;\n voxelSize: [number, number, number];\n worldOrigin: [number, number, number];\n origin: [number, number, number];\n background: TileValue;\n}\n\nfunction layoutGrid(tree: BuiltTree, codec: VDBLeafCodec, p: LayoutParams): Uint32Array {\n const L = codec.layout;\n const nTiles = tree.rootTiles.length;\n const nUpper = tree.uppers.length;\n const nLower = tree.lowers.length;\n const nLeaf = tree.leaves.length;\n\n // Block base offsets (all multiples of 32).\n const treeOff = GRID_SIZE; // 672\n const rootOff = treeOff + TREE_SIZE; // 736\n const rootBlockSize = L.rootSize + nTiles * L.rootTileSize;\n const upperOff = rootOff + rootBlockSize;\n const lowerOff = upperOff + nUpper * L.upperSize;\n const leafOff = lowerOff + nLower * L.lowerSize;\n\n // Per-leaf plans + cumulative offsets. FLOAT/Fp8 leaves are fixed-size; FpN\n // leaves vary (96 + bitWidth*64), so the block is not a uniform stride.\n const leafPlans = tree.leaves.map((leaf) => codec.planLeaf(leaf.values));\n const leafByteOffset = new Array<number>(nLeaf);\n let leafAcc = 0;\n for (let i = 0; i < nLeaf; i++) {\n leafByteOffset[i] = leafAcc;\n leafAcc += leafPlans[i]!.byteSize;\n }\n const total = leafOff + leafAcc;\n\n const w = new GridImageWriter(total);\n\n const upperAbs = (i: number): number => upperOff + i * L.upperSize;\n const lowerAbs = (i: number): number => lowerOff + i * L.lowerSize;\n const leafAbs = (i: number): number => leafOff + leafByteOffset[i]!;\n\n // ---- GridData ----------------------------------------------------------\n writeGridData(w, tree, codec, p, total);\n\n // ---- TreeData ----------------------------------------------------------\n w.setU64(treeOff + TREE_OFF_NODE_OFFSET_LEAF, BigInt(leafOff - treeOff));\n w.setU64(treeOff + TREE_OFF_NODE_OFFSET_LOWER, BigInt(lowerOff - treeOff));\n w.setU64(treeOff + TREE_OFF_NODE_OFFSET_UPPER, BigInt(upperOff - treeOff));\n w.setU64(treeOff + TREE_OFF_NODE_OFFSET_ROOT, BigInt(rootOff - treeOff));\n w.setU32(treeOff + TREE_OFF_NODE_COUNT_LEAF, nLeaf);\n w.setU32(treeOff + TREE_OFF_NODE_COUNT_LOWER, nLower);\n w.setU32(treeOff + TREE_OFF_NODE_COUNT_UPPER, nUpper);\n // Active tiles exist only when the leaf-path source supplied them (K4.1).\n w.setU32(treeOff + TREE_OFF_TILE_COUNT_LOWER, tree.tileCounts.lower);\n w.setU32(treeOff + TREE_OFF_TILE_COUNT_UPPER, tree.tileCounts.upper);\n w.setU32(treeOff + TREE_OFF_TILE_COUNT_ROOT, tree.tileCounts.root);\n w.setU64(treeOff + TREE_OFF_VOXEL_COUNT, BigInt(tree.activeVoxelCount));\n\n // ---- RootData + tiles --------------------------------------------------\n const ibox = bboxOrEmpty(tree.root);\n writeCoord(w, rootOff + ROOT_OFF_BBOX_MIN, ibox.min);\n writeCoord(w, rootOff + ROOT_OFF_BBOX_MAX, ibox.max);\n w.setU32(rootOff + ROOT_OFF_TABLE_SIZE, nTiles);\n codec.writeConstant(w, rootOff + L.rootOffBackground, p.background);\n writeStats(w, codec, rootOff, L.rootOffMin, L.rootOffMax, L.rootOffAve, L.rootOffStdDev, tree.root);\n\n tree.rootTiles.forEach((tile, i) => {\n const tileOff = rootOff + L.rootSize + i * L.rootTileSize;\n w.setU64(tileOff + ROOT_TILE_OFF_KEY, tile.key);\n if (tile.child) {\n w.setI64(tileOff + ROOT_TILE_OFF_CHILD, BigInt(upperAbs(tile.child.memIndex) - rootOff));\n w.setU32(tileOff + ROOT_TILE_OFF_STATE, 0);\n // Child slot: the value field stays zero (the image is zero-filled).\n } else {\n // Root tile: no child (offset 0), state on (active) or off (inactive), the tile's value.\n w.setI64(tileOff + ROOT_TILE_OFF_CHILD, 0n);\n w.setU32(tileOff + ROOT_TILE_OFF_STATE, tile.active ? 1 : 0);\n codec.writeConstant(w, tileOff + L.rootTileOffValue, tile.value);\n }\n });\n\n // ---- Upper nodes -------------------------------------------------------\n for (const upper of tree.uppers) {\n writeInternalNode(w, upperAbs(upper.memIndex), upper, {\n tableCount: UPPER_TABLE_COUNT,\n childMaskOff: UPPER_OFF_CHILD_MASK,\n tableOff: L.upperOffTable,\n tableStride: L.tableStride,\n offMin: L.upperOffMin,\n offMax: L.upperOffMax,\n offAve: L.upperOffAve,\n offStdDev: L.upperOffStdDev,\n background: p.background,\n codec,\n childAbs: lowerAbs,\n });\n }\n\n // ---- Lower nodes -------------------------------------------------------\n for (const lower of tree.lowers) {\n writeInternalNode(w, lowerAbs(lower.memIndex), lower, {\n tableCount: LOWER_TABLE_COUNT,\n childMaskOff: LOWER_OFF_CHILD_MASK,\n tableOff: L.lowerOffTable,\n tableStride: L.tableStride,\n offMin: L.lowerOffMin,\n offMax: L.lowerOffMax,\n offAve: L.lowerOffAve,\n offStdDev: L.lowerOffStdDev,\n background: p.background,\n codec,\n childAbs: leafAbs,\n });\n }\n\n // ---- Leaf nodes --------------------------------------------------------\n for (const leaf of tree.leaves) {\n codec.encodeLeaf(w, leafAbs(leaf.memIndex), leaf, leafPlans[leaf.memIndex]!);\n }\n\n return w.u32;\n}\n\ninterface InternalNodeWriteParams {\n tableCount: number;\n childMaskOff: number;\n tableOff: number;\n tableStride: number;\n offMin: number;\n offMax: number;\n offAve: number;\n offStdDev: number;\n background: TileValue;\n codec: VDBLeafCodec;\n /** Absolute byte offset of child with the given memIndex. */\n childAbs: (memIndex: number) => number;\n}\n\nfunction writeInternalNode(\n w: GridImageWriter,\n nodeOff: number,\n node: UpperNode | LowerNode,\n p: InternalNodeWriteParams,\n): void {\n const s = node.stats;\n const bmin = s.isEmpty ? node.origin : s.bboxMin;\n const bmax = s.isEmpty ? node.origin : s.bboxMax;\n writeCoord(w, nodeOff + NODE_OFF_BBOX_MIN, bmin);\n writeCoord(w, nodeOff + NODE_OFF_BBOX_MAX, bmax);\n w.setU64(nodeOff + NODE_OFF_FLAGS, BigInt(NODE_FLAG_STATS));\n writeStats(w, p.codec, nodeOff, p.offMin, p.offMax, p.offAve, p.offStdDev, s);\n\n // Table: child slots hold an i64 offset (relative to this node); active\n // tiles set their value-mask bit and hold the tile value; every other slot\n // is an inactive background tile carrying the background value.\n const childSlots = node.children;\n const tiles = node.tiles;\n const inactiveTiles = node.inactiveTiles;\n const backgroundIsZero =\n typeof p.background === \"number\" ? p.background === 0 : p.background.every((c) => c === 0);\n for (let n = 0; n < p.tableCount; n++) {\n const slotOff = nodeOff + p.tableOff + n * p.tableStride;\n const child = childSlots.get(n);\n const tileValue = tiles.size > 0 ? tiles.get(n) : undefined;\n if (child !== undefined) {\n w.setMaskBit(nodeOff + p.childMaskOff, n);\n w.setI64(slotOff, BigInt(p.childAbs(child.memIndex) - nodeOff));\n } else if (tileValue !== undefined) {\n w.setMaskBit(nodeOff + NODE_OFF_VALUE_MASK, n);\n p.codec.writeConstant(w, slotOff, tileValue);\n } else if (inactiveTiles.size > 0 && inactiveTiles.has(n)) {\n p.codec.writeConstant(w, slotOff, inactiveTiles.get(n)!);\n } else if (!backgroundIsZero) {\n // Skip when background is 0: the buffer is already zero-filled.\n p.codec.writeConstant(w, slotOff, p.background);\n }\n }\n}\n\nfunction writeStats(\n w: GridImageWriter,\n codec: VDBLeafCodec,\n base: number,\n offMin: number,\n offMax: number,\n offAve: number,\n offStdDev: number,\n s: StatsAccumulator,\n): void {\n if (codec.components === 3) {\n writeVec3StatsBlock(w, base, offMin, offMax, offAve, offStdDev, s);\n return;\n }\n // Min/max have the grid's value type (f32, or binary16 for Half); ave/stddev are f32.\n // Extrema's start value (the type's largest finite) stays when a node holds only +-inf (K7.H1).\n const finiteMax = codec.layout.gridType === GRID_TYPE_HALF ? STATS_HALF_MAX : STATS_FLOAT_MAX;\n codec.writeConstant(w, base + offMin, s.storedMin(finiteMax));\n codec.writeConstant(w, base + offMax, s.storedMax(finiteMax));\n w.setF32(base + offAve, s.average);\n w.setF32(base + offStdDev, s.stdDev);\n}\n\nfunction writeGridData(\n w: GridImageWriter,\n tree: BuiltTree,\n codec: VDBLeafCodec,\n p: LayoutParams,\n total: number,\n): void {\n w.setU64(GRID_OFF_MAGIC, MAGIC_GRID);\n w.setU64(GRID_OFF_CHECKSUM, CHECKSUM_DISABLED);\n w.setU32(GRID_OFF_VERSION, VERSION_PACKED);\n w.setU32(GRID_OFF_FLAGS, GRID_FLAGS_STATS_BBOX_BREADTH_FIRST);\n w.setU32(GRID_OFF_GRID_INDEX, 0);\n w.setU32(GRID_OFF_GRID_COUNT, 1);\n w.setU64(GRID_OFF_GRID_SIZE, BigInt(total));\n // Grid name: C string in the fixed 256-byte inline field.\n w.setBytes(GRID_OFF_GRID_NAME, p.nameBytes); // NUL terminator already zero\n writeMap(w, p);\n writeWorldBBox(w, tree, p);\n const vs = p.voxelSize;\n w.setF64(GRID_OFF_VOXEL_SIZE, vs[0]);\n w.setF64(GRID_OFF_VOXEL_SIZE + 8, vs[1]);\n w.setF64(GRID_OFF_VOXEL_SIZE + 16, vs[2]);\n w.setU32(GRID_OFF_GRID_CLASS, p.gridClassId);\n w.setU32(GRID_OFF_GRID_TYPE, codec.layout.gridType);\n // No blind metadata: offset points at end-of-grid, count 0 (native\n // convention, verified on sphere_fog_float.nvdb).\n w.setU64(GRID_OFF_BLIND_METADATA_OFFSET, BigInt(total));\n w.setU32(GRID_OFF_BLIND_METADATA_COUNT, 0);\n w.setU32(GRID_OFF_DATA0, 0);\n w.setU64(GRID_OFF_DATA1, 0n);\n w.setU64(GRID_OFF_DATA2, 0n);\n}\n\nfunction writeMap(w: GridImageWriter, p: LayoutParams): void {\n const s = p.voxelSize;\n const t: [number, number, number] = [\n p.worldOrigin[0] - p.origin[0] * s[0],\n p.worldOrigin[1] - p.origin[1] * s[1],\n p.worldOrigin[2] - p.origin[2] * s[2],\n ];\n const mat = [s[0], 0, 0, 0, s[1], 0, 0, 0, s[2]];\n const invMat = [1 / s[0], 0, 0, 0, 1 / s[1], 0, 0, 0, 1 / s[2]];\n const mapBase = GRID_OFF_MAP;\n for (let i = 0; i < 9; i++) {\n w.setF32(mapBase + MAP_OFF_MATF + i * 4, mat[i]!);\n w.setF32(mapBase + MAP_OFF_INVMATF + i * 4, invMat[i]!);\n w.setF64(mapBase + MAP_OFF_MATD + i * 8, mat[i]!);\n w.setF64(mapBase + MAP_OFF_INVMATD + i * 8, invMat[i]!);\n }\n for (let i = 0; i < 3; i++) {\n w.setF32(mapBase + MAP_OFF_VECF + i * 4, t[i]!);\n w.setF64(mapBase + MAP_OFF_VECD + i * 8, t[i]!);\n }\n w.setF32(mapBase + MAP_OFF_TAPERF, 1);\n w.setF64(mapBase + MAP_OFF_TAPERD, 1);\n}\n\nfunction writeWorldBBox(w: GridImageWriter, tree: BuiltTree, p: LayoutParams): void {\n const ibox = bboxOrEmpty(tree.root);\n const wb = worldBBoxFromIndex(ibox, p.voxelSize, p.worldOrigin, p.origin);\n for (let a = 0; a < 3; a++) w.setF64(GRID_OFF_WORLD_BBOX + a * 8, wb.min[a]!);\n for (let a = 0; a < 3; a++) w.setF64(GRID_OFF_WORLD_BBOX + 24 + a * 8, wb.max[a]!);\n}\n\n// ---------------------------------------------------------------------------\n// Small helpers\n// ---------------------------------------------------------------------------\n\nfunction writeCoord(w: GridImageWriter, off: number, c: readonly [number, number, number]): void {\n w.setI32(off, c[0]);\n w.setI32(off + 4, c[1]);\n w.setI32(off + 8, c[2]);\n}\n\nfunction bboxOrEmpty(s: StatsAccumulator): {\n min: [number, number, number];\n max: [number, number, number];\n} {\n if (s.isEmpty) return { min: [0, 0, 0], max: [-1, -1, -1] };\n return { min: [...s.bboxMin], max: [...s.bboxMax] };\n}\n\nfunction worldBBoxFromIndex(\n ibox: { min: [number, number, number]; max: [number, number, number] },\n voxelSize: [number, number, number],\n worldOrigin: [number, number, number],\n origin: [number, number, number],\n): { min: [number, number, number]; max: [number, number, number] } {\n const t = [\n worldOrigin[0] - origin[0] * voxelSize[0],\n worldOrigin[1] - origin[1] * voxelSize[1],\n worldOrigin[2] - origin[2] * voxelSize[2],\n ];\n const min: [number, number, number] = [0, 0, 0];\n const max: [number, number, number] = [0, 0, 0];\n for (let a = 0; a < 3; a++) {\n min[a] = ibox.min[a]! * voxelSize[a]! + t[a]!;\n // \"+ one voxel\" convention: world max corner is (indexMax + 1) * voxelSize.\n max[a] = (ibox.max[a]! + 1) * voxelSize[a]! + t[a]!;\n }\n return { min, max };\n}\n"]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* stats.ts — per-node active-value statistics, computed the way NanoVDB's
|
|
3
|
+
* `tools/GridStats.h` does: min/max are the extrema of *active* voxel values in
|
|
4
|
+
* a node's subtree, `ave` is their arithmetic mean, and `stddev` is the
|
|
5
|
+
* *population* standard deviation (divide by N, not N-1). A parent node's stats
|
|
6
|
+
* are the exact aggregate of its children's plus its own active tiles, each
|
|
7
|
+
* tile counted with GridStats' weight (see {@link StatsAccumulator.addTile}).
|
|
8
|
+
*
|
|
9
|
+
* Two accumulations (K7.H1, DIVERGES V73), chosen by
|
|
10
|
+
* {@link vdbSetStatsAccumulation} when an accumulator is made:
|
|
11
|
+
* - `'welford'` (default since K7.H1): GridStats' own f64 update, ported
|
|
12
|
+
* operation for operation (`Stats<T, 0>::add(val)`, `add(val, n)`,
|
|
13
|
+
* `add(other)`). Fed in GridStats' order (leaf voxels by offset, an internal
|
|
14
|
+
* node's active tiles then its children by slot, the root table in order) it
|
|
15
|
+
* reproduces native ave/stddev bit for bit, ±∞ leaves included (NaN there).
|
|
16
|
+
* - `'sums'` (K1–K7.H): f64 count, sum and sum of squares; ave/stddev within a
|
|
17
|
+
* few f32 ulp of native, ±∞ where Welford gives NaN.
|
|
18
|
+
* Either way ave/stddev are narrowed to f32 only when stored.
|
|
19
|
+
*/
|
|
20
|
+
/** How {@link StatsAccumulator} accumulates ave/stddev (K7.H1 A/B; see the file header). */
|
|
21
|
+
export type VDBStatsAccumulation = "welford" | "sums";
|
|
22
|
+
/**
|
|
23
|
+
* Sets how accumulators made from now on compute ave/stddev, and returns the previous setting.
|
|
24
|
+
* Internal (tests and A/B scripts); builds made under one setting are consistent.
|
|
25
|
+
*/
|
|
26
|
+
export declare function vdbSetStatsAccumulation(mode: VDBStatsAccumulation): VDBStatsAccumulation;
|
|
27
|
+
/** Running active-value statistics plus the tight index-space bbox of the
|
|
28
|
+
* active voxels they cover. */
|
|
29
|
+
export declare class StatsAccumulator {
|
|
30
|
+
/** Samples (with tiles: GridStats weight, see {@link addTile}). */
|
|
31
|
+
count: number;
|
|
32
|
+
readonly mode: VDBStatsAccumulation;
|
|
33
|
+
private sum;
|
|
34
|
+
private sumSq;
|
|
35
|
+
private avg;
|
|
36
|
+
private aux;
|
|
37
|
+
min: number;
|
|
38
|
+
max: number;
|
|
39
|
+
bboxMin: [number, number, number];
|
|
40
|
+
bboxMax: [number, number, number];
|
|
41
|
+
/** Adds one active voxel at index coord (x,y,z) with the given value. */
|
|
42
|
+
addVoxel(value: number, x: number, y: number, z: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* Adds an active tile: `value` counted `weight` times, with the tile's
|
|
45
|
+
* inclusive index bbox. NanoVDB GridStats passes the child node type's slot
|
|
46
|
+
* count as the weight, so once tiles are involved `count` is a stats weight,
|
|
47
|
+
* not a voxel count.
|
|
48
|
+
*/
|
|
49
|
+
addTile(value: number, weight: number, bboxMin: readonly [number, number, number], bboxMax: readonly [number, number, number]): void;
|
|
50
|
+
/** Merges a child accumulator's totals into this one (both must use the same accumulation). */
|
|
51
|
+
merge(child: StatsAccumulator): void;
|
|
52
|
+
get average(): number;
|
|
53
|
+
/** Population standard deviation (GridStats convention). */
|
|
54
|
+
get stdDev(): number;
|
|
55
|
+
get isEmpty(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* `min` as GridStats' `Extrema` stores it: Extrema starts at the value type's largest finite value
|
|
58
|
+
* (`finiteMax`: FLT_MAX for Float, 65504 for Half), so a node whose values are all +∞ keeps that
|
|
59
|
+
* start value as its minimum (K7.H1). 0 when empty.
|
|
60
|
+
*/
|
|
61
|
+
storedMin(finiteMax: number): number;
|
|
62
|
+
/** `max` as GridStats stores it: −`finiteMax` when every value is −∞ (see {@link storedMin}). 0 when empty. */
|
|
63
|
+
storedMax(finiteMax: number): number;
|
|
64
|
+
}
|
|
65
|
+
/** FLT_MAX, `std::numeric_limits<float>::max()`: GridStats' starting minimum for f32 values. */
|
|
66
|
+
export declare const STATS_FLOAT_MAX = 3.4028234663852886e+38;
|
|
67
|
+
/** 65504, the largest finite binary16: GridStats' starting minimum for Half values (raw 0x7BFF). */
|
|
68
|
+
export declare const STATS_HALF_MAX = 65504;
|
|
69
|
+
/** `Vec3<float>::lengthSqr()` evaluated in f32: `x*x + y*y + z*z`, left to right. */
|
|
70
|
+
export declare function lengthSqrF32(x: number, y: number, z: number): number;
|
|
71
|
+
/**
|
|
72
|
+
* Vector statistics, NanoVDB `tools/GridStats.h` `Stats<Vec3f, 1>` (rank 1):
|
|
73
|
+
* every value is ranked by its f32 `lengthSqr()`. `min`/`max` (inherited) are
|
|
74
|
+
* the extreme squared lengths and {@link minVec}/{@link maxVec} the vectors
|
|
75
|
+
* that hold them (first one wins on ties, as `Pair::operator<` is strict);
|
|
76
|
+
* `average` and `stdDev` are the mean and population standard deviation of the
|
|
77
|
+
* squared lengths, not of the components.
|
|
78
|
+
*/
|
|
79
|
+
export declare class Vec3StatsAccumulator extends StatsAccumulator {
|
|
80
|
+
minVec: [number, number, number];
|
|
81
|
+
maxVec: [number, number, number];
|
|
82
|
+
/** Adds one active voxel with vector value (vx, vy, vz) at index coord (x, y, z). */
|
|
83
|
+
addVoxelVec(vx: number, vy: number, vz: number, x: number, y: number, z: number): void;
|
|
84
|
+
/** Adds an active vector tile with GridStats weight `weight` (see {@link StatsAccumulator.addTile}). */
|
|
85
|
+
addTileVec(value: readonly [number, number, number], weight: number, bboxMin: readonly [number, number, number], bboxMax: readonly [number, number, number]): void;
|
|
86
|
+
merge(child: StatsAccumulator): void;
|
|
87
|
+
}
|