@pmndrs/vdb 0.1.0 → 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 +592 -2
- package/README.md +85 -37
- package/THIRD_PARTY_NOTICES.md +197 -29
- package/dist/core/compute/atlas.d.ts +10 -2
- package/dist/core/compute/atlas.js +6 -1
- package/dist/core/compute/atlas.js.map +1 -1
- package/dist/core/compute/index.d.ts +3 -3
- package/dist/core/compute/index.js +2 -2
- package/dist/core/compute/index.js.map +1 -1
- 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 +22 -7
- package/dist/core/compute/pyramid.js +22 -9
- package/dist/core/compute/pyramid.js.map +1 -1
- package/dist/core/compute/shared.d.ts +1 -0
- package/dist/core/compute/shared.js.map +1 -1
- package/dist/core/compute/stats.d.ts +10 -3
- package/dist/core/compute/stats.js +6 -1
- package/dist/core/compute/stats.js.map +1 -1
- package/dist/core/compute/value-transform.d.ts +8 -1
- package/dist/core/compute/value-transform.js +9 -3
- package/dist/core/compute/value-transform.js.map +1 -1
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.js +8 -0
- package/dist/core/errors.js.map +1 -1
- 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 +25 -3
- package/dist/core/index.js +23 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/internal.d.ts +17 -1
- package/dist/core/internal.js +18 -1
- package/dist/core/internal.js.map +1 -1
- package/dist/core/pool/image-header.d.ts +13 -2
- package/dist/core/pool/image-header.js +24 -5
- package/dist/core/pool/image-header.js.map +1 -1
- package/dist/core/pool/layout.d.ts +35 -1
- package/dist/core/pool/layout.js +51 -2
- package/dist/core/pool/layout.js.map +1 -1
- package/dist/core/pool/limits.d.ts +1 -0
- package/dist/core/pool/limits.js +1 -0
- package/dist/core/pool/limits.js.map +1 -1
- package/dist/core/pool/pool.d.ts +120 -15
- package/dist/core/pool/pool.js +255 -24
- package/dist/core/pool/pool.js.map +1 -1
- 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/{three → core}/sequence.d.ts +32 -2
- package/dist/{three → core}/sequence.js +24 -2
- 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 +33 -2
- package/dist/core/source/dense.js +121 -24
- package/dist/core/source/dense.js.map +1 -1
- 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 +59 -2
- package/dist/core/source/types.js.map +1 -1
- 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 +12 -3
- package/dist/core/types.js +6 -2
- package/dist/core/types.js.map +1 -1
- package/dist/core/wgsl/api.d.ts +29 -5
- package/dist/core/wgsl/api.js +110 -27
- package/dist/core/wgsl/api.js.map +1 -1
- package/dist/core/wgsl/generate.d.ts +8 -0
- package/dist/core/wgsl/generate.js +195 -22
- package/dist/core/wgsl/generate.js.map +1 -1
- 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 +5 -1
- package/dist/core/wgsl/level-set.js +11 -5
- package/dist/core/wgsl/level-set.js.map +1 -1
- 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 +2 -2
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
- package/dist/core/wgsl/types.d.ts +97 -3
- package/dist/core/wgsl/types.js.map +1 -1
- package/dist/three/coarse-first.d.ts +53 -8
- package/dist/three/coarse-first.js +24 -6
- package/dist/three/coarse-first.js.map +1 -1
- package/dist/three/compute.d.ts +12 -2
- package/dist/three/compute.js +16 -6
- package/dist/three/compute.js.map +1 -1
- package/dist/three/device.d.ts +7 -0
- package/dist/three/device.js +3 -0
- package/dist/three/device.js.map +1 -1
- 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 +64 -114
- package/dist/three/frame/emission-light.js +188 -567
- package/dist/three/frame/emission-light.js.map +1 -1
- package/dist/three/frame/index.d.ts +11 -31
- package/dist/three/frame/index.js +9 -29
- package/dist/three/frame/index.js.map +1 -1
- package/dist/three/frame/medium.d.ts +12 -0
- package/dist/three/frame/medium.js.map +1 -1
- package/dist/three/frame/renderer.d.ts +58 -454
- package/dist/three/frame/renderer.js +409 -1427
- package/dist/three/frame/renderer.js.map +1 -1
- package/dist/three/frame/spectrum.d.ts +0 -14
- package/dist/three/frame/spectrum.js +2 -23
- package/dist/three/frame/spectrum.js.map +1 -1
- package/dist/three/frame/three-internals.d.ts +3 -8
- package/dist/three/frame/three-internals.js +13 -11
- package/dist/three/frame/three-internals.js.map +1 -1
- package/dist/three/frame/volume-shadows.d.ts +93 -107
- package/dist/three/frame/volume-shadows.js +278 -631
- package/dist/three/frame/volume-shadows.js.map +1 -1
- package/dist/three/frame/volume.d.ts +91 -33
- package/dist/three/frame/volume.js +63 -51
- package/dist/three/frame/volume.js.map +1 -1
- package/dist/three/grid-node.d.ts +34 -1
- package/dist/three/grid-node.js +36 -1
- package/dist/three/grid-node.js.map +1 -1
- package/dist/three/index.d.ts +20 -11
- package/dist/three/index.js +21 -12
- package/dist/three/index.js.map +1 -1
- package/dist/three/internal.d.ts +14 -8
- package/dist/three/internal.js +11 -7
- package/dist/three/internal.js.map +1 -1
- package/dist/three/level-set-material.d.ts +81 -8
- package/dist/three/level-set-material.js +162 -125
- package/dist/three/level-set-material.js.map +1 -1
- 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 +141 -11
- package/dist/three/material.js +161 -18
- package/dist/three/material.js.map +1 -1
- package/dist/three/points.d.ts +60 -4
- package/dist/three/points.js +140 -9
- package/dist/three/points.js.map +1 -1
- package/dist/three/sparse-source.d.ts +49 -117
- package/dist/three/sparse-source.js +109 -580
- package/dist/three/sparse-source.js.map +1 -1
- package/dist/three/volume-source.d.ts +11 -156
- package/dist/three/volume-source.js +29 -272
- package/dist/three/volume-source.js.map +1 -1
- 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 +23 -4
- package/dist/tools/cpu/compute.js +35 -14
- package/dist/tools/cpu/compute.js.map +1 -1
- 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 +42 -3
- package/dist/tools/cpu/level-set.js +59 -7
- package/dist/tools/cpu/level-set.js.map +1 -1
- 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 +93 -2
- package/dist/tools/cpu/march.js +165 -14
- package/dist/tools/cpu/march.js.map +1 -1
- 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/read-value.d.ts +19 -6
- package/dist/tools/cpu/read-value.js +32 -17
- package/dist/tools/cpu/read-value.js.map +1 -1
- package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
- package/dist/tools/cpu/sample-trilinear.js +19 -7
- package/dist/tools/cpu/sample-trilinear.js.map +1 -1
- package/dist/tools/cpu/stride-tables.d.ts +2 -2
- package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
- package/dist/tools/cpu/stride-tables.generated.js +7 -6
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
- package/dist/tools/cpu/stride-tables.js +1 -1
- package/dist/tools/cpu/stride-tables.js.map +1 -1
- 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 +9 -0
- package/dist/tools/errors.js +9 -0
- package/dist/tools/errors.js.map +1 -1
- 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 +15 -0
- package/dist/tools/frame/blackbody.js +35 -0
- package/dist/tools/frame/blackbody.js.map +1 -1
- 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 +9 -0
- package/dist/tools/frame/emission.js +9 -1
- package/dist/tools/frame/emission.js.map +1 -1
- 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 +3 -2
- package/dist/tools/frame/environment.js +8 -4
- package/dist/tools/frame/environment.js.map +1 -1
- 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 +90 -0
- package/dist/tools/frame/grid.js +112 -13
- package/dist/tools/frame/grid.js.map +1 -1
- package/dist/tools/frame/index.d.ts +14 -0
- package/dist/tools/frame/index.js +45 -4
- package/dist/tools/frame/index.js.map +1 -1
- package/dist/tools/frame/medium.d.ts +16 -0
- package/dist/tools/frame/medium.js +3 -1
- package/dist/tools/frame/medium.js.map +1 -1
- package/dist/tools/frame/mie.d.ts +9 -0
- package/dist/tools/frame/mie.js +18 -0
- package/dist/tools/frame/mie.js.map +1 -1
- 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 +6 -5
- package/dist/tools/frame/neural-weights.js +234 -235
- package/dist/tools/frame/neural-weights.js.map +1 -1
- package/dist/tools/frame/neural.js +1 -1
- package/dist/tools/frame/neural.js.map +1 -1
- 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 +17 -0
- package/dist/tools/frame/pyramid-layout.js +47 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -1
- package/dist/tools/frame/shadows.d.ts +110 -0
- package/dist/tools/frame/shadows.js +286 -0
- package/dist/tools/frame/shadows.js.map +1 -1
- package/dist/tools/frame/sparse.d.ts +82 -0
- package/dist/tools/frame/sparse.js +242 -1
- package/dist/tools/frame/sparse.js.map +1 -1
- 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 +21 -2
- package/dist/tools/frame/spectral.js +30 -8
- package/dist/tools/frame/spectral.js.map +1 -1
- 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 +66 -15
- package/dist/tools/index.js +55 -11
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/internal.d.ts +58 -17
- package/dist/tools/internal.js +65 -11
- package/dist/tools/internal.js.map +1 -1
- package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
- package/dist/tools/nanovdb/build-from-vdb.js +10 -2
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
- package/dist/tools/nanovdb/bytes.d.ts +17 -4
- package/dist/tools/nanovdb/bytes.js +46 -3
- package/dist/tools/nanovdb/bytes.js.map +1 -1
- package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
- package/dist/tools/nanovdb/coarse-first.js +7 -1
- package/dist/tools/nanovdb/coarse-first.js.map +1 -1
- 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 +3 -1
- package/dist/tools/nanovdb/index.js +2 -1
- package/dist/tools/nanovdb/index.js.map +1 -1
- package/dist/tools/nanovdb/inspect.d.ts +10 -1
- package/dist/tools/nanovdb/inspect.js +8 -1
- package/dist/tools/nanovdb/inspect.js.map +1 -1
- package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
- package/dist/tools/nanovdb/leaf-codec.js +40 -4
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
- package/dist/tools/nanovdb/quantize.d.ts +39 -10
- package/dist/tools/nanovdb/quantize.js +96 -44
- package/dist/tools/nanovdb/quantize.js.map +1 -1
- package/dist/tools/nanovdb/resample.d.ts +20 -3
- package/dist/tools/nanovdb/resample.js +20 -7
- package/dist/tools/nanovdb/resample.js.map +1 -1
- package/dist/tools/nanovdb/serialize.d.ts +34 -3
- package/dist/tools/nanovdb/serialize.js +51 -7
- package/dist/tools/nanovdb/serialize.js.map +1 -1
- package/dist/tools/nanovdb/stats.d.ts +34 -5
- package/dist/tools/nanovdb/stats.js +87 -11
- package/dist/tools/nanovdb/stats.js.map +1 -1
- package/dist/tools/nanovdb/transform.d.ts +4 -0
- package/dist/tools/nanovdb/transform.js +3 -0
- package/dist/tools/nanovdb/transform.js.map +1 -1
- package/dist/tools/nanovdb/tree.d.ts +14 -3
- package/dist/tools/nanovdb/tree.js +25 -13
- package/dist/tools/nanovdb/tree.js.map +1 -1
- package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
- package/dist/tools/nanovdb/write-nvdb.js +108 -28
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
- package/dist/tools/nvdb-file.d.ts +77 -7
- package/dist/tools/nvdb-file.js +177 -20
- package/dist/tools/nvdb-file.js.map +1 -1
- package/dist/tools/nvdb-stream.d.ts +23 -7
- package/dist/tools/nvdb-stream.js +78 -34
- package/dist/tools/nvdb-stream.js.map +1 -1
- 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/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 +35 -5
- package/dist/tools/vdb/blosc.js +82 -26
- package/dist/tools/vdb/blosc.js.map +1 -1
- 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 +13 -3
- package/dist/tools/vdb/byte-reader.js +26 -4
- package/dist/tools/vdb/byte-reader.js.map +1 -1
- package/dist/tools/vdb/compression.d.ts +13 -5
- package/dist/tools/vdb/compression.js +13 -2
- package/dist/tools/vdb/compression.js.map +1 -1
- package/dist/tools/vdb/grid.js +8 -2
- package/dist/tools/vdb/grid.js.map +1 -1
- package/dist/tools/vdb/index.d.ts +2 -1
- package/dist/tools/vdb/index.js.map +1 -1
- 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.js +1 -1
- package/dist/tools/vdb/metadata.js.map +1 -1
- package/dist/tools/vdb/parse.d.ts +24 -2
- package/dist/tools/vdb/parse.js +102 -32
- package/dist/tools/vdb/parse.js.map +1 -1
- package/dist/tools/vdb/point-render-data.d.ts +49 -1
- package/dist/tools/vdb/point-render-data.js +91 -11
- package/dist/tools/vdb/point-render-data.js.map +1 -1
- package/dist/tools/vdb/points.d.ts +26 -0
- package/dist/tools/vdb/points.js +46 -5
- package/dist/tools/vdb/points.js.map +1 -1
- package/dist/tools/vdb/types.d.ts +59 -2
- package/dist/tools/vdb/types.js.map +1 -1
- package/dist/tools/wvdb/bake.d.ts +38 -9
- package/dist/tools/wvdb/bake.js +63 -13
- package/dist/tools/wvdb/bake.js.map +1 -1
- package/dist/tools/wvdb/dense.d.ts +80 -1
- package/dist/tools/wvdb/dense.js +67 -8
- package/dist/tools/wvdb/dense.js.map +1 -1
- package/dist/tools/wvdb/format.d.ts +59 -0
- package/dist/tools/wvdb/format.js +3 -0
- package/dist/tools/wvdb/format.js.map +1 -1
- package/dist/tools/wvdb/index.d.ts +1 -0
- package/dist/tools/wvdb/index.js +1 -0
- package/dist/tools/wvdb/index.js.map +1 -1
- package/dist/tools/wvdb/level-set.d.ts +10 -2
- package/dist/tools/wvdb/level-set.js.map +1 -1
- package/dist/tools/wvdb/nanovdb.d.ts +6 -1
- package/dist/tools/wvdb/nanovdb.js +5 -1
- package/dist/tools/wvdb/nanovdb.js.map +1 -1
- 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 +77 -1
- package/dist/tools/wvdb/read.js +30 -7
- package/dist/tools/wvdb/read.js.map +1 -1
- package/dist/tools/wvdb/write.d.ts +23 -1
- package/dist/tools/wvdb/write.js +8 -1
- package/dist/tools/wvdb/write.js.map +1 -1
- package/package.json +2 -1
- package/vendor/VENDOR.md +21 -6
- package/vendor/pnanovdb.wgsl +52 -14
- package/dist/three/frame/blackbody.d.ts +0 -42
- package/dist/three/frame/blackbody.js +0 -74
- package/dist/three/frame/blackbody.js.map +0 -1
- package/dist/three/frame/chunks.d.ts +0 -157
- package/dist/three/frame/chunks.js +0 -559
- package/dist/three/frame/chunks.js.map +0 -1
- package/dist/three/frame/density-material.d.ts +0 -53
- package/dist/three/frame/density-material.js +0 -353
- package/dist/three/frame/density-material.js.map +0 -1
- package/dist/three/frame/environment-grid-material.d.ts +0 -21
- package/dist/three/frame/environment-grid-material.js +0 -184
- package/dist/three/frame/environment-grid-material.js.map +0 -1
- package/dist/three/frame/environment-material.d.ts +0 -22
- package/dist/three/frame/environment-material.js +0 -87
- package/dist/three/frame/environment-material.js.map +0 -1
- package/dist/three/frame/grid-mip-material.d.ts +0 -12
- package/dist/three/frame/grid-mip-material.js +0 -61
- package/dist/three/frame/grid-mip-material.js.map +0 -1
- package/dist/three/frame/inject-material.d.ts +0 -56
- package/dist/three/frame/inject-material.js +0 -424
- package/dist/three/frame/inject-material.js.map +0 -1
- package/dist/three/frame/integrate-material.d.ts +0 -26
- package/dist/three/frame/integrate-material.js +0 -198
- package/dist/three/frame/integrate-material.js.map +0 -1
- package/dist/three/frame/layout.d.ts +0 -34
- package/dist/three/frame/layout.js +0 -48
- package/dist/three/frame/layout.js.map +0 -1
- package/dist/three/frame/lighting-material.d.ts +0 -41
- package/dist/three/frame/lighting-material.js +0 -257
- package/dist/three/frame/lighting-material.js.map +0 -1
- package/dist/three/frame/lights.d.ts +0 -11
- package/dist/three/frame/lights.js +0 -16
- package/dist/three/frame/lights.js.map +0 -1
- package/dist/three/frame/neural.d.ts +0 -14
- package/dist/three/frame/neural.js +0 -105
- package/dist/three/frame/neural.js.map +0 -1
- package/dist/three/frame/phase.d.ts +0 -44
- package/dist/three/frame/phase.js +0 -80
- package/dist/three/frame/phase.js.map +0 -1
- package/dist/three/frame/shadow-density-material.d.ts +0 -30
- package/dist/three/frame/shadow-density-material.js +0 -123
- package/dist/three/frame/shadow-density-material.js.map +0 -1
- package/dist/three/frame/temporal-material.d.ts +0 -29
- package/dist/three/frame/temporal-material.js +0 -152
- package/dist/three/frame/temporal-material.js.map +0 -1
- package/dist/three/frame/transmittance-material.d.ts +0 -31
- package/dist/three/frame/transmittance-material.js +0 -315
- package/dist/three/frame/transmittance-material.js.map +0 -1
- package/dist/three/frame/view.d.ts +0 -103
- package/dist/three/frame/view.js +0 -296
- package/dist/three/frame/view.js.map +0 -1
- package/dist/three/frame/volume-shadow-material.d.ts +0 -36
- package/dist/three/frame/volume-shadow-material.js +0 -128
- package/dist/three/frame/volume-shadow-material.js.map +0 -1
- package/dist/three/sequence.js.map +0 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P1.12, the optional "B" path of the pathtracer integration: a NanoVDB grid to pmndrs/pathtracer's V3.2 sparse
|
|
3
|
+
* brick atlas + indirection (`volumes.gridLayout: 'atlas'`, its `buildBrickAtlas(resolution, dense)` in
|
|
4
|
+
* `packages/pathtracer/src/volume/volume.ts`, MIT, read at main `06488fa`), straight from the tree's leaves and tiles,
|
|
5
|
+
* without a dense copy of the grid. Its kernels then read the atlas as they do today; the `.nvdb` is only the
|
|
6
|
+
* delivery format.
|
|
7
|
+
*
|
|
8
|
+
* The layout is its own (bit for bit on the same field): bricks of 8³ cells, brick `c` holding the voxels
|
|
9
|
+
* `[8c - 1, 8c + 7]` (its trilinear support, `ATLAS_CELL = 9` texels per side), a brick occupied when its majorant is
|
|
10
|
+
* above 0 (`vdbBrickMajorant(image, { align: 'pathtracer' })`, equal to its `brickMajorants`, P1.2), occupied bricks
|
|
11
|
+
* packed in x-fastest cell order into a near-cubic block of `ceil(cbrt(occupied))²` bricks per layer, and an `r32uint`
|
|
12
|
+
* indirection `bx | by << 10 | bz << 20` (`0xffffffff` for an empty brick). The field is the P1.1 contract's: the grid
|
|
13
|
+
* inside its index bbox, 0 outside it and outside `[0, resolution)`.
|
|
14
|
+
*/
|
|
15
|
+
import { VDBToolsError } from "../errors.js";
|
|
16
|
+
import { brickMajorantLayout, vdbBrickMajorant } from "./majorant.js";
|
|
17
|
+
import { forEachTreeRegion, indexBBox, leafVoxels } from "./march.js";
|
|
18
|
+
/** Brick edge in voxels (its `BRICK`). */
|
|
19
|
+
const BRICK = 8;
|
|
20
|
+
/** Atlas texels per brick side (its `ATLAS_CELL`: the brick plus a one-voxel apron on the low side). */
|
|
21
|
+
const CELL = BRICK + 1;
|
|
22
|
+
/** Indirection value of an empty brick (its `ATLAS_EMPTY`). */
|
|
23
|
+
const EMPTY = 0xffffffff;
|
|
24
|
+
/**
|
|
25
|
+
* Builds pmndrs/pathtracer's V3.2 brick atlas and indirection (`volumes.gridLayout: 'atlas'`) from a NanoVDB grid image
|
|
26
|
+
* (P1.12): the arrays its `buildBrickAtlas(resolution, dense)` gives for the dense grid of the same field, without
|
|
27
|
+
* making that dense grid. Values come from the tree (leaf voxels active or not, tiles, the background), 0 outside the
|
|
28
|
+
* index bbox and outside `[0, resolution)` (the P1.1 contract: for a `vdbBuildFromDense` image of its array, the
|
|
29
|
+
* same array). Works on every scalar grid type (Fp values as decoded by the readers).
|
|
30
|
+
*
|
|
31
|
+
* @param image The grid image (little-endian u32 words, `GridData` at word 0).
|
|
32
|
+
* @param options The dense grid's resolution.
|
|
33
|
+
* @throws VDBToolsError `VDB_BAD_OPTION` for a bad resolution, a bbox outside it, or more occupied bricks than its
|
|
34
|
+
* 10-bit atlas coordinates hold.
|
|
35
|
+
*/
|
|
36
|
+
export function vdbBrickAtlas(image, options = {}) {
|
|
37
|
+
const { min, max } = indexBBox(image);
|
|
38
|
+
const resolution = options.resolution;
|
|
39
|
+
let layout;
|
|
40
|
+
try {
|
|
41
|
+
layout = brickMajorantLayout(min, max, { align: "pathtracer", ...(resolution !== undefined ? { resolution } : {}) });
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
if (e instanceof VDBToolsError)
|
|
45
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `vdbBrickAtlas: ${e.message.replace(/^.*?vdbBrickMajorant: /, "")}`);
|
|
46
|
+
throw e;
|
|
47
|
+
}
|
|
48
|
+
const n = layout.resolution;
|
|
49
|
+
const cells = layout.dims;
|
|
50
|
+
const total = cells[0] * cells[1] * cells[2];
|
|
51
|
+
// A brick is occupied when its majorant (over the 9³ voxels its lookups read) is above 0: its `brickMajorants(..) > 0`.
|
|
52
|
+
const mj = vdbBrickMajorant(image, { align: "pathtracer", resolution: n }).data;
|
|
53
|
+
let occupied = 0;
|
|
54
|
+
for (let i = 0; i < total; i++)
|
|
55
|
+
if (mj[i] > 0)
|
|
56
|
+
occupied++;
|
|
57
|
+
const ax = Math.max(1, Math.ceil(Math.cbrt(occupied)));
|
|
58
|
+
const ay = ax;
|
|
59
|
+
const az = Math.max(1, Math.ceil(occupied / (ax * ay)));
|
|
60
|
+
if (ax > 1023 || az > 1023)
|
|
61
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `vdbBrickAtlas: ${occupied} bricks do not fit the atlas's 10-bit brick coordinates.`);
|
|
62
|
+
const dims = [ax * CELL, ay * CELL, az * CELL];
|
|
63
|
+
const data = new Float32Array(dims[0] * dims[1] * dims[2]);
|
|
64
|
+
const indirection = new Uint32Array(total).fill(EMPTY);
|
|
65
|
+
/** Atlas texel origin of each cell's brick (-1: empty). */
|
|
66
|
+
const slot = new Int32Array(total).fill(-1);
|
|
67
|
+
let k = 0;
|
|
68
|
+
for (let i = 0; i < total; i++) {
|
|
69
|
+
if (!(mj[i] > 0))
|
|
70
|
+
continue;
|
|
71
|
+
const bx = k % ax;
|
|
72
|
+
const by = Math.floor(k / ax) % ay;
|
|
73
|
+
const bz = Math.floor(k / (ax * ay));
|
|
74
|
+
k++;
|
|
75
|
+
indirection[i] = (bx | (by << 10) | (bz << 20)) >>> 0;
|
|
76
|
+
slot[i] = bx * CELL + dims[0] * (by * CELL + dims[1] * (bz * CELL));
|
|
77
|
+
}
|
|
78
|
+
// Where the field comes from the tree: the bbox inside [0, n).
|
|
79
|
+
const domLo = [Math.max(min[0], 0), Math.max(min[1], 0), Math.max(min[2], 0)];
|
|
80
|
+
const domHi = [Math.min(max[0], n[0] - 1), Math.min(max[1], n[1] - 1), Math.min(max[2], n[2] - 1)];
|
|
81
|
+
if (domLo.some((v, a) => v > domHi[a]))
|
|
82
|
+
return { resolution: [...n], cells: [...cells], bricks: [ax, ay, az], dims, data, indirection, occupied };
|
|
83
|
+
/** Calls `fill(texel, x, y, z)` for every voxel of the box [a, b] (inclusive, clipped to the domain) in every occupied brick that holds it. */
|
|
84
|
+
const each = (a, b, fill) => {
|
|
85
|
+
const lo = [0, 1, 2].map((q) => Math.max(a[q], domLo[q]));
|
|
86
|
+
const hi = [0, 1, 2].map((q) => Math.min(b[q], domHi[q]));
|
|
87
|
+
if (lo.some((v, q) => v > hi[q]))
|
|
88
|
+
return;
|
|
89
|
+
// Brick c holds [8c - 1, 8c + 7]: the bricks meeting [lo, hi] are ceil((lo - 7) / 8) .. floor((hi + 1) / 8).
|
|
90
|
+
const c0 = lo.map((v, q) => Math.max(0, Math.ceil((v - 7) / BRICK)));
|
|
91
|
+
const c1 = hi.map((v, q) => Math.min(cells[q] - 1, Math.floor((v + 1) / BRICK)));
|
|
92
|
+
for (let cz = c0[2]; cz <= c1[2]; cz++)
|
|
93
|
+
for (let cy = c0[1]; cy <= c1[1]; cy++)
|
|
94
|
+
for (let cx = c0[0]; cx <= c1[0]; cx++) {
|
|
95
|
+
const base = slot[cx + cells[0] * (cy + cells[1] * cz)];
|
|
96
|
+
if (base < 0)
|
|
97
|
+
continue;
|
|
98
|
+
const o = [cx * BRICK - 1, cy * BRICK - 1, cz * BRICK - 1];
|
|
99
|
+
const x0 = Math.max(lo[0], o[0]), x1 = Math.min(hi[0], o[0] + BRICK);
|
|
100
|
+
const y0 = Math.max(lo[1], o[1]), y1 = Math.min(hi[1], o[1] + BRICK);
|
|
101
|
+
const z0 = Math.max(lo[2], o[2]), z1 = Math.min(hi[2], o[2] + BRICK);
|
|
102
|
+
for (let z = z0; z <= z1; z++)
|
|
103
|
+
for (let y = y0; y <= y1; y++) {
|
|
104
|
+
const row = base + (x0 - o[0]) + dims[0] * (y - o[1] + dims[1] * (z - o[2]));
|
|
105
|
+
for (let x = x0; x <= x1; x++)
|
|
106
|
+
fill(row + (x - x0), x, y, z);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
// Space under no root tile reads the background: fill it first (a no-op for background 0), then the tree overwrites.
|
|
111
|
+
const regions = [];
|
|
112
|
+
const { background } = forEachTreeRegion(image, (r) => {
|
|
113
|
+
regions.push({ lo: r.origin, hi: [r.origin[0] + r.dim - 1, r.origin[1] + r.dim - 1, r.origin[2] + r.dim - 1], level: r.level, leaf: r.leaf, value: r.value });
|
|
114
|
+
});
|
|
115
|
+
if (background !== 0)
|
|
116
|
+
each(domLo, domHi, (t) => (data[t] = background));
|
|
117
|
+
for (const r of regions) {
|
|
118
|
+
if (r.level > 0) {
|
|
119
|
+
const v = r.value;
|
|
120
|
+
each(r.lo, r.hi, (t) => (data[t] = v));
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const { values } = leafVoxels(image, r.leaf);
|
|
124
|
+
const [ox, oy, oz] = r.lo;
|
|
125
|
+
each(r.lo, r.hi, (t, x, y, z) => (data[t] = values[((x - ox) << 6) | ((y - oy) << 3) | (z - oz)]));
|
|
126
|
+
}
|
|
127
|
+
return { resolution: [...n], cells: [...cells], bricks: [ax, ay, az], dims, data, indirection, occupied };
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=brick-atlas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brick-atlas.js","sourceRoot":"","sources":["../../../src/tools/cpu/brick-atlas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,UAAU,EAAa,MAAM,YAAY,CAAC;AAEjF,0CAA0C;AAC1C,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,wGAAwG;AACxG,MAAM,IAAI,GAAG,KAAK,GAAG,CAAC,CAAC;AACvB,+DAA+D;AAC/D,MAAM,KAAK,GAAG,UAAU,CAAC;AA0BzB;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,KAAkB,EAAE,UAAgC,EAAE;IAClF,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC,KAAK,C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GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC5G,CAAC","sourcesContent":["/**\n * P1.12, the optional \"B\" path of the pathtracer integration: a NanoVDB grid to pmndrs/pathtracer's V3.2 sparse\n * brick atlas + indirection (`volumes.gridLayout: 'atlas'`, its `buildBrickAtlas(resolution, dense)` in\n * `packages/pathtracer/src/volume/volume.ts`, MIT, read at main `06488fa`), straight from the tree's leaves and tiles,\n * without a dense copy of the grid. Its kernels then read the atlas as they do today; the `.nvdb` is only the\n * delivery format.\n *\n * The layout is its own (bit for bit on the same field): bricks of 8³ cells, brick `c` holding the voxels\n * `[8c - 1, 8c + 7]` (its trilinear support, `ATLAS_CELL = 9` texels per side), a brick occupied when its majorant is\n * above 0 (`vdbBrickMajorant(image, { align: 'pathtracer' })`, equal to its `brickMajorants`, P1.2), occupied bricks\n * packed in x-fastest cell order into a near-cubic block of `ceil(cbrt(occupied))²` bricks per layer, and an `r32uint`\n * indirection `bx | by << 10 | bz << 20` (`0xffffffff` for an empty brick). The field is the P1.1 contract's: the grid\n * inside its index bbox, 0 outside it and outside `[0, resolution)`.\n */\nimport { VDBToolsError } from \"../errors.js\";\nimport type { VDBVec3 } from \"../vdb/types.js\";\nimport { brickMajorantLayout, vdbBrickMajorant } from \"./majorant.js\";\nimport { forEachTreeRegion, indexBBox, leafVoxels, type Vec3 } from \"./march.js\";\n\n/** Brick edge in voxels (its `BRICK`). */\nconst BRICK = 8;\n/** Atlas texels per brick side (its `ATLAS_CELL`: the brick plus a one-voxel apron on the low side). */\nconst CELL = BRICK + 1;\n/** Indirection value of an empty brick (its `ATLAS_EMPTY`). */\nconst EMPTY = 0xffffffff;\n\n/** pmndrs/pathtracer's V3.2 sparse brick atlas (its `BrickAtlas`), built by {@link vdbBrickAtlas}. */\nexport interface VDBBrickAtlas {\n /** The dense grid's voxel counts (`[0, resolution)` in index space). */\n resolution: VDBVec3;\n /** Bricks per axis over the grid: `floor((resolution + 8) / 8)` (its `brickDims`). */\n cells: VDBVec3;\n /** Atlas size in bricks. */\n bricks: VDBVec3;\n /** Atlas size in texels (`bricks * 9`). */\n dims: VDBVec3;\n /** The atlas texels, x fastest; voxels outside the grid (and empty texels) are 0. */\n data: Float32Array;\n /** One texel per brick of `cells`, x fastest: `0xffffffff` (empty) or `bx | by << 10 | bz << 20` (atlas brick). */\n indirection: Uint32Array;\n /** Occupied bricks. */\n occupied: number;\n}\n\n/** Options of {@link vdbBrickAtlas}. */\nexport interface VDBBrickAtlasOptions {\n /** The dense grid's voxel counts. Default `indexBBoxMax + 1` (the grid's bbox must lie in `[0, resolution - 1]`). */\n resolution?: VDBVec3;\n}\n\n/**\n * Builds pmndrs/pathtracer's V3.2 brick atlas and indirection (`volumes.gridLayout: 'atlas'`) from a NanoVDB grid image\n * (P1.12): the arrays its `buildBrickAtlas(resolution, dense)` gives for the dense grid of the same field, without\n * making that dense grid. Values come from the tree (leaf voxels active or not, tiles, the background), 0 outside the\n * index bbox and outside `[0, resolution)` (the P1.1 contract: for a `vdbBuildFromDense` image of its array, the\n * same array). Works on every scalar grid type (Fp values as decoded by the readers).\n *\n * @param image The grid image (little-endian u32 words, `GridData` at word 0).\n * @param options The dense grid's resolution.\n * @throws VDBToolsError `VDB_BAD_OPTION` for a bad resolution, a bbox outside it, or more occupied bricks than its\n * 10-bit atlas coordinates hold.\n */\nexport function vdbBrickAtlas(image: Uint32Array, options: VDBBrickAtlasOptions = {}): VDBBrickAtlas {\n const { min, max } = indexBBox(image);\n const resolution = options.resolution;\n let layout: ReturnType<typeof brickMajorantLayout>;\n try {\n layout = brickMajorantLayout(min, max, { align: \"pathtracer\", ...(resolution !== undefined ? { resolution } : {}) });\n } catch (e) {\n if (e instanceof VDBToolsError) throw new VDBToolsError(\"VDB_BAD_OPTION\", `vdbBrickAtlas: ${e.message.replace(/^.*?vdbBrickMajorant: /, \"\")}`);\n throw e;\n }\n const n = layout.resolution;\n const cells = layout.dims;\n const total = cells[0] * cells[1] * cells[2];\n // A brick is occupied when its majorant (over the 9³ voxels its lookups read) is above 0: its `brickMajorants(..) > 0`.\n const mj = vdbBrickMajorant(image, { align: \"pathtracer\", resolution: n }).data;\n let occupied = 0;\n for (let i = 0; i < total; i++) if (mj[i]! > 0) occupied++;\n const ax = Math.max(1, Math.ceil(Math.cbrt(occupied)));\n const ay = ax;\n const az = Math.max(1, Math.ceil(occupied / (ax * ay)));\n if (ax > 1023 || az > 1023) throw new VDBToolsError(\"VDB_BAD_OPTION\", `vdbBrickAtlas: ${occupied} bricks do not fit the atlas's 10-bit brick coordinates.`);\n const dims: Vec3 = [ax * CELL, ay * CELL, az * CELL];\n const data = new Float32Array(dims[0] * dims[1] * dims[2]);\n const indirection = new Uint32Array(total).fill(EMPTY);\n /** Atlas texel origin of each cell's brick (-1: empty). */\n const slot = new Int32Array(total).fill(-1);\n let k = 0;\n for (let i = 0; i < total; i++) {\n if (!(mj[i]! > 0)) continue;\n const bx = k % ax;\n const by = Math.floor(k / ax) % ay;\n const bz = Math.floor(k / (ax * ay));\n k++;\n indirection[i] = (bx | (by << 10) | (bz << 20)) >>> 0;\n slot[i] = bx * CELL + dims[0] * (by * CELL + dims[1] * (bz * CELL));\n }\n\n // Where the field comes from the tree: the bbox inside [0, n).\n const domLo: Vec3 = [Math.max(min[0], 0), Math.max(min[1], 0), Math.max(min[2], 0)];\n const domHi: Vec3 = [Math.min(max[0], n[0] - 1), Math.min(max[1], n[1] - 1), Math.min(max[2], n[2] - 1)];\n if (domLo.some((v, a) => v > domHi[a]!)) return { resolution: [...n], cells: [...cells], bricks: [ax, ay, az], dims, data, indirection, occupied };\n /** Calls `fill(texel, x, y, z)` for every voxel of the box [a, b] (inclusive, clipped to the domain) in every occupied brick that holds it. */\n const each = (a: Vec3, b: Vec3, fill: (texel: number, x: number, y: number, z: number) => void) => {\n const lo = [0, 1, 2].map((q) => Math.max(a[q]!, domLo[q]!));\n const hi = [0, 1, 2].map((q) => Math.min(b[q]!, domHi[q]!));\n if (lo.some((v, q) => v > hi[q]!)) return;\n // Brick c holds [8c - 1, 8c + 7]: the bricks meeting [lo, hi] are ceil((lo - 7) / 8) .. floor((hi + 1) / 8).\n const c0 = lo.map((v, q) => Math.max(0, Math.ceil((v - 7) / BRICK)));\n const c1 = hi.map((v, q) => Math.min(cells[q]! - 1, Math.floor((v + 1) / BRICK)));\n for (let cz = c0[2]!; cz <= c1[2]!; cz++)\n for (let cy = c0[1]!; cy <= c1[1]!; cy++)\n for (let cx = c0[0]!; cx <= c1[0]!; cx++) {\n const base = slot[cx + cells[0] * (cy + cells[1] * cz)]!;\n if (base < 0) continue;\n const o = [cx * BRICK - 1, cy * BRICK - 1, cz * BRICK - 1];\n const x0 = Math.max(lo[0]!, o[0]!), x1 = Math.min(hi[0]!, o[0]! + BRICK);\n const y0 = Math.max(lo[1]!, o[1]!), y1 = Math.min(hi[1]!, o[1]! + BRICK);\n const z0 = Math.max(lo[2]!, o[2]!), z1 = Math.min(hi[2]!, o[2]! + BRICK);\n for (let z = z0; z <= z1; z++)\n for (let y = y0; y <= y1; y++) {\n const row = base + (x0 - o[0]!) + dims[0] * (y - o[1]! + dims[1] * (z - o[2]!));\n for (let x = x0; x <= x1; x++) fill(row + (x - x0), x, y, z);\n }\n }\n };\n // Space under no root tile reads the background: fill it first (a no-op for background 0), then the tree overwrites.\n const regions: { lo: Vec3; hi: Vec3; level: number; leaf: number; value: number }[] = [];\n const { background } = forEachTreeRegion(image, (r) => {\n regions.push({ lo: r.origin, hi: [r.origin[0] + r.dim - 1, r.origin[1] + r.dim - 1, r.origin[2] + r.dim - 1], level: r.level, leaf: r.leaf, value: r.value });\n });\n if (background !== 0) each(domLo, domHi, (t) => (data[t] = background));\n for (const r of regions) {\n if (r.level > 0) {\n const v = r.value;\n each(r.lo, r.hi, (t) => (data[t] = v));\n continue;\n }\n const { values } = leafVoxels(image, r.leaf);\n const [ox, oy, oz] = r.lo;\n each(r.lo, r.hi, (t, x, y, z) => (data[t] = values[((x - ox) << 6) | ((y - oy) << 3) | (z - oz)]!));\n }\n return { resolution: [...n], cells: [...cells], bricks: [ax, ay, az], dims, data, indirection, occupied };\n}\n"]}
|
|
@@ -12,20 +12,27 @@ export declare function bboxSize(bbox: IndexBBox): [number, number, number];
|
|
|
12
12
|
* `maxDim` (a literal per-axis clamp, not a proportional downscale; v1).
|
|
13
13
|
*/
|
|
14
14
|
export declare function atlasDims(bbox: IndexBBox, maxDim: number): [number, number, number];
|
|
15
|
-
/** The root node's stored min/max statistics (f32), meaningful when the grid has stats. */
|
|
15
|
+
/** The root node's stored min/max statistics (f32; binary16 decoded for Half), meaningful when the grid has stats. */
|
|
16
16
|
export declare function rootStats(gridWords: Uint32Array): {
|
|
17
17
|
min: number;
|
|
18
18
|
max: number;
|
|
19
19
|
};
|
|
20
|
+
/** Options of {@link vdbGridStatsCpu}. */
|
|
20
21
|
export interface VDBGridStatsCpuOptions {
|
|
21
22
|
/** Histogram bins (default 256). */
|
|
22
23
|
histogramBins?: number;
|
|
23
24
|
}
|
|
25
|
+
/** Result of {@link vdbGridStatsCpu}, the twin of the GPU `gridStats` result. */
|
|
24
26
|
export interface VDBGridStatsCpuResult {
|
|
27
|
+
/** Smallest active value. */
|
|
25
28
|
min: number;
|
|
29
|
+
/** Largest active value. */
|
|
26
30
|
max: number;
|
|
31
|
+
/** Mean of the active values. */
|
|
27
32
|
mean: number;
|
|
33
|
+
/** Counts of active voxels per bin over {@link range}. */
|
|
28
34
|
histogram: Uint32Array;
|
|
35
|
+
/** Number of active voxels in the index bbox. */
|
|
29
36
|
activeVoxelCount: number;
|
|
30
37
|
/** The path the GPU takes for this grid: `true` when the root min is ≥ 0 (atomics). */
|
|
31
38
|
usedAtomicFastPath: boolean;
|
|
@@ -46,9 +53,14 @@ export interface VDBGridStatsCpuResult {
|
|
|
46
53
|
* < 0) reduces f32 values in f64 on the CPU. The f32 normalization divides, so
|
|
47
54
|
* a GPU with an inexact division may put a voxel in the neighbouring bin or
|
|
48
55
|
* shift the mean by a fixed-point step.
|
|
56
|
+
*
|
|
57
|
+
* @param gridWords The grid image (little-endian u32 words, `GridData` at word 0).
|
|
58
|
+
* @param options Histogram bin count.
|
|
49
59
|
*/
|
|
50
60
|
export declare function vdbGridStatsCpu(gridWords: Uint32Array, options?: VDBGridStatsCpuOptions): VDBGridStatsCpuResult;
|
|
61
|
+
/** How an atlas samples the grid: the nearest voxel or trilinear interpolation. */
|
|
51
62
|
export type VDBAtlasFilter = "nearest" | "trilinear";
|
|
63
|
+
/** Texel format of a decoded atlas: 8-bit unsigned or 32-bit float. */
|
|
52
64
|
export type VDBAtlasFormat = "uint8" | "float32";
|
|
53
65
|
export interface AtlasFromRawOptions {
|
|
54
66
|
format: VDBAtlasFormat;
|
|
@@ -64,8 +76,11 @@ export interface AtlasFromRawOptions {
|
|
|
64
76
|
* normalizing); `float32` maps to `[0, 1]` or returns `raw` itself.
|
|
65
77
|
*/
|
|
66
78
|
export declare function atlasFromRaw(raw: Float32Array, o: AtlasFromRawOptions): Uint8Array | Float32Array;
|
|
79
|
+
/** Options of {@link vdbDecodeToAtlasCpu}. */
|
|
67
80
|
export interface VDBDecodeToAtlasCpuOptions {
|
|
81
|
+
/** Longest atlas side in texels (default 256). */
|
|
68
82
|
maxDim?: number;
|
|
83
|
+
/** Sampling filter (default `'trilinear'`). */
|
|
69
84
|
filter?: VDBAtlasFilter;
|
|
70
85
|
}
|
|
71
86
|
/**
|
|
@@ -75,14 +90,18 @@ export interface VDBDecodeToAtlasCpuOptions {
|
|
|
75
90
|
* centres at full resolution, K2.6) with `vdbReadValue(floor(p + 0.5))` (`'nearest'`) or
|
|
76
91
|
* the vendored trilinear (`'trilinear'`, the default). Feed the result to
|
|
77
92
|
* {@link atlasFromRaw} for the formatted atlas.
|
|
93
|
+
*
|
|
94
|
+
* @param gridWords The grid image (little-endian u32 words, `GridData` at word 0).
|
|
95
|
+
* @param options Longest atlas side and filter.
|
|
78
96
|
*/
|
|
79
97
|
export declare function vdbDecodeToAtlasCpu(gridWords: Uint32Array, options?: VDBDecodeToAtlasCpuOptions): {
|
|
80
98
|
raw: Float32Array;
|
|
81
99
|
dims: [number, number, number];
|
|
82
100
|
};
|
|
83
101
|
/**
|
|
84
|
-
* Returns a copy of a Float grid image with `fn` applied to every leaf
|
|
85
|
-
* value inside the index bbox (active or inactive), rounded to f32
|
|
102
|
+
* Returns a copy of a Float or Half grid image with `fn` applied to every leaf
|
|
103
|
+
* voxel value inside the index bbox (active or inactive), rounded to f32 (and,
|
|
104
|
+
* in a Half grid, then to the nearest binary16 as `vdbFloatToHalf` does; K7.H1). Tile,
|
|
86
105
|
* background and out-of-bbox leaf values are left alone, exactly as v1's GPU
|
|
87
106
|
* `valueTransform` did (it visited the dense bbox and rewrote level-0
|
|
88
107
|
* addresses only).
|
|
@@ -92,6 +111,6 @@ export declare function vdbDecodeToAtlasCpu(gridWords: Uint32Array, options?: VD
|
|
|
92
111
|
* (`gridStats`' range, `vdbNodeMax` skipping) see stale bounds; rebuild the
|
|
93
112
|
* grid (e.g. `vdbBuildFromDense`) when they matter.
|
|
94
113
|
*
|
|
95
|
-
* Float
|
|
114
|
+
* Float and Half only: quantized (Fp*) leaves would need re-encoding.
|
|
96
115
|
*/
|
|
97
116
|
export declare function transformLeafValues(gridWords: Uint32Array, fn: (value: number) => number): Uint32Array;
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* so GPU parity compares with a tolerance and reports the bit-exact count.
|
|
15
15
|
*/
|
|
16
16
|
import { VDBToolsError } from "../errors.js";
|
|
17
|
-
import {
|
|
17
|
+
import { vdbFloatToHalf, vdbHalfToFloat } from "../nanovdb/half.js";
|
|
18
|
+
import { indexBBox, isActive, vdbReadValueF32Cpu, treeNodes } from "./march.js";
|
|
18
19
|
import { defineNumber, gridTypeConstantsFor, gridTypeConstantsForId, gridTypeIds } from "./stride-tables.js";
|
|
19
20
|
const f = Math.fround;
|
|
20
21
|
const GRID_OFF_GRID_TYPE = defineNumber("PNANOVDB_GRID_OFF_GRID_TYPE");
|
|
@@ -34,10 +35,15 @@ export function atlasDims(bbox, maxDim) {
|
|
|
34
35
|
const [sx, sy, sz] = bboxSize(bbox);
|
|
35
36
|
return [Math.min(sx, maxDim), Math.min(sy, maxDim), Math.min(sz, maxDim)];
|
|
36
37
|
}
|
|
37
|
-
/** The root node's stored min/max statistics (f32), meaningful when the grid has stats. */
|
|
38
|
+
/** The root node's stored min/max statistics (f32; binary16 decoded for Half), meaningful when the grid has stats. */
|
|
38
39
|
export function rootStats(gridWords) {
|
|
39
|
-
const
|
|
40
|
+
const gridType = gridWords[GRID_OFF_GRID_TYPE >>> 2];
|
|
41
|
+
const gt = gridTypeConstantsForId(gridType);
|
|
40
42
|
const root = GRID_SIZE + gridWords[(GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT) >>> 2];
|
|
43
|
+
if (gridType === gridTypeIds.HALF) {
|
|
44
|
+
const half = (address) => vdbHalfToFloat(gridWords[address >>> 2] >>> ((address & 2) << 3));
|
|
45
|
+
return { min: half(root + gt.root_off_min), max: half(root + gt.root_off_max) };
|
|
46
|
+
}
|
|
41
47
|
const f32 = new Float32Array(gridWords.buffer, gridWords.byteOffset, gridWords.length);
|
|
42
48
|
return { min: f32[(root + gt.root_off_min) >>> 2], max: f32[(root + gt.root_off_max) >>> 2] };
|
|
43
49
|
}
|
|
@@ -52,6 +58,9 @@ export function rootStats(gridWords) {
|
|
|
52
58
|
* < 0) reduces f32 values in f64 on the CPU. The f32 normalization divides, so
|
|
53
59
|
* a GPU with an inexact division may put a voxel in the neighbouring bin or
|
|
54
60
|
* shift the mean by a fixed-point step.
|
|
61
|
+
*
|
|
62
|
+
* @param gridWords The grid image (little-endian u32 words, `GridData` at word 0).
|
|
63
|
+
* @param options Histogram bin count.
|
|
55
64
|
*/
|
|
56
65
|
export function vdbGridStatsCpu(gridWords, options = {}) {
|
|
57
66
|
const bins = options.histogramBins ?? 256;
|
|
@@ -75,7 +84,7 @@ export function vdbGridStatsCpu(gridWords, options = {}) {
|
|
|
75
84
|
ijk[2] = z;
|
|
76
85
|
if (!isActive(gridWords, ijk))
|
|
77
86
|
continue;
|
|
78
|
-
const v =
|
|
87
|
+
const v = vdbReadValueF32Cpu(gridWords, ijk);
|
|
79
88
|
count++;
|
|
80
89
|
if (v < min)
|
|
81
90
|
min = v;
|
|
@@ -138,6 +147,9 @@ export function atlasFromRaw(raw, o) {
|
|
|
138
147
|
* centres at full resolution, K2.6) with `vdbReadValue(floor(p + 0.5))` (`'nearest'`) or
|
|
139
148
|
* the vendored trilinear (`'trilinear'`, the default). Feed the result to
|
|
140
149
|
* {@link atlasFromRaw} for the formatted atlas.
|
|
150
|
+
*
|
|
151
|
+
* @param gridWords The grid image (little-endian u32 words, `GridData` at word 0).
|
|
152
|
+
* @param options Longest atlas side and filter.
|
|
141
153
|
*/
|
|
142
154
|
export function vdbDecodeToAtlasCpu(gridWords, options = {}) {
|
|
143
155
|
const bbox = indexBBox(gridWords);
|
|
@@ -153,7 +165,7 @@ export function vdbDecodeToAtlasCpu(gridWords, options = {}) {
|
|
|
153
165
|
const g = [x, y, z];
|
|
154
166
|
for (let a = 0; a < 3; a++)
|
|
155
167
|
pos[a] = f(bbox.min[a] + f(f(f(f(g[a] + 0.5) * size[a]) / dims[a]) - 0.5));
|
|
156
|
-
raw[i++] = trilinear ? trilinearF32(gridWords, pos) :
|
|
168
|
+
raw[i++] = trilinear ? trilinearF32(gridWords, pos) : vdbReadValueF32Cpu(gridWords, [Math.floor(f(pos[0] + 0.5)), Math.floor(f(pos[1] + 0.5)), Math.floor(f(pos[2] + 0.5))]);
|
|
157
169
|
}
|
|
158
170
|
}
|
|
159
171
|
}
|
|
@@ -163,7 +175,7 @@ export function vdbDecodeToAtlasCpu(gridWords, options = {}) {
|
|
|
163
175
|
function trilinearF32(gridWords, xyz) {
|
|
164
176
|
const b = [Math.floor(xyz[0]), Math.floor(xyz[1]), Math.floor(xyz[2])];
|
|
165
177
|
const u = [f(xyz[0] - b[0]), f(xyz[1] - b[1]), f(xyz[2] - b[2])];
|
|
166
|
-
const tap = (dx, dy, dz) =>
|
|
178
|
+
const tap = (dx, dy, dz) => vdbReadValueF32Cpu(gridWords, [b[0] + dx, b[1] + dy, b[2] + dz]);
|
|
167
179
|
const mix = (a, c, t) => f(a + f(t * f(c - a)));
|
|
168
180
|
const x00 = mix(tap(0, 0, 0), tap(1, 0, 0), u[0]);
|
|
169
181
|
const x10 = mix(tap(0, 1, 0), tap(1, 1, 0), u[0]);
|
|
@@ -174,8 +186,9 @@ function trilinearF32(gridWords, xyz) {
|
|
|
174
186
|
// ---------------------------------------------------------------------------
|
|
175
187
|
// Value transform
|
|
176
188
|
/**
|
|
177
|
-
* Returns a copy of a Float grid image with `fn` applied to every leaf
|
|
178
|
-
* value inside the index bbox (active or inactive), rounded to f32
|
|
189
|
+
* Returns a copy of a Float or Half grid image with `fn` applied to every leaf
|
|
190
|
+
* voxel value inside the index bbox (active or inactive), rounded to f32 (and,
|
|
191
|
+
* in a Half grid, then to the nearest binary16 as `vdbFloatToHalf` does; K7.H1). Tile,
|
|
179
192
|
* background and out-of-bbox leaf values are left alone, exactly as v1's GPU
|
|
180
193
|
* `valueTransform` did (it visited the dense bbox and rewrote level-0
|
|
181
194
|
* addresses only).
|
|
@@ -185,19 +198,21 @@ function trilinearF32(gridWords, xyz) {
|
|
|
185
198
|
* (`gridStats`' range, `vdbNodeMax` skipping) see stale bounds; rebuild the
|
|
186
199
|
* grid (e.g. `vdbBuildFromDense`) when they matter.
|
|
187
200
|
*
|
|
188
|
-
* Float
|
|
201
|
+
* Float and Half only: quantized (Fp*) leaves would need re-encoding.
|
|
189
202
|
*/
|
|
190
203
|
export function transformLeafValues(gridWords, fn) {
|
|
191
204
|
if (typeof fn !== "function")
|
|
192
205
|
throw new VDBToolsError("VDB_BAD_OPTION", "transformLeafValues: fn must be a function (value: number) => number");
|
|
193
206
|
const gridType = gridWords[GRID_OFF_GRID_TYPE >>> 2];
|
|
194
|
-
|
|
195
|
-
|
|
207
|
+
const half = gridType === gridTypeIds.HALF;
|
|
208
|
+
if (gridType !== gridTypeIds.FLOAT && !half) {
|
|
209
|
+
throw new VDBToolsError("VDB_UNSUPPORTED_GRID_TYPE", `transformLeafValues: grid type ${gridType} is not Float (${gridTypeIds.FLOAT}) or Half (${gridTypeIds.HALF}); quantized leaves would need re-encoding. ` +
|
|
196
210
|
"Transform the Float source and quantize() afterwards.");
|
|
197
211
|
}
|
|
198
212
|
const out = gridWords.slice();
|
|
199
213
|
const outF32 = new Float32Array(out.buffer, out.byteOffset, out.length);
|
|
200
|
-
const
|
|
214
|
+
const outU16 = new Uint16Array(out.buffer, out.byteOffset, out.length * 2);
|
|
215
|
+
const table = gridTypeConstantsFor(half ? "HALF" : "FLOAT").leaf_off_table;
|
|
201
216
|
const { min, max } = indexBBox(gridWords);
|
|
202
217
|
for (const node of treeNodes(gridWords)) {
|
|
203
218
|
if (node.level !== 0)
|
|
@@ -209,8 +224,14 @@ export function transformLeafValues(gridWords, fn) {
|
|
|
209
224
|
const z = oz + (n & 7);
|
|
210
225
|
if (x < min[0] || y < min[1] || z < min[2] || x > max[0] || y > max[1] || z > max[2])
|
|
211
226
|
continue;
|
|
212
|
-
|
|
213
|
-
|
|
227
|
+
if (half) {
|
|
228
|
+
const at = (node.address + table + 2 * n) >>> 1;
|
|
229
|
+
outU16[at] = vdbFloatToHalf(f(fn(vdbHalfToFloat(outU16[at]))));
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
const word = (node.address + table + 4 * n) >>> 2;
|
|
233
|
+
outF32[word] = f(fn(outF32[word]));
|
|
234
|
+
}
|
|
214
235
|
}
|
|
215
236
|
}
|
|
216
237
|
return out;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compute.js","sourceRoot":"","sources":["../../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ClD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAE,CAAC,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * CPU twins (D11) of the core compute tools (K2.3, `core/compute/`):\n * `vdbGridStatsCpu` (twin of `gridStats`), `vdbDecodeToAtlasCpu` (twin of\n * `decodeToAtlas`) and `transformLeafValues`, the CPU value transform that\n * `vdbApplyValueTransform` writes back with `pool.replace` (it is also the twin of\n * v1's GPU `valueTransform`, which the pool's read-only binding retired).\n *\n * The shared pure pieces live here so the core and its twins cannot drift:\n * `atlasDims` (output resolution), `atlasFromRaw` (normalize / quantize after\n * readback) and `rootStats` (the range both tools use).\n *\n * Float arithmetic: each WGSL f32 operation is rounded with `Math.fround` in\n * the WGSL's order. WGSL allows a 2.5 ULP division and fused multiply-adds,\n * so GPU parity compares with a tolerance and reports the bit-exact count.\n */\nimport { VDBToolsError } from \"../errors.js\";\nimport { indexBBox, isActive, vdbReadValueF32, treeNodes, type Vec3 } from \"./march.js\";\nimport { defineNumber, gridTypeConstantsFor, gridTypeConstantsForId, gridTypeIds } from \"./stride-tables.js\";\n\nconst f = Math.fround;\n\nconst GRID_OFF_GRID_TYPE = defineNumber(\"PNANOVDB_GRID_OFF_GRID_TYPE\");\nconst GRID_SIZE = defineNumber(\"PNANOVDB_GRID_SIZE\");\nconst TREE_OFF_NODE_OFFSET_ROOT = defineNumber(\"PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT\");\n\n/** Fixed-point scale of the GPU fast path's 64-bit sum (2^20). */\nexport const GRID_STATS_SUM_SCALE = 1048576;\n\n/** Index bbox, inclusive on both ends. */\nexport interface IndexBBox {\n min: readonly [number, number, number];\n max: readonly [number, number, number];\n}\n\n/** Per-axis voxel count of an inclusive-max index bbox (`max - min + 1`). */\nexport function bboxSize(bbox: IndexBBox): [number, number, number] {\n return [bbox.max[0] - bbox.min[0] + 1, bbox.max[1] - bbox.min[1] + 1, bbox.max[2] - bbox.min[2] + 1];\n}\n\n/**\n * `decodeToAtlas` output resolution: each axis of the index bbox clamped to\n * `maxDim` (a literal per-axis clamp, not a proportional downscale; v1).\n */\nexport function atlasDims(bbox: IndexBBox, maxDim: number): [number, number, number] {\n const [sx, sy, sz] = bboxSize(bbox);\n return [Math.min(sx, maxDim), Math.min(sy, maxDim), Math.min(sz, maxDim)];\n}\n\n/** The root node's stored min/max statistics (f32), meaningful when the grid has stats. */\nexport function rootStats(gridWords: Uint32Array): { min: number; max: number } {\n const gt = gridTypeConstantsForId(gridWords[GRID_OFF_GRID_TYPE >>> 2]!);\n const root = GRID_SIZE + gridWords[(GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT) >>> 2]!;\n const f32 = new Float32Array(gridWords.buffer, gridWords.byteOffset, gridWords.length);\n return { min: f32[(root + gt.root_off_min) >>> 2]!, max: f32[(root + gt.root_off_max) >>> 2]! };\n}\n\n// ---------------------------------------------------------------------------\n// gridStats\n\nexport interface VDBGridStatsCpuOptions {\n /** Histogram bins (default 256). */\n histogramBins?: number;\n}\n\nexport interface VDBGridStatsCpuResult {\n min: number;\n max: number;\n mean: number;\n histogram: Uint32Array;\n activeVoxelCount: number;\n /** The path the GPU takes for this grid: `true` when the root min is ≥ 0 (atomics). */\n usedAtomicFastPath: boolean;\n /** The histogram range: the root min/max statistics. */\n range: { min: number; max: number };\n}\n\n/**\n * Twin of `gridStats`: min, max, mean and a histogram over the ACTIVE voxels of\n * the dense index bbox, read as the GPU reads them (`vdbIsActive`,\n * `vdbReadValue`). The histogram spans the root statistics `[rootMin,\n * rootMax]`.\n *\n * Both GPU paths are reproduced: the atomics path (root min ≥ 0) normalizes in\n * f32 and sums `u32(norm * 2^20)` in a 64-bit integer; the dump path (root min\n * < 0) reduces f32 values in f64 on the CPU. The f32 normalization divides, so\n * a GPU with an inexact division may put a voxel in the neighbouring bin or\n * shift the mean by a fixed-point step.\n */\nexport function vdbGridStatsCpu(gridWords: Uint32Array, options: VDBGridStatsCpuOptions = {}): VDBGridStatsCpuResult {\n const bins = options.histogramBins ?? 256;\n const range = rootStats(gridWords);\n const fast = range.min >= 0;\n const { min: lo, max: hi } = indexBBox(gridWords);\n const histogram = new Uint32Array(bins);\n let min = Infinity;\n let max = -Infinity;\n let count = 0;\n let sumFixed = 0n;\n let sum = 0;\n const spanF = f(Math.max(f(range.max - range.min), f(1e-20)));\n const spanD = Math.max(range.max - range.min, 1e-20);\n const ijk: Vec3 = [0, 0, 0];\n for (let z = lo[2]; z <= hi[2]; z++) {\n for (let y = lo[1]; y <= hi[1]; y++) {\n for (let x = lo[0]; x <= hi[0]; x++) {\n ijk[0] = x;\n ijk[1] = y;\n ijk[2] = z;\n if (!isActive(gridWords, ijk)) continue;\n const v = vdbReadValueF32(gridWords, ijk);\n count++;\n if (v < min) min = v;\n if (v > max) max = v;\n let norm: number;\n if (fast) {\n norm = Math.min(Math.max(f(f(v - range.min) / spanF), 0), 1);\n sumFixed += BigInt(Math.trunc(f(norm * GRID_STATS_SUM_SCALE)));\n histogram[Math.min(Math.trunc(f(norm * bins)), bins - 1)]!++;\n } else {\n sum += v;\n norm = Math.min(Math.max((v - range.min) / spanD, 0), 1);\n histogram[Math.min(Math.floor(norm * bins), bins - 1)]!++;\n }\n }\n }\n }\n if (count === 0) return { min: 0, max: 0, mean: 0, histogram, activeVoxelCount: 0, usedAtomicFastPath: fast, range };\n // The GPU's 64-bit sum wraps like a u64.\n sumFixed &= (1n << 64n) - 1n;\n const mean = fast\n ? range.min + (Number(sumFixed) / (GRID_STATS_SUM_SCALE * count)) * (range.max - range.min)\n : sum / count;\n return { min, max, mean, histogram, activeVoxelCount: count, usedAtomicFastPath: fast, range };\n}\n\n// ---------------------------------------------------------------------------\n// decodeToAtlas\n\nexport type VDBAtlasFilter = \"nearest\" | \"trilinear\";\nexport type VDBAtlasFormat = \"uint8\" | \"float32\";\n\nexport interface AtlasFromRawOptions {\n format: VDBAtlasFormat;\n normalize: boolean;\n range: { min: number; max: number };\n}\n\n/**\n * Post-readback step of `decodeToAtlas` (v1, in f64): `uint8` maps `[min,\n * max]` to `[0, 255]` with `Math.round` (or clamps the raw value when not\n * normalizing); `float32` maps to `[0, 1]` or returns `raw` itself.\n */\nexport function atlasFromRaw(raw: Float32Array, o: AtlasFromRawOptions): Uint8Array | Float32Array {\n const n = raw.length;\n const span = Math.max(o.range.max - o.range.min, 1e-20);\n if (o.format === \"uint8\") {\n const out = new Uint8Array(n);\n if (o.normalize) {\n for (let i = 0; i < n; i++) out[i] = Math.round(Math.min(Math.max((raw[i]! - o.range.min) / span, 0), 1) * 255);\n } else {\n for (let i = 0; i < n; i++) out[i] = Math.min(Math.max(Math.round(raw[i]!), 0), 255);\n }\n return out;\n }\n if (!o.normalize) return raw;\n const out = new Float32Array(n);\n for (let i = 0; i < n; i++) out[i] = Math.min(Math.max((raw[i]! - o.range.min) / span, 0), 1);\n return out;\n}\n\nexport interface VDBDecodeToAtlasCpuOptions {\n maxDim?: number;\n filter?: VDBAtlasFilter;\n}\n\n/**\n * Twin of the `decodeToAtlas` pass before normalization: one f32 per output\n * voxel (x fastest), sampled at index position `min + (i + 0.5) * size / dims\n * - 0.5` (cell `i` of `dims` over `[min, max]`, `size = max - min + 1`; voxel\n * centres at full resolution, K2.6) with `vdbReadValue(floor(p + 0.5))` (`'nearest'`) or\n * the vendored trilinear (`'trilinear'`, the default). Feed the result to\n * {@link atlasFromRaw} for the formatted atlas.\n */\nexport function vdbDecodeToAtlasCpu(\n gridWords: Uint32Array,\n options: VDBDecodeToAtlasCpuOptions = {},\n): { raw: Float32Array; dims: [number, number, number] } {\n const bbox = indexBBox(gridWords);\n const size = bboxSize(bbox);\n const dims = atlasDims(bbox, options.maxDim ?? 256);\n const trilinear = (options.filter ?? \"trilinear\") === \"trilinear\";\n const raw = new Float32Array(dims[0] * dims[1] * dims[2]);\n const pos: Vec3 = [0, 0, 0];\n let i = 0;\n for (let z = 0; z < dims[2]; z++) {\n for (let y = 0; y < dims[1]; y++) {\n for (let x = 0; x < dims[0]; x++) {\n const g: Vec3 = [x, y, z];\n for (let a = 0; a < 3; a++) pos[a] = f(bbox.min[a]! + f(f(f(f(g[a]! + 0.5) * size[a]!) / dims[a]!) - 0.5));\n raw[i++] = trilinear ? trilinearF32(gridWords, pos) : vdbReadValueF32(gridWords, [Math.floor(f(pos[0] + 0.5)), Math.floor(f(pos[1] + 0.5)), Math.floor(f(pos[2] + 0.5))]);\n }\n }\n }\n return { raw, dims };\n}\n\n/** The vendored `sample_trilinear_typed` in f32: `mix(a, b, t)` as `a + t * (b - a)`. */\nfunction trilinearF32(gridWords: Uint32Array, xyz: Vec3): number {\n const b: Vec3 = [Math.floor(xyz[0]), Math.floor(xyz[1]), Math.floor(xyz[2])];\n const u = [f(xyz[0] - b[0]), f(xyz[1] - b[1]), f(xyz[2] - b[2])];\n const tap = (dx: number, dy: number, dz: number) => vdbReadValueF32(gridWords, [b[0] + dx, b[1] + dy, b[2] + dz]);\n const mix = (a: number, c: number, t: number) => f(a + f(t * f(c - a)));\n const x00 = mix(tap(0, 0, 0), tap(1, 0, 0), u[0]!);\n const x10 = mix(tap(0, 1, 0), tap(1, 1, 0), u[0]!);\n const x01 = mix(tap(0, 0, 1), tap(1, 0, 1), u[0]!);\n const x11 = mix(tap(0, 1, 1), tap(1, 1, 1), u[0]!);\n return mix(mix(x00, x10, u[1]!), mix(x01, x11, u[1]!), u[2]!);\n}\n\n// ---------------------------------------------------------------------------\n// Value transform\n\n/**\n * Returns a copy of a Float grid image with `fn` applied to every leaf voxel\n * value inside the index bbox (active or inactive), rounded to f32. Tile,\n * background and out-of-bbox leaf values are left alone, exactly as v1's GPU\n * `valueTransform` did (it visited the dense bbox and rewrote level-0\n * addresses only).\n *\n * The image's statistics (root/node min, max, average, deviation) are NOT\n * recomputed: they describe the source values. Tools that trust them\n * (`gridStats`' range, `vdbNodeMax` skipping) see stale bounds; rebuild the\n * grid (e.g. `vdbBuildFromDense`) when they matter.\n *\n * Float (GridType 1) only: quantized leaves would need re-encoding.\n */\nexport function transformLeafValues(gridWords: Uint32Array, fn: (value: number) => number): Uint32Array {\n if (typeof fn !== \"function\") throw new VDBToolsError(\"VDB_BAD_OPTION\", \"transformLeafValues: fn must be a function (value: number) => number\");\n const gridType = gridWords[GRID_OFF_GRID_TYPE >>> 2];\n if (gridType !== gridTypeIds.FLOAT) {\n throw new VDBToolsError(\"VDB_UNSUPPORTED_GRID_TYPE\", \n `transformLeafValues: grid type ${gridType} is not Float (${gridTypeIds.FLOAT}); quantized leaves would need re-encoding. ` +\n \"Transform the Float source and quantize() afterwards.\",\n );\n }\n const out = gridWords.slice();\n const outF32 = new Float32Array(out.buffer, out.byteOffset, out.length);\n const table = gridTypeConstantsFor(\"FLOAT\").leaf_off_table;\n const { min, max } = indexBBox(gridWords);\n for (const node of treeNodes(gridWords)) {\n if (node.level !== 0) continue;\n const [ox, oy, oz] = node.origin;\n for (let n = 0; n < 512; n++) {\n const x = ox + (n >> 6);\n const y = oy + ((n >> 3) & 7);\n const z = oz + (n & 7);\n if (x < min[0] || y < min[1] || z < min[2] || x > max[0] || y > max[1] || z > max[2]) continue;\n const word = (node.address + table + 4 * n) >>> 2;\n outF32[word] = f(fn(outF32[word]!));\n }\n }\n return out;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"compute.js","sourceRoot":"","sources":["../../../src/tools/cpu/compute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE7G,MA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,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACvB,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;gBAAE,SAAS;YAC/F,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;gBAChD,MAAM,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAClE,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;gBAClD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAE,CAAC,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * CPU twins (D11) of the core compute tools (K2.3, `core/compute/`):\n * `vdbGridStatsCpu` (twin of `gridStats`), `vdbDecodeToAtlasCpu` (twin of\n * `decodeToAtlas`) and `transformLeafValues`, the CPU value transform that\n * `vdbApplyValueTransform` writes back with `pool.replace` (it is also the twin of\n * v1's GPU `valueTransform`, which the pool's read-only binding retired).\n *\n * The shared pure pieces live here so the core and its twins cannot drift:\n * `atlasDims` (output resolution), `atlasFromRaw` (normalize / quantize after\n * readback) and `rootStats` (the range both tools use).\n *\n * Float arithmetic: each WGSL f32 operation is rounded with `Math.fround` in\n * the WGSL's order. WGSL allows a 2.5 ULP division and fused multiply-adds,\n * so GPU parity compares with a tolerance and reports the bit-exact count.\n */\nimport { VDBToolsError } from \"../errors.js\";\nimport { vdbFloatToHalf, vdbHalfToFloat } from \"../nanovdb/half.js\";\nimport { indexBBox, isActive, vdbReadValueF32Cpu, treeNodes, type Vec3 } from \"./march.js\";\nimport { defineNumber, gridTypeConstantsFor, gridTypeConstantsForId, gridTypeIds } from \"./stride-tables.js\";\n\nconst f = Math.fround;\n\nconst GRID_OFF_GRID_TYPE = defineNumber(\"PNANOVDB_GRID_OFF_GRID_TYPE\");\nconst GRID_SIZE = defineNumber(\"PNANOVDB_GRID_SIZE\");\nconst TREE_OFF_NODE_OFFSET_ROOT = defineNumber(\"PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT\");\n\n/** Fixed-point scale of the GPU fast path's 64-bit sum (2^20). */\nexport const GRID_STATS_SUM_SCALE = 1048576;\n\n/** Index bbox, inclusive on both ends. */\nexport interface IndexBBox {\n min: readonly [number, number, number];\n max: readonly [number, number, number];\n}\n\n/** Per-axis voxel count of an inclusive-max index bbox (`max - min + 1`). */\nexport function bboxSize(bbox: IndexBBox): [number, number, number] {\n return [bbox.max[0] - bbox.min[0] + 1, bbox.max[1] - bbox.min[1] + 1, bbox.max[2] - bbox.min[2] + 1];\n}\n\n/**\n * `decodeToAtlas` output resolution: each axis of the index bbox clamped to\n * `maxDim` (a literal per-axis clamp, not a proportional downscale; v1).\n */\nexport function atlasDims(bbox: IndexBBox, maxDim: number): [number, number, number] {\n const [sx, sy, sz] = bboxSize(bbox);\n return [Math.min(sx, maxDim), Math.min(sy, maxDim), Math.min(sz, maxDim)];\n}\n\n/** The root node's stored min/max statistics (f32; binary16 decoded for Half), meaningful when the grid has stats. */\nexport function rootStats(gridWords: Uint32Array): { min: number; max: number } {\n const gridType = gridWords[GRID_OFF_GRID_TYPE >>> 2]!;\n const gt = gridTypeConstantsForId(gridType);\n const root = GRID_SIZE + gridWords[(GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT) >>> 2]!;\n if (gridType === gridTypeIds.HALF) {\n const half = (address: number) => vdbHalfToFloat(gridWords[address >>> 2]! >>> ((address & 2) << 3));\n return { min: half(root + gt.root_off_min), max: half(root + gt.root_off_max) };\n }\n const f32 = new Float32Array(gridWords.buffer, gridWords.byteOffset, gridWords.length);\n return { min: f32[(root + gt.root_off_min) >>> 2]!, max: f32[(root + gt.root_off_max) >>> 2]! };\n}\n\n// ---------------------------------------------------------------------------\n// gridStats\n\n/** Options of {@link vdbGridStatsCpu}. */\nexport interface VDBGridStatsCpuOptions {\n /** Histogram bins (default 256). */\n histogramBins?: number;\n}\n\n/** Result of {@link vdbGridStatsCpu}, the twin of the GPU `gridStats` result. */\nexport interface VDBGridStatsCpuResult {\n /** Smallest active value. */\n min: number;\n /** Largest active value. */\n max: number;\n /** Mean of the active values. */\n mean: number;\n /** Counts of active voxels per bin over {@link range}. */\n histogram: Uint32Array;\n /** Number of active voxels in the index bbox. */\n activeVoxelCount: number;\n /** The path the GPU takes for this grid: `true` when the root min is ≥ 0 (atomics). */\n usedAtomicFastPath: boolean;\n /** The histogram range: the root min/max statistics. */\n range: { min: number; max: number };\n}\n\n/**\n * Twin of `gridStats`: min, max, mean and a histogram over the ACTIVE voxels of\n * the dense index bbox, read as the GPU reads them (`vdbIsActive`,\n * `vdbReadValue`). The histogram spans the root statistics `[rootMin,\n * rootMax]`.\n *\n * Both GPU paths are reproduced: the atomics path (root min ≥ 0) normalizes in\n * f32 and sums `u32(norm * 2^20)` in a 64-bit integer; the dump path (root min\n * < 0) reduces f32 values in f64 on the CPU. The f32 normalization divides, so\n * a GPU with an inexact division may put a voxel in the neighbouring bin or\n * shift the mean by a fixed-point step.\n *\n * @param gridWords The grid image (little-endian u32 words, `GridData` at word 0).\n * @param options Histogram bin count.\n */\nexport function vdbGridStatsCpu(gridWords: Uint32Array, options: VDBGridStatsCpuOptions = {}): VDBGridStatsCpuResult {\n const bins = options.histogramBins ?? 256;\n const range = rootStats(gridWords);\n const fast = range.min >= 0;\n const { min: lo, max: hi } = indexBBox(gridWords);\n const histogram = new Uint32Array(bins);\n let min = Infinity;\n let max = -Infinity;\n let count = 0;\n let sumFixed = 0n;\n let sum = 0;\n const spanF = f(Math.max(f(range.max - range.min), f(1e-20)));\n const spanD = Math.max(range.max - range.min, 1e-20);\n const ijk: Vec3 = [0, 0, 0];\n for (let z = lo[2]; z <= hi[2]; z++) {\n for (let y = lo[1]; y <= hi[1]; y++) {\n for (let x = lo[0]; x <= hi[0]; x++) {\n ijk[0] = x;\n ijk[1] = y;\n ijk[2] = z;\n if (!isActive(gridWords, ijk)) continue;\n const v = vdbReadValueF32Cpu(gridWords, ijk);\n count++;\n if (v < min) min = v;\n if (v > max) max = v;\n let norm: number;\n if (fast) {\n norm = Math.min(Math.max(f(f(v - range.min) / spanF), 0), 1);\n sumFixed += BigInt(Math.trunc(f(norm * GRID_STATS_SUM_SCALE)));\n histogram[Math.min(Math.trunc(f(norm * bins)), bins - 1)]!++;\n } else {\n sum += v;\n norm = Math.min(Math.max((v - range.min) / spanD, 0), 1);\n histogram[Math.min(Math.floor(norm * bins), bins - 1)]!++;\n }\n }\n }\n }\n if (count === 0) return { min: 0, max: 0, mean: 0, histogram, activeVoxelCount: 0, usedAtomicFastPath: fast, range };\n // The GPU's 64-bit sum wraps like a u64.\n sumFixed &= (1n << 64n) - 1n;\n const mean = fast\n ? range.min + (Number(sumFixed) / (GRID_STATS_SUM_SCALE * count)) * (range.max - range.min)\n : sum / count;\n return { min, max, mean, histogram, activeVoxelCount: count, usedAtomicFastPath: fast, range };\n}\n\n// ---------------------------------------------------------------------------\n// decodeToAtlas\n\n/** How an atlas samples the grid: the nearest voxel or trilinear interpolation. */\nexport type VDBAtlasFilter = \"nearest\" | \"trilinear\";\n/** Texel format of a decoded atlas: 8-bit unsigned or 32-bit float. */\nexport type VDBAtlasFormat = \"uint8\" | \"float32\";\n\nexport interface AtlasFromRawOptions {\n format: VDBAtlasFormat;\n normalize: boolean;\n range: { min: number; max: number };\n}\n\n/**\n * Post-readback step of `decodeToAtlas` (v1, in f64): `uint8` maps `[min,\n * max]` to `[0, 255]` with `Math.round` (or clamps the raw value when not\n * normalizing); `float32` maps to `[0, 1]` or returns `raw` itself.\n */\nexport function atlasFromRaw(raw: Float32Array, o: AtlasFromRawOptions): Uint8Array | Float32Array {\n const n = raw.length;\n const span = Math.max(o.range.max - o.range.min, 1e-20);\n if (o.format === \"uint8\") {\n const out = new Uint8Array(n);\n if (o.normalize) {\n for (let i = 0; i < n; i++) out[i] = Math.round(Math.min(Math.max((raw[i]! - o.range.min) / span, 0), 1) * 255);\n } else {\n for (let i = 0; i < n; i++) out[i] = Math.min(Math.max(Math.round(raw[i]!), 0), 255);\n }\n return out;\n }\n if (!o.normalize) return raw;\n const out = new Float32Array(n);\n for (let i = 0; i < n; i++) out[i] = Math.min(Math.max((raw[i]! - o.range.min) / span, 0), 1);\n return out;\n}\n\n/** Options of {@link vdbDecodeToAtlasCpu}. */\nexport interface VDBDecodeToAtlasCpuOptions {\n /** Longest atlas side in texels (default 256). */\n maxDim?: number;\n /** Sampling filter (default `'trilinear'`). */\n filter?: VDBAtlasFilter;\n}\n\n/**\n * Twin of the `decodeToAtlas` pass before normalization: one f32 per output\n * voxel (x fastest), sampled at index position `min + (i + 0.5) * size / dims\n * - 0.5` (cell `i` of `dims` over `[min, max]`, `size = max - min + 1`; voxel\n * centres at full resolution, K2.6) with `vdbReadValue(floor(p + 0.5))` (`'nearest'`) or\n * the vendored trilinear (`'trilinear'`, the default). Feed the result to\n * {@link atlasFromRaw} for the formatted atlas.\n *\n * @param gridWords The grid image (little-endian u32 words, `GridData` at word 0).\n * @param options Longest atlas side and filter.\n */\nexport function vdbDecodeToAtlasCpu(\n gridWords: Uint32Array,\n options: VDBDecodeToAtlasCpuOptions = {},\n): { raw: Float32Array; dims: [number, number, number] } {\n const bbox = indexBBox(gridWords);\n const size = bboxSize(bbox);\n const dims = atlasDims(bbox, options.maxDim ?? 256);\n const trilinear = (options.filter ?? \"trilinear\") === \"trilinear\";\n const raw = new Float32Array(dims[0] * dims[1] * dims[2]);\n const pos: Vec3 = [0, 0, 0];\n let i = 0;\n for (let z = 0; z < dims[2]; z++) {\n for (let y = 0; y < dims[1]; y++) {\n for (let x = 0; x < dims[0]; x++) {\n const g: Vec3 = [x, y, z];\n for (let a = 0; a < 3; a++) pos[a] = f(bbox.min[a]! + f(f(f(f(g[a]! + 0.5) * size[a]!) / dims[a]!) - 0.5));\n raw[i++] = trilinear ? trilinearF32(gridWords, pos) : vdbReadValueF32Cpu(gridWords, [Math.floor(f(pos[0] + 0.5)), Math.floor(f(pos[1] + 0.5)), Math.floor(f(pos[2] + 0.5))]);\n }\n }\n }\n return { raw, dims };\n}\n\n/** The vendored `sample_trilinear_typed` in f32: `mix(a, b, t)` as `a + t * (b - a)`. */\nfunction trilinearF32(gridWords: Uint32Array, xyz: Vec3): number {\n const b: Vec3 = [Math.floor(xyz[0]), Math.floor(xyz[1]), Math.floor(xyz[2])];\n const u = [f(xyz[0] - b[0]), f(xyz[1] - b[1]), f(xyz[2] - b[2])];\n const tap = (dx: number, dy: number, dz: number) => vdbReadValueF32Cpu(gridWords, [b[0] + dx, b[1] + dy, b[2] + dz]);\n const mix = (a: number, c: number, t: number) => f(a + f(t * f(c - a)));\n const x00 = mix(tap(0, 0, 0), tap(1, 0, 0), u[0]!);\n const x10 = mix(tap(0, 1, 0), tap(1, 1, 0), u[0]!);\n const x01 = mix(tap(0, 0, 1), tap(1, 0, 1), u[0]!);\n const x11 = mix(tap(0, 1, 1), tap(1, 1, 1), u[0]!);\n return mix(mix(x00, x10, u[1]!), mix(x01, x11, u[1]!), u[2]!);\n}\n\n// ---------------------------------------------------------------------------\n// Value transform\n\n/**\n * Returns a copy of a Float or Half grid image with `fn` applied to every leaf\n * voxel value inside the index bbox (active or inactive), rounded to f32 (and,\n * in a Half grid, then to the nearest binary16 as `vdbFloatToHalf` does; K7.H1). Tile,\n * background and out-of-bbox leaf values are left alone, exactly as v1's GPU\n * `valueTransform` did (it visited the dense bbox and rewrote level-0\n * addresses only).\n *\n * The image's statistics (root/node min, max, average, deviation) are NOT\n * recomputed: they describe the source values. Tools that trust them\n * (`gridStats`' range, `vdbNodeMax` skipping) see stale bounds; rebuild the\n * grid (e.g. `vdbBuildFromDense`) when they matter.\n *\n * Float and Half only: quantized (Fp*) leaves would need re-encoding.\n */\nexport function transformLeafValues(gridWords: Uint32Array, fn: (value: number) => number): Uint32Array {\n if (typeof fn !== \"function\") throw new VDBToolsError(\"VDB_BAD_OPTION\", \"transformLeafValues: fn must be a function (value: number) => number\");\n const gridType = gridWords[GRID_OFF_GRID_TYPE >>> 2];\n const half = gridType === gridTypeIds.HALF;\n if (gridType !== gridTypeIds.FLOAT && !half) {\n throw new VDBToolsError(\"VDB_UNSUPPORTED_GRID_TYPE\",\n `transformLeafValues: grid type ${gridType} is not Float (${gridTypeIds.FLOAT}) or Half (${gridTypeIds.HALF}); quantized leaves would need re-encoding. ` +\n \"Transform the Float source and quantize() afterwards.\",\n );\n }\n const out = gridWords.slice();\n const outF32 = new Float32Array(out.buffer, out.byteOffset, out.length);\n const outU16 = new Uint16Array(out.buffer, out.byteOffset, out.length * 2);\n const table = gridTypeConstantsFor(half ? \"HALF\" : \"FLOAT\").leaf_off_table;\n const { min, max } = indexBBox(gridWords);\n for (const node of treeNodes(gridWords)) {\n if (node.level !== 0) continue;\n const [ox, oy, oz] = node.origin;\n for (let n = 0; n < 512; n++) {\n const x = ox + (n >> 6);\n const y = oy + ((n >> 3) & 7);\n const z = oz + (n & 7);\n if (x < min[0] || y < min[1] || z < min[2] || x > max[0] || y > max[1] || z > max[2]) continue;\n if (half) {\n const at = (node.address + table + 2 * n) >>> 1;\n outU16[at] = vdbFloatToHalf(f(fn(vdbHalfToFloat(outU16[at]!))));\n } else {\n const word = (node.address + table + 4 * n) >>> 2;\n outF32[word] = f(fn(outF32[word]!));\n }\n }\n }\n return out;\n}\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** What the lean accessor caches (the module option `cache`). */
|
|
2
|
+
export type LeanCache = "leaf" | "lower" | "lowerLeaf";
|
|
3
|
+
/** Options of {@link LeanReadCounter}: the module options that change what a read loads. */
|
|
4
|
+
export interface LeanReadOptions {
|
|
5
|
+
/** The accessor cache. Default `'leaf'`. */
|
|
6
|
+
cache?: LeanCache;
|
|
7
|
+
/** `'zero'`: taps outside the index bbox read 0 without a load, and an init reads the bbox. Default `'background'`. */
|
|
8
|
+
outside?: "background" | "zero";
|
|
9
|
+
/** Grid types the module compiles: with 1 (default) the unchecked init does not read the record's type. */
|
|
10
|
+
compiledTypes?: number;
|
|
11
|
+
}
|
|
12
|
+
/** The lean `VdbAccessor`. */
|
|
13
|
+
export interface LeanAccessor {
|
|
14
|
+
ok: boolean;
|
|
15
|
+
/** Leaf cache: origin (`ijk & -8`) and byte address (0 = none); with cache `'lower'` the lower node (`ijk & -128`). */
|
|
16
|
+
lk: [number, number, number];
|
|
17
|
+
la: number;
|
|
18
|
+
/** `'lowerLeaf'`: the lower node. */
|
|
19
|
+
qk: [number, number, number];
|
|
20
|
+
qa: number;
|
|
21
|
+
}
|
|
22
|
+
/** Loads since the last {@link LeanReadCounter.reset}. */
|
|
23
|
+
export interface LeanReadCounts {
|
|
24
|
+
/** Pool-table words (the grid count and the grid's record). */
|
|
25
|
+
table: number;
|
|
26
|
+
/** Words of the grid image. */
|
|
27
|
+
image: number;
|
|
28
|
+
/** Different words among them (a word loaded twice counts once). */
|
|
29
|
+
distinct: number;
|
|
30
|
+
}
|
|
31
|
+
/** The lean reader on one grid image, counting loads. */
|
|
32
|
+
export declare class LeanReadCounter {
|
|
33
|
+
readonly image: Uint32Array;
|
|
34
|
+
readonly cache: LeanCache;
|
|
35
|
+
readonly zero: boolean;
|
|
36
|
+
readonly gridType: number;
|
|
37
|
+
private readonly compiledTypes;
|
|
38
|
+
private readonly lo;
|
|
39
|
+
private readonly hi;
|
|
40
|
+
private table;
|
|
41
|
+
private loads;
|
|
42
|
+
private readonly seen;
|
|
43
|
+
constructor(image: Uint32Array, options?: LeanReadOptions);
|
|
44
|
+
/** Forget the loads counted so far. */
|
|
45
|
+
reset(): void;
|
|
46
|
+
/** Loads since the last `reset()`. */
|
|
47
|
+
get counts(): LeanReadCounts;
|
|
48
|
+
private rec;
|
|
49
|
+
/** `vdb_ln_w`. */
|
|
50
|
+
private w;
|
|
51
|
+
private bit;
|
|
52
|
+
/** `vdb_live(g)`: the grid count and the record's flags. */
|
|
53
|
+
private live;
|
|
54
|
+
private root;
|
|
55
|
+
/**
|
|
56
|
+
* `vdbAccessorInit(g)` (`'checked'`) or the helper `vdbAccessorInitUnchecked(g)`.
|
|
57
|
+
* Checked: `vdbGridType` (live check, type), the image offset, the root offset (an image word) and, with
|
|
58
|
+
* `outside: 'zero'`, `vdbIndexMin` and `vdbIndexMax` (a live check and 3 words each).
|
|
59
|
+
* Unchecked: the type (only in a module of several types), the image offset, the root offset, the 6 bbox words.
|
|
60
|
+
*/
|
|
61
|
+
accessor(init?: "checked" | "unchecked"): LeanAccessor;
|
|
62
|
+
/** `vdb_ln_lower`: (address, level) with level 1 the lower node, 2 upper tile, 3 root tile, 4 background; then (mask word address, bit). */
|
|
63
|
+
private lower;
|
|
64
|
+
/** `vdb_ln_down`: the lower node's child lookup: (address, level 0 leaf / 1 lower tile, mask word address, bit). */
|
|
65
|
+
private down;
|
|
66
|
+
/** `vdb_ln_find`: the whole descent. */
|
|
67
|
+
private find;
|
|
68
|
+
private f32;
|
|
69
|
+
/** `vdb_ln_tile`: a tile or background slot. */
|
|
70
|
+
private tile;
|
|
71
|
+
/** `vdb_ln_leaf`: voxel `n` of the leaf at `l`. */
|
|
72
|
+
private leaf;
|
|
73
|
+
private differs;
|
|
74
|
+
/** `vdbReadValue(&acc, ijk)`. */
|
|
75
|
+
readValue(acc: LeanAccessor, ijk: readonly [number, number, number]): number;
|
|
76
|
+
/** `vdbIsActive(&acc, ijk)` (no cache: a walk from the root every time). */
|
|
77
|
+
isActive(acc: LeanAccessor, ijk: readonly [number, number, number]): boolean;
|
|
78
|
+
private tap;
|
|
79
|
+
/** `vdbSample(&acc, xyz)`, trilinear (and `vdbSampleFast`, the same function under the lean reader). */
|
|
80
|
+
sample(acc: LeanAccessor, xyz: readonly [number, number, number]): number;
|
|
81
|
+
}
|