@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,726 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CPU twins (D11) of the `march` WGSL profile (docs/dev/design/K1-core.md §3.2,
|
|
3
|
+
* task K1.4b): the vendored HDDA (`vdbHddaInit/Update/Step`), the node size at
|
|
4
|
+
* a voxel (`vdbGetDim`), node statistics (the fork's
|
|
5
|
+
* `{root,upper,lower,leaf}_get_{min,max,ave,stddev}_float`, with the K1.4b Fp
|
|
6
|
+
* leaf-stats fix), `vdbNodeMax`, `vdbRayClip`, and `hddaWalk`, the canonical
|
|
7
|
+
* walk the GPU probe kernel runs with the same calls. Also the opt-in helpers
|
|
8
|
+
* (K1.7a): `vdbCellBoundTrilinear`, `vdbHddaCellEnd`, `vdbRayClipSupport`.
|
|
9
|
+
*
|
|
10
|
+
* Float arithmetic: every f32 operation of the WGSL is rounded here with
|
|
11
|
+
* `Math.fround`, in the WGSL's evaluation order. GPUs may fuse a multiply-add
|
|
12
|
+
* or use a less exact division (WGSL allows 2.5 ULP), so GPU parity compares
|
|
13
|
+
* `t` with a tolerance, not bit for bit.
|
|
14
|
+
*
|
|
15
|
+
* What the node stats guarantee (NanoVDB `tools/GridStats.h`): a node's
|
|
16
|
+
* min/max/ave/stddev cover the ACTIVE voxels and ACTIVE tiles of its subtree.
|
|
17
|
+
* They say nothing about inactive voxels, inactive tiles or the background.
|
|
18
|
+
* A trilinear sample at `p` blends voxels `floor(p)` and `floor(p) + 1`, so a
|
|
19
|
+
* sample inside a leaf's cell can read a neighbouring leaf, a tile, or an
|
|
20
|
+
* inactive voxel: the leaf's max does not bound it. The bound for a sample is
|
|
21
|
+
* the max over its 2x2x2 support of each tap's own bound (leaf max for a leaf
|
|
22
|
+
* voxel, the value for a tile or the background), and that is a bound only if
|
|
23
|
+
* every inactive leaf voxel is <= its leaf's max. `test/tools/cpu-march.test.ts`
|
|
24
|
+
* checks exactly these statements per fixture.
|
|
25
|
+
*
|
|
26
|
+
* Fp leaf stats (NanoVDB.h `LeafFnBase`, OpenVDB a532de55): uint16 codes at
|
|
27
|
+
* leaf bytes 88/90/92/94; min/max/ave = code * quantum + minimum, stddev =
|
|
28
|
+
* code * quantum, with the leaf's own mMinimum (byte 80) and mQuantum (84).
|
|
29
|
+
*
|
|
30
|
+
* Half grids (K7.H, NanoVDB `GridType::Half`): voxels, tiles, the background
|
|
31
|
+
* and min/max stats are IEEE binary16 at every level (2-byte aligned), decoded
|
|
32
|
+
* exactly as the fork's `pnanovdb_read_half` (`unpack2x16float`) does;
|
|
33
|
+
* ave/stddev are f32.
|
|
34
|
+
*/
|
|
35
|
+
import { VDBToolsError } from "../errors.js";
|
|
36
|
+
import { vdbHalfToFloat } from "../nanovdb/half.js";
|
|
37
|
+
import { defineBigInt, defineNumber, gridTypeConstantsForId, gridTypeIds } from "./stride-tables.js";
|
|
38
|
+
const f = Math.fround;
|
|
39
|
+
const GRID_OFF_MAGIC = defineNumber("PNANOVDB_GRID_OFF_MAGIC");
|
|
40
|
+
const GRID_OFF_FLAGS = defineNumber("PNANOVDB_GRID_OFF_FLAGS");
|
|
41
|
+
const GRID_OFF_GRID_TYPE = defineNumber("PNANOVDB_GRID_OFF_GRID_TYPE");
|
|
42
|
+
const GRID_SIZE = defineNumber("PNANOVDB_GRID_SIZE");
|
|
43
|
+
const MAGIC_GRID = defineBigInt("PNANOVDB_MAGIC_GRID");
|
|
44
|
+
const TREE_OFF_NODE_OFFSET_ROOT = defineNumber("PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT");
|
|
45
|
+
const ROOT_OFF_BBOX_MIN = defineNumber("PNANOVDB_ROOT_OFF_BBOX_MIN");
|
|
46
|
+
const ROOT_OFF_BBOX_MAX = defineNumber("PNANOVDB_ROOT_OFF_BBOX_MAX");
|
|
47
|
+
const ROOT_OFF_TABLE_SIZE = defineNumber("PNANOVDB_ROOT_OFF_TABLE_SIZE");
|
|
48
|
+
const ROOT_TILE_OFF_KEY = defineNumber("PNANOVDB_ROOT_TILE_OFF_KEY");
|
|
49
|
+
const ROOT_TILE_OFF_CHILD = defineNumber("PNANOVDB_ROOT_TILE_OFF_CHILD");
|
|
50
|
+
const ROOT_TILE_OFF_STATE = defineNumber("PNANOVDB_ROOT_TILE_OFF_STATE");
|
|
51
|
+
const UPPER_OFF_VALUE_MASK = defineNumber("PNANOVDB_UPPER_OFF_VALUE_MASK");
|
|
52
|
+
const UPPER_OFF_CHILD_MASK = defineNumber("PNANOVDB_UPPER_OFF_CHILD_MASK");
|
|
53
|
+
const LOWER_OFF_VALUE_MASK = defineNumber("PNANOVDB_LOWER_OFF_VALUE_MASK");
|
|
54
|
+
const LOWER_OFF_CHILD_MASK = defineNumber("PNANOVDB_LOWER_OFF_CHILD_MASK");
|
|
55
|
+
const LEAF_OFF_VALUE_MASK = defineNumber("PNANOVDB_LEAF_OFF_VALUE_MASK");
|
|
56
|
+
const LEAF_TABLE_NEG_OFF_BBOX_DIF_AND_FLAGS = defineNumber("PNANOVDB_LEAF_TABLE_NEG_OFF_BBOX_DIF_AND_FLAGS");
|
|
57
|
+
const LEAF_TABLE_NEG_OFF_MINIMUM = defineNumber("PNANOVDB_LEAF_TABLE_NEG_OFF_MINIMUM");
|
|
58
|
+
const LEAF_TABLE_NEG_OFF_QUANTUM = defineNumber("PNANOVDB_LEAF_TABLE_NEG_OFF_QUANTUM");
|
|
59
|
+
/** PNANOVDB_GRID_FLAGS_HAS_MIN_MAX (1 << 2); not in the extracted defines. */
|
|
60
|
+
const GRID_FLAGS_HAS_MIN_MAX = 4;
|
|
61
|
+
/** PNANOVDB_HDDA_FLOAT_MAX. */
|
|
62
|
+
const HDDA_FLOAT_MAX = f(1e38);
|
|
63
|
+
const FORWARD_SCALE = f(0.999999);
|
|
64
|
+
const FORWARD_BIAS = f(1.0e-6);
|
|
65
|
+
const FP_TYPES = new Set([gridTypeIds.FP4, gridTypeIds.FP8, gridTypeIds.FP16, gridTypeIds.FPN]);
|
|
66
|
+
const SUPPORTED_TYPES = new Set([gridTypeIds.FLOAT, gridTypeIds.HALF, ...FP_TYPES]);
|
|
67
|
+
/** Per-image header cache, keyed by the array: images are treated as immutable once read. */
|
|
68
|
+
const grids = new WeakMap();
|
|
69
|
+
function u32(words, address) {
|
|
70
|
+
return words[address >>> 2];
|
|
71
|
+
}
|
|
72
|
+
function grid(words) {
|
|
73
|
+
let g = grids.get(words);
|
|
74
|
+
if (g)
|
|
75
|
+
return g;
|
|
76
|
+
const magic = (BigInt(u32(words, GRID_OFF_MAGIC + 4)) << 32n) | BigInt(u32(words, GRID_OFF_MAGIC));
|
|
77
|
+
if (magic !== MAGIC_GRID)
|
|
78
|
+
throw new VDBToolsError("VDB_BAD_IMAGE", "march: gridWords does not start with a NanoVDB GridData block");
|
|
79
|
+
const gridType = u32(words, GRID_OFF_GRID_TYPE);
|
|
80
|
+
if (!SUPPORTED_TYPES.has(gridType))
|
|
81
|
+
throw new VDBToolsError("VDB_UNSUPPORTED_GRID_TYPE", `march: grid type ${gridType} is not Float/Half/Fp4/Fp8/Fp16/FpN`);
|
|
82
|
+
const root = GRID_SIZE + u32(words, GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT);
|
|
83
|
+
g = {
|
|
84
|
+
words,
|
|
85
|
+
f32: new Float32Array(words.buffer, words.byteOffset, words.length),
|
|
86
|
+
gridType,
|
|
87
|
+
gt: gridTypeConstantsForId(gridType),
|
|
88
|
+
fp: FP_TYPES.has(gridType),
|
|
89
|
+
half: gridType === gridTypeIds.HALF,
|
|
90
|
+
hasStats: (u32(words, GRID_OFF_FLAGS) & GRID_FLAGS_HAS_MIN_MAX) !== 0,
|
|
91
|
+
root,
|
|
92
|
+
};
|
|
93
|
+
grids.set(words, g);
|
|
94
|
+
return g;
|
|
95
|
+
}
|
|
96
|
+
function readF32(g, address) {
|
|
97
|
+
return g.f32[address >>> 2];
|
|
98
|
+
}
|
|
99
|
+
/** pnanovdb_read_uint16 (fork, K1.4b): the u16 at a 2-byte-aligned address. */
|
|
100
|
+
function readU16(g, address) {
|
|
101
|
+
return (u32(g.words, address & ~3) >>> ((address & 2) << 3)) & 0xffff;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* A value slot (voxel, tile, background) or a min/max stats slot, as the
|
|
105
|
+
* grid stores it: binary16 for Half (the fork's `pnanovdb_read_half`), f32 otherwise.
|
|
106
|
+
*/
|
|
107
|
+
function readValueSlot(g, address) {
|
|
108
|
+
return g.half ? vdbHalfToFloat(readU16(g, address)) : readF32(g, address);
|
|
109
|
+
}
|
|
110
|
+
function maskBit(g, base, n) {
|
|
111
|
+
return ((u32(g.words, base + 4 * (n >>> 5)) >>> (n & 31)) & 1) !== 0;
|
|
112
|
+
}
|
|
113
|
+
/** Child offset (low word of the i64; the fork's 32-bit addressing). */
|
|
114
|
+
function childOffset(g, address) {
|
|
115
|
+
return u32(g.words, address) | 0;
|
|
116
|
+
}
|
|
117
|
+
function coordKey(x, y, z) {
|
|
118
|
+
return BigInt(z >>> 12) | (BigInt(y >>> 12) << 21n) | (BigInt(x >>> 12) << 42n);
|
|
119
|
+
}
|
|
120
|
+
function locate(g, [x, y, z]) {
|
|
121
|
+
const gt = g.gt;
|
|
122
|
+
const key = coordKey(x, y, z);
|
|
123
|
+
const count = u32(g.words, g.root + ROOT_OFF_TABLE_SIZE);
|
|
124
|
+
let tile = 0;
|
|
125
|
+
for (let i = 0; i < count; i++) {
|
|
126
|
+
const t = g.root + gt.root_size + i * gt.root_tile_size;
|
|
127
|
+
const k = (BigInt(u32(g.words, t + ROOT_TILE_OFF_KEY + 4)) << 32n) | BigInt(u32(g.words, t + ROOT_TILE_OFF_KEY));
|
|
128
|
+
if (k === key) {
|
|
129
|
+
tile = t;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const path = { level: 4, upper: 0, lower: 0, leaf: 0, valueAddress: g.root + gt.root_off_background, active: false };
|
|
134
|
+
if (tile === 0)
|
|
135
|
+
return path;
|
|
136
|
+
const child = childOffset(g, tile + ROOT_TILE_OFF_CHILD);
|
|
137
|
+
if (child === 0 && u32(g.words, tile + ROOT_TILE_OFF_CHILD + 4) === 0) {
|
|
138
|
+
path.level = 3;
|
|
139
|
+
path.valueAddress = tile + gt.root_tile_off_value;
|
|
140
|
+
path.active = u32(g.words, tile + ROOT_TILE_OFF_STATE) !== 0;
|
|
141
|
+
return path;
|
|
142
|
+
}
|
|
143
|
+
path.upper = g.root + child;
|
|
144
|
+
const un = (((x & 4095) >> 7) << 10) + (((y & 4095) >> 7) << 5) + ((z & 4095) >> 7);
|
|
145
|
+
const ut = path.upper + gt.upper_off_table + gt.table_stride * un;
|
|
146
|
+
if (!maskBit(g, path.upper + UPPER_OFF_CHILD_MASK, un)) {
|
|
147
|
+
path.level = 2;
|
|
148
|
+
path.valueAddress = ut;
|
|
149
|
+
path.active = maskBit(g, path.upper + UPPER_OFF_VALUE_MASK, un);
|
|
150
|
+
return path;
|
|
151
|
+
}
|
|
152
|
+
path.lower = path.upper + childOffset(g, ut);
|
|
153
|
+
const ln = (((x & 127) >> 3) << 8) + (((y & 127) >> 3) << 4) + ((z & 127) >> 3);
|
|
154
|
+
const lt = path.lower + gt.lower_off_table + gt.table_stride * ln;
|
|
155
|
+
if (!maskBit(g, path.lower + LOWER_OFF_CHILD_MASK, ln)) {
|
|
156
|
+
path.level = 1;
|
|
157
|
+
path.valueAddress = lt;
|
|
158
|
+
path.active = maskBit(g, path.lower + LOWER_OFF_VALUE_MASK, ln);
|
|
159
|
+
return path;
|
|
160
|
+
}
|
|
161
|
+
path.leaf = path.lower + childOffset(g, lt);
|
|
162
|
+
path.level = 0;
|
|
163
|
+
path.active = maskBit(g, path.leaf + LEAF_OFF_VALUE_MASK, ((x & 7) << 6) + ((y & 7) << 3) + (z & 7));
|
|
164
|
+
return path;
|
|
165
|
+
}
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
// Node size and statistics
|
|
168
|
+
/**
|
|
169
|
+
* Twin of `vdbGetDim` (vendored `readaccessor_get_dim`): 1 inside a leaf, 8 in
|
|
170
|
+
* a lower-node tile, 128 in an upper-node tile, 4096 in a root tile or the
|
|
171
|
+
* background.
|
|
172
|
+
*/
|
|
173
|
+
export function getDim(gridWords, ijk) {
|
|
174
|
+
return DIM_OF_LEVEL[locate(grid(gridWords), ijk).level];
|
|
175
|
+
}
|
|
176
|
+
const DIM_OF_LEVEL = [1, 8, 128, 4096, 4096];
|
|
177
|
+
/** pnanovdb_leaf_fp_get_stat_float: `code * quantum (+ minimum)` in f32. */
|
|
178
|
+
function leafFpStat(g, leaf, address, withMinimum) {
|
|
179
|
+
const table = leaf + g.gt.leaf_off_table; // value_stride_bits is 0 for the Fp types
|
|
180
|
+
const minimum = readF32(g, table - LEAF_TABLE_NEG_OFF_MINIMUM);
|
|
181
|
+
const quantum = readF32(g, table - LEAF_TABLE_NEG_OFF_QUANTUM);
|
|
182
|
+
const scaled = f(readU16(g, address) * quantum);
|
|
183
|
+
return withMinimum ? f(scaled + minimum) : scaled;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Twin of the fork's `{root,upper,lower,leaf}_get_{min,max,ave,stddev}_float`
|
|
187
|
+
* for the node at byte `address` of the image. Root, upper and lower stats are
|
|
188
|
+
* f32; Fp leaf stats are uint16 codes decoded against the leaf's quantization.
|
|
189
|
+
* Meaningful only when the grid has stats (`HAS_MIN_MAX`) and the node has
|
|
190
|
+
* active values.
|
|
191
|
+
*/
|
|
192
|
+
export function nodeStats(gridWords, level, address) {
|
|
193
|
+
const g = grid(gridWords);
|
|
194
|
+
const gt = g.gt;
|
|
195
|
+
if (level === 0 && g.fp) {
|
|
196
|
+
return {
|
|
197
|
+
min: leafFpStat(g, address, address + gt.leaf_off_min, true),
|
|
198
|
+
max: leafFpStat(g, address, address + gt.leaf_off_max, true),
|
|
199
|
+
ave: leafFpStat(g, address, address + gt.leaf_off_ave, true),
|
|
200
|
+
stddev: leafFpStat(g, address, address + gt.leaf_off_stddev, false),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const off = level === 0
|
|
204
|
+
? [gt.leaf_off_min, gt.leaf_off_max, gt.leaf_off_ave, gt.leaf_off_stddev]
|
|
205
|
+
: level === 1
|
|
206
|
+
? [gt.lower_off_min, gt.lower_off_max, gt.lower_off_ave, gt.lower_off_stddev]
|
|
207
|
+
: level === 2
|
|
208
|
+
? [gt.upper_off_min, gt.upper_off_max, gt.upper_off_ave, gt.upper_off_stddev]
|
|
209
|
+
: [gt.root_off_min, gt.root_off_max, gt.root_off_ave, gt.root_off_stddev];
|
|
210
|
+
return {
|
|
211
|
+
min: readValueSlot(g, address + off[0]),
|
|
212
|
+
max: readValueSlot(g, address + off[1]),
|
|
213
|
+
ave: readF32(g, address + off[2]),
|
|
214
|
+
stddev: readF32(g, address + off[3]),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/** Whether the grid carries node stats (`HAS_MIN_MAX`; pool record flag b1). */
|
|
218
|
+
export function gridHasStats(gridWords) {
|
|
219
|
+
return grid(gridWords).hasStats;
|
|
220
|
+
}
|
|
221
|
+
/** The pool's `valueMax` for this image with no caller bound (`VDBGridPool`): max(root max, background), or +Infinity without stats. */
|
|
222
|
+
export function defaultValueMax(gridWords) {
|
|
223
|
+
const g = grid(gridWords);
|
|
224
|
+
if (!g.hasStats)
|
|
225
|
+
return Infinity;
|
|
226
|
+
return Math.max(readValueSlot(g, g.root + g.gt.root_off_max), readValueSlot(g, g.root + g.gt.root_off_background));
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Twin of `vdbNodeMax(acc, ijk, dim)`: a bound for the aligned cell of size
|
|
230
|
+
* `dim` holding `ijk`. With `a = getDim(ijk)`: if `a > 1` and `dim <= a` the
|
|
231
|
+
* cell is one tile and the result is its value (exact). Otherwise it is the
|
|
232
|
+
* max statistic of the smallest node spanning the cell (leaf for `dim <= 8`,
|
|
233
|
+
* lower `<= 128`, upper `<= 4096`, else root), which bounds that node's ACTIVE
|
|
234
|
+
* values only; without stats it is `valueMax` (+Infinity unless the caller
|
|
235
|
+
* gave a bound).
|
|
236
|
+
*/
|
|
237
|
+
export function nodeMax(gridWords, ijk, dim, options = {}) {
|
|
238
|
+
const g = grid(gridWords);
|
|
239
|
+
const path = locate(g, ijk);
|
|
240
|
+
const a = DIM_OF_LEVEL[path.level];
|
|
241
|
+
if (a > 1 && dim <= a)
|
|
242
|
+
return readValueSlot(g, path.valueAddress);
|
|
243
|
+
if (!g.hasStats)
|
|
244
|
+
return options.valueMax ?? defaultValueMax(gridWords);
|
|
245
|
+
if (dim <= 8)
|
|
246
|
+
return nodeStats(gridWords, 0, path.leaf).max;
|
|
247
|
+
if (dim <= 128)
|
|
248
|
+
return nodeStats(gridWords, 1, path.lower).max;
|
|
249
|
+
if (dim <= 4096)
|
|
250
|
+
return nodeStats(gridWords, 2, path.upper).max;
|
|
251
|
+
return nodeStats(gridWords, 3, g.root).max;
|
|
252
|
+
}
|
|
253
|
+
/** Twin of `vdbIsActive`. */
|
|
254
|
+
export function isActive(gridWords, ijk) {
|
|
255
|
+
return locate(grid(gridWords), ijk).active;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Twin of `vdbReadValue` (f32 decode in WGSL order; any of Float/Half/Fp4/Fp8/Fp16/FpN).
|
|
259
|
+
*
|
|
260
|
+
* This matches the GPU's evaluation order (f32 arithmetic), so it is the right
|
|
261
|
+
* oracle for GPU parity checks. `readValue` instead returns the exact f64
|
|
262
|
+
* decode; on Fp grids the two can differ by 1 ulp (f32).
|
|
263
|
+
*
|
|
264
|
+
* @param gridWords The grid image (little-endian u32 words, `GridData` at word 0).
|
|
265
|
+
* @param ijk Integer index coordinates of the voxel.
|
|
266
|
+
*/
|
|
267
|
+
export function vdbReadValueF32Cpu(gridWords, ijk) {
|
|
268
|
+
const g = grid(gridWords);
|
|
269
|
+
const path = locate(g, ijk);
|
|
270
|
+
if (path.level !== 0)
|
|
271
|
+
return readValueSlot(g, path.valueAddress);
|
|
272
|
+
const n = ((ijk[0] & 7) << 6) + ((ijk[1] & 7) << 3) + (ijk[2] & 7);
|
|
273
|
+
return leafValue(g, path.leaf, n);
|
|
274
|
+
}
|
|
275
|
+
function leafValue(g, leaf, n) {
|
|
276
|
+
const table = leaf + g.gt.leaf_off_table;
|
|
277
|
+
if (!g.fp)
|
|
278
|
+
return readValueSlot(g, table + ((g.gt.value_stride_bits * n) >> 3));
|
|
279
|
+
let logBits;
|
|
280
|
+
if (g.gridType === gridTypeIds.FP4)
|
|
281
|
+
logBits = 2;
|
|
282
|
+
else if (g.gridType === gridTypeIds.FP8)
|
|
283
|
+
logBits = 3;
|
|
284
|
+
else if (g.gridType === gridTypeIds.FP16)
|
|
285
|
+
logBits = 4;
|
|
286
|
+
else
|
|
287
|
+
logBits = (u32(g.words, table - LEAF_TABLE_NEG_OFF_BBOX_DIF_AND_FLAGS) >>> 24) >>> 5;
|
|
288
|
+
const bits = 1 << logBits;
|
|
289
|
+
const perWordBits = 5 - logBits;
|
|
290
|
+
const minimum = readF32(g, table - LEAF_TABLE_NEG_OFF_MINIMUM);
|
|
291
|
+
const quantum = readF32(g, table - LEAF_TABLE_NEG_OFF_QUANTUM);
|
|
292
|
+
const raw = u32(g.words, table + ((n >> perWordBits) << 2));
|
|
293
|
+
const code = (raw >>> ((n & ((1 << perWordBits) - 1)) << logBits)) & ((1 << bits) - 1);
|
|
294
|
+
return f(f(code * quantum) + minimum);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Every node of the tree, root first, then depth first. Leaves carry no tiles;
|
|
298
|
+
* use {@link leafVoxels} for their values.
|
|
299
|
+
*/
|
|
300
|
+
export function treeNodes(gridWords) {
|
|
301
|
+
const g = grid(gridWords);
|
|
302
|
+
const gt = g.gt;
|
|
303
|
+
const out = [{ level: 3, address: g.root, origin: [0, 0, 0], parent: -1, activeTiles: [] }];
|
|
304
|
+
const rootNode = out[0];
|
|
305
|
+
const count = u32(g.words, g.root + ROOT_OFF_TABLE_SIZE);
|
|
306
|
+
for (let i = 0; i < count; i++) {
|
|
307
|
+
const t = g.root + gt.root_size + i * gt.root_tile_size;
|
|
308
|
+
const lo = u32(g.words, t + ROOT_TILE_OFF_KEY);
|
|
309
|
+
const hi = u32(g.words, t + ROOT_TILE_OFF_KEY + 4);
|
|
310
|
+
const key = (BigInt(hi) << 32n) | BigInt(lo);
|
|
311
|
+
const origin = [
|
|
312
|
+
Number((key >> 42n) & 0x1fffffn) << 12 | 0,
|
|
313
|
+
Number((key >> 21n) & 0x1fffffn) << 12 | 0,
|
|
314
|
+
Number(key & 0x1fffffn) << 12 | 0,
|
|
315
|
+
];
|
|
316
|
+
const child = childOffset(g, t + ROOT_TILE_OFF_CHILD);
|
|
317
|
+
if (child === 0 && u32(g.words, t + ROOT_TILE_OFF_CHILD + 4) === 0) {
|
|
318
|
+
if (u32(g.words, t + ROOT_TILE_OFF_STATE) !== 0)
|
|
319
|
+
rootNode.activeTiles.push({ value: readValueSlot(g, t + gt.root_tile_off_value), origin, dim: 4096 });
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
const upper = g.root + child;
|
|
323
|
+
const ui = out.push({ level: 2, address: upper, origin, parent: 0, activeTiles: [] }) - 1;
|
|
324
|
+
for (let un = 0; un < 32768; un++) {
|
|
325
|
+
const uo = [origin[0] + ((un >> 10) & 31) * 128, origin[1] + ((un >> 5) & 31) * 128, origin[2] + (un & 31) * 128];
|
|
326
|
+
const ut = upper + gt.upper_off_table + gt.table_stride * un;
|
|
327
|
+
if (!maskBit(g, upper + UPPER_OFF_CHILD_MASK, un)) {
|
|
328
|
+
if (maskBit(g, upper + UPPER_OFF_VALUE_MASK, un))
|
|
329
|
+
out[ui].activeTiles.push({ value: readValueSlot(g, ut), origin: uo, dim: 128 });
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
const lower = upper + childOffset(g, ut);
|
|
333
|
+
const li = out.push({ level: 1, address: lower, origin: uo, parent: ui, activeTiles: [] }) - 1;
|
|
334
|
+
for (let ln = 0; ln < 4096; ln++) {
|
|
335
|
+
const lo3 = [uo[0] + ((ln >> 8) & 15) * 8, uo[1] + ((ln >> 4) & 15) * 8, uo[2] + (ln & 15) * 8];
|
|
336
|
+
const lt = lower + gt.lower_off_table + gt.table_stride * ln;
|
|
337
|
+
if (!maskBit(g, lower + LOWER_OFF_CHILD_MASK, ln)) {
|
|
338
|
+
if (maskBit(g, lower + LOWER_OFF_VALUE_MASK, ln))
|
|
339
|
+
out[li].activeTiles.push({ value: readValueSlot(g, lt), origin: lo3, dim: 8 });
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
out.push({ level: 0, address: lower + childOffset(g, lt), origin: lo3, parent: li, activeTiles: [] });
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return out;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Every leaf and every tile of the tree, active or not (P1.2, the brick-majorant builder needs the
|
|
350
|
+
* values a trilinear tap can read, inactive ones included). Space under no root tile reads the
|
|
351
|
+
* background: the result lists the min corners of the root tiles (with or without a child), so a
|
|
352
|
+
* caller can tell which 4096-blocks are covered.
|
|
353
|
+
*/
|
|
354
|
+
export function forEachTreeRegion(gridWords, visit) {
|
|
355
|
+
const g = grid(gridWords);
|
|
356
|
+
const gt = g.gt;
|
|
357
|
+
const rootTiles = [];
|
|
358
|
+
const count = u32(g.words, g.root + ROOT_OFF_TABLE_SIZE);
|
|
359
|
+
for (let i = 0; i < count; i++) {
|
|
360
|
+
const t = g.root + gt.root_size + i * gt.root_tile_size;
|
|
361
|
+
const key = (BigInt(u32(g.words, t + ROOT_TILE_OFF_KEY + 4)) << 32n) | BigInt(u32(g.words, t + ROOT_TILE_OFF_KEY));
|
|
362
|
+
const origin = [
|
|
363
|
+
Number((key >> 42n) & 0x1fffffn) << 12 | 0,
|
|
364
|
+
Number((key >> 21n) & 0x1fffffn) << 12 | 0,
|
|
365
|
+
Number(key & 0x1fffffn) << 12 | 0,
|
|
366
|
+
];
|
|
367
|
+
rootTiles.push(origin);
|
|
368
|
+
const child = childOffset(g, t + ROOT_TILE_OFF_CHILD);
|
|
369
|
+
if (child === 0 && u32(g.words, t + ROOT_TILE_OFF_CHILD + 4) === 0) {
|
|
370
|
+
visit({ level: 3, origin, dim: 4096, leaf: 0, value: readValueSlot(g, t + gt.root_tile_off_value) });
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
const upper = g.root + child;
|
|
374
|
+
for (let un = 0; un < 32768; un++) {
|
|
375
|
+
const uo = [origin[0] + ((un >> 10) & 31) * 128, origin[1] + ((un >> 5) & 31) * 128, origin[2] + (un & 31) * 128];
|
|
376
|
+
const ut = upper + gt.upper_off_table + gt.table_stride * un;
|
|
377
|
+
if (!maskBit(g, upper + UPPER_OFF_CHILD_MASK, un)) {
|
|
378
|
+
visit({ level: 2, origin: uo, dim: 128, leaf: 0, value: readValueSlot(g, ut) });
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const lower = upper + childOffset(g, ut);
|
|
382
|
+
for (let ln = 0; ln < 4096; ln++) {
|
|
383
|
+
const lo3 = [uo[0] + ((ln >> 8) & 15) * 8, uo[1] + ((ln >> 4) & 15) * 8, uo[2] + (ln & 15) * 8];
|
|
384
|
+
const lt = lower + gt.lower_off_table + gt.table_stride * ln;
|
|
385
|
+
if (!maskBit(g, lower + LOWER_OFF_CHILD_MASK, ln)) {
|
|
386
|
+
visit({ level: 1, origin: lo3, dim: 8, leaf: 0, value: readValueSlot(g, lt) });
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
visit({ level: 0, origin: lo3, dim: 8, leaf: lower + childOffset(g, lt), value: 0 });
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return { background: readValueSlot(g, g.root + gt.root_off_background), rootTiles };
|
|
394
|
+
}
|
|
395
|
+
function popcount32(v) {
|
|
396
|
+
v -= (v >>> 1) & 0x55555555;
|
|
397
|
+
v = (v & 0x33333333) + ((v >>> 2) & 0x33333333);
|
|
398
|
+
return (((v + (v >>> 4)) & 0x0f0f0f0f) * 0x01010101) >>> 24;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Walks the tree of a scalar grid image (Float, Half, Fp4, Fp8, Fp16, FpN): its leaves and tiles, and on request
|
|
402
|
+
* its upper and lower nodes. For drawing node boxes, counting what a grid stores, or telling where a voxel's value
|
|
403
|
+
* comes from (a leaf holds one value per voxel; a tile is one value for its whole block).
|
|
404
|
+
*
|
|
405
|
+
* The order is the image's own: root entries in table order (signed origin order: x, then y, then z), then each
|
|
406
|
+
* node's table by slot, depth first. Every entry is a new object. Space that no entry covers reads the grid's
|
|
407
|
+
* background. Voxel values are not decoded here: read them with `vdbReadValueCpu`.
|
|
408
|
+
*
|
|
409
|
+
* The image and the options are checked when the first entry is asked for, not when the function is called.
|
|
410
|
+
*
|
|
411
|
+
* @param image A NanoVDB grid image (`NvdbFile.gridImage`, `buildFromVdb`, `vdbBuildFromDense`, `vdbQuantize`…).
|
|
412
|
+
* @throws {VDBToolsError} `VDB_BAD_IMAGE` for words that are not a grid image, `VDB_UNSUPPORTED_GRID_TYPE` for a
|
|
413
|
+
* grid type that is not scalar (vector, point and index grids), `VDB_BAD_OPTION` for an unknown `tiles` value.
|
|
414
|
+
*/
|
|
415
|
+
export function* vdbTreeNodes(image, options = {}) {
|
|
416
|
+
const tiles = options.tiles ?? "active";
|
|
417
|
+
if (tiles !== "active" && tiles !== "all" && tiles !== "none") {
|
|
418
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `vdbTreeNodes: tiles must be 'active', 'all' or 'none', got ${String(tiles)}`);
|
|
419
|
+
}
|
|
420
|
+
const leaves = options.leaves !== false;
|
|
421
|
+
const internalNodes = options.internalNodes === true;
|
|
422
|
+
const allTiles = tiles === "all";
|
|
423
|
+
const g = grid(image);
|
|
424
|
+
const gt = g.gt;
|
|
425
|
+
const count = u32(g.words, g.root + ROOT_OFF_TABLE_SIZE);
|
|
426
|
+
for (let i = 0; i < count; i++) {
|
|
427
|
+
const t = g.root + gt.root_size + i * gt.root_tile_size;
|
|
428
|
+
const key = (BigInt(u32(g.words, t + ROOT_TILE_OFF_KEY + 4)) << 32n) | BigInt(u32(g.words, t + ROOT_TILE_OFF_KEY));
|
|
429
|
+
const ox = Number((key >> 42n) & 0x1fffffn) << 12 | 0;
|
|
430
|
+
const oy = Number((key >> 21n) & 0x1fffffn) << 12 | 0;
|
|
431
|
+
const oz = Number(key & 0x1fffffn) << 12 | 0;
|
|
432
|
+
const child = childOffset(g, t + ROOT_TILE_OFF_CHILD);
|
|
433
|
+
if (child === 0 && u32(g.words, t + ROOT_TILE_OFF_CHILD + 4) === 0) {
|
|
434
|
+
if (tiles === "none")
|
|
435
|
+
continue;
|
|
436
|
+
const active = u32(g.words, t + ROOT_TILE_OFF_STATE) !== 0;
|
|
437
|
+
if (active || allTiles)
|
|
438
|
+
yield { kind: "tile", level: 3, origin: [ox, oy, oz], size: 4096, value: readValueSlot(g, t + gt.root_tile_off_value), active };
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
const upper = g.root + child;
|
|
442
|
+
if (internalNodes)
|
|
443
|
+
yield { kind: "upper", level: 2, origin: [ox, oy, oz], size: 4096 };
|
|
444
|
+
for (let un = 0; un < 32768; un++) {
|
|
445
|
+
const isChild = maskBit(g, upper + UPPER_OFF_CHILD_MASK, un);
|
|
446
|
+
if (!isChild && tiles === "none")
|
|
447
|
+
continue;
|
|
448
|
+
const ux = ox + ((un >> 10) & 31) * 128;
|
|
449
|
+
const uy = oy + ((un >> 5) & 31) * 128;
|
|
450
|
+
const uz = oz + (un & 31) * 128;
|
|
451
|
+
const ut = upper + gt.upper_off_table + gt.table_stride * un;
|
|
452
|
+
if (!isChild) {
|
|
453
|
+
const active = maskBit(g, upper + UPPER_OFF_VALUE_MASK, un);
|
|
454
|
+
if (active || allTiles)
|
|
455
|
+
yield { kind: "tile", level: 2, origin: [ux, uy, uz], size: 128, value: readValueSlot(g, ut), active };
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
const lower = upper + childOffset(g, ut);
|
|
459
|
+
if (internalNodes)
|
|
460
|
+
yield { kind: "lower", level: 1, origin: [ux, uy, uz], size: 128 };
|
|
461
|
+
for (let ln = 0; ln < 4096; ln++) {
|
|
462
|
+
const isLeaf = maskBit(g, lower + LOWER_OFF_CHILD_MASK, ln);
|
|
463
|
+
if (isLeaf ? !leaves : tiles === "none")
|
|
464
|
+
continue;
|
|
465
|
+
const origin = [ux + ((ln >> 8) & 15) * 8, uy + ((ln >> 4) & 15) * 8, uz + (ln & 15) * 8];
|
|
466
|
+
const lt = lower + gt.lower_off_table + gt.table_stride * ln;
|
|
467
|
+
if (!isLeaf) {
|
|
468
|
+
const active = maskBit(g, lower + LOWER_OFF_VALUE_MASK, ln);
|
|
469
|
+
if (active || allTiles)
|
|
470
|
+
yield { kind: "tile", level: 1, origin, size: 8, value: readValueSlot(g, lt), active };
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
const mask = lower + childOffset(g, lt) + LEAF_OFF_VALUE_MASK;
|
|
474
|
+
let activeVoxelCount = 0;
|
|
475
|
+
for (let w = 0; w < 16; w++)
|
|
476
|
+
activeVoxelCount += popcount32(u32(g.words, mask + 4 * w));
|
|
477
|
+
yield { kind: "leaf", level: 0, origin, size: 8, activeVoxelCount };
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
/** A leaf's 512 decoded values (f32, WGSL decode order) and active flags, x-major (`n = x*64 + y*8 + z`). */
|
|
483
|
+
export function leafVoxels(gridWords, leafAddress) {
|
|
484
|
+
const g = grid(gridWords);
|
|
485
|
+
const values = new Float32Array(512);
|
|
486
|
+
const active = new Uint8Array(512);
|
|
487
|
+
for (let n = 0; n < 512; n++) {
|
|
488
|
+
values[n] = leafValue(g, leafAddress, n);
|
|
489
|
+
active[n] = maskBit(g, leafAddress + LEAF_OFF_VALUE_MASK, n) ? 1 : 0;
|
|
490
|
+
}
|
|
491
|
+
return { values, active };
|
|
492
|
+
}
|
|
493
|
+
function posToVoxel(pos, dim) {
|
|
494
|
+
const mask = ~(dim - 1);
|
|
495
|
+
return [Math.floor(pos[0]) & mask, Math.floor(pos[1]) & mask, Math.floor(pos[2]) & mask];
|
|
496
|
+
}
|
|
497
|
+
function rayStart(o, t, d) {
|
|
498
|
+
return [f(o[0] + f(d[0] * t)), f(o[1] + f(d[1] * t)), f(o[2] + f(d[2] * t))];
|
|
499
|
+
}
|
|
500
|
+
const f3 = (v) => [f(v[0]), f(v[1]), f(v[2])];
|
|
501
|
+
/** Twin of `vdbHddaInit` (vendored `pnanovdb_hdda_init`). */
|
|
502
|
+
export function hddaInit(origin, tmin, direction, tmax, dim) {
|
|
503
|
+
const o = f3(origin);
|
|
504
|
+
const d = f3(direction);
|
|
505
|
+
const h = { dim, tmin: f(tmin), tmax: f(tmax), voxel: [0, 0, 0], step: [0, 0, 0], delta: [0, 0, 0], next: [0, 0, 0] };
|
|
506
|
+
const pos = rayStart(o, h.tmin, d);
|
|
507
|
+
h.voxel = posToVoxel(pos, dim);
|
|
508
|
+
for (let i = 0; i < 3; i++) {
|
|
509
|
+
const inv = f(1 / d[i]);
|
|
510
|
+
if (d[i] === 0) {
|
|
511
|
+
h.next[i] = HDDA_FLOAT_MAX;
|
|
512
|
+
h.step[i] = 0;
|
|
513
|
+
h.delta[i] = 0;
|
|
514
|
+
}
|
|
515
|
+
else if (inv > 0) {
|
|
516
|
+
h.step[i] = 1;
|
|
517
|
+
h.next[i] = f(h.tmin + f(f(f(h.voxel[i] + dim) - pos[i]) * inv));
|
|
518
|
+
h.delta[i] = inv;
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
h.step[i] = -1;
|
|
522
|
+
h.next[i] = f(h.tmin + f(f(h.voxel[i] - pos[i]) * inv));
|
|
523
|
+
h.delta[i] = -inv;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return h;
|
|
527
|
+
}
|
|
528
|
+
/** Twin of `vdbHddaUpdate` (vendored `pnanovdb_hdda_update`): switch to `dim`; false if already there. */
|
|
529
|
+
export function hddaUpdate(h, origin, direction, dim) {
|
|
530
|
+
if (h.dim === dim)
|
|
531
|
+
return false;
|
|
532
|
+
h.dim = dim;
|
|
533
|
+
const o = f3(origin);
|
|
534
|
+
const d = f3(direction);
|
|
535
|
+
const pos = rayStart(o, h.tmin, d);
|
|
536
|
+
h.voxel = posToVoxel(pos, dim);
|
|
537
|
+
for (let i = 0; i < 3; i++) {
|
|
538
|
+
if (h.step[i] === 0)
|
|
539
|
+
continue;
|
|
540
|
+
const inv = f(1 / d[i]);
|
|
541
|
+
h.next[i] = f(h.tmin + f(f(h.voxel[i] - pos[i]) * inv));
|
|
542
|
+
if (h.step[i] > 0)
|
|
543
|
+
h.next[i] = f(h.next[i] + f(dim * inv));
|
|
544
|
+
}
|
|
545
|
+
return true;
|
|
546
|
+
}
|
|
547
|
+
/** Twin of `vdbHddaStep` (vendored `pnanovdb_hdda_step`, with PNANOVDB_ENFORCE_FORWARD_STEPPING). */
|
|
548
|
+
export function hddaStep(h) {
|
|
549
|
+
const n = h.next;
|
|
550
|
+
const a = n[0] < n[1] && n[0] < n[2] ? 0 : n[1] < n[2] ? 1 : 2;
|
|
551
|
+
if (n[a] <= h.tmin)
|
|
552
|
+
n[a] = f(n[a] + f(f(h.tmin - f(FORWARD_SCALE * n[a])) + FORWARD_BIAS));
|
|
553
|
+
h.tmin = n[a];
|
|
554
|
+
n[a] = f(n[a] + f(h.dim * h.delta[a]));
|
|
555
|
+
h.voxel[a] = (h.voxel[a] + h.dim * h.step[a]) | 0;
|
|
556
|
+
return h.tmin <= h.tmax;
|
|
557
|
+
}
|
|
558
|
+
/** The grid's index bbox (root bbox, inclusive): the pool record's `indexBBoxMin/Max`. */
|
|
559
|
+
export function indexBBox(gridWords) {
|
|
560
|
+
const g = grid(gridWords);
|
|
561
|
+
const i = (a) => u32(g.words, a) | 0;
|
|
562
|
+
return {
|
|
563
|
+
min: [i(g.root + ROOT_OFF_BBOX_MIN), i(g.root + ROOT_OFF_BBOX_MIN + 4), i(g.root + ROOT_OFF_BBOX_MIN + 8)],
|
|
564
|
+
max: [i(g.root + ROOT_OFF_BBOX_MAX), i(g.root + ROOT_OFF_BBOX_MAX + 4), i(g.root + ROOT_OFF_BBOX_MAX + 8)],
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Twin of `vdbRayClip(g, o, d, &t)`: clip `[t0, t1]` to the voxel-cell box
|
|
569
|
+
* `[min, max + 1]` (vendored `hdda_ray_clip`); hit if the clipped interval is
|
|
570
|
+
* non-empty. NaN handling (an axis-parallel ray starting exactly on a slab
|
|
571
|
+
* plane) follows JS `Math.min/max`, which a GPU need not match.
|
|
572
|
+
*/
|
|
573
|
+
export function rayClip(gridWords, origin, direction, t) {
|
|
574
|
+
const { min, max } = indexBBox(gridWords);
|
|
575
|
+
return clipBox([min[0], min[1], min[2]], [max[0] + 1, max[1] + 1, max[2] + 1], origin, direction, t);
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Twin of the opt-in `vdbRayClipSupport(g, o, d, &t)` (helper
|
|
579
|
+
* `'rayClipSupport'`): clip `[t0, t1]` to the box where `vdbSample` can read
|
|
580
|
+
* the grid's voxels, `[min - 1, max + 1]` for trilinear and
|
|
581
|
+
* `[min - 0.5, max + 0.5]` for nearest. Unlike {@link rayClip}'s
|
|
582
|
+
* `[min, max + 1]` it keeps the min-side half of the trilinear support.
|
|
583
|
+
*/
|
|
584
|
+
export function rayClipSupport(gridWords, origin, direction, t, options = {}) {
|
|
585
|
+
const { min, max } = indexBBox(gridWords);
|
|
586
|
+
const pad = options.sampler === "nearest" ? 0.5 : 1;
|
|
587
|
+
return clipBox([f(min[0] - pad), f(min[1] - pad), f(min[2] - pad)], [f(max[0] + pad), f(max[1] + pad), f(max[2] + pad)], origin, direction, t);
|
|
588
|
+
}
|
|
589
|
+
/** The vendored `hdda_ray_clip` slab test against `[lo, hi]` (f32 box corners). */
|
|
590
|
+
function clipBox(lo, hi, origin, direction, t) {
|
|
591
|
+
const o = f3(origin);
|
|
592
|
+
const d = f3(direction);
|
|
593
|
+
const near = [];
|
|
594
|
+
const far = [];
|
|
595
|
+
for (let i = 0; i < 3; i++) {
|
|
596
|
+
const inv = f(1 / d[i]);
|
|
597
|
+
const a = f(f(lo[i] - o[i]) * inv);
|
|
598
|
+
const b = f(f(hi[i] - o[i]) * inv);
|
|
599
|
+
near.push(Math.min(a, b));
|
|
600
|
+
far.push(Math.max(a, b));
|
|
601
|
+
}
|
|
602
|
+
const tnear = Math.max(near[0], Math.max(near[1], near[2]));
|
|
603
|
+
const tfar = Math.min(far[0], Math.min(far[1], far[2]));
|
|
604
|
+
const hit = tnear <= tfar;
|
|
605
|
+
const t0 = Math.max(f(t[0]), tnear);
|
|
606
|
+
const t1 = Math.min(f(t[1]), tfar);
|
|
607
|
+
return { hit: hit && t0 <= t1, t0, t1 };
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Twin of the opt-in `vdbHddaCellEnd(&h)` (helper `'hddaCellEnd'`): the ray
|
|
611
|
+
* `t` where the HDDA's current cell ends, `min(next, tmax)`.
|
|
612
|
+
*/
|
|
613
|
+
export function hddaCellEnd(h) {
|
|
614
|
+
return Math.min(Math.min(h.next[0], h.next[1]), Math.min(h.next[2], h.tmax));
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Twin of the opt-in `vdbCellBoundTrilinear(acc, ijk, dim)` (helper
|
|
618
|
+
* `'cellBoundTrilinear'`): the max of {@link nodeMax} over the 2x2x2 block of
|
|
619
|
+
* aligned `dim`-cells whose min corner is the cell holding `ijk`. It bounds
|
|
620
|
+
* every trilinear sample whose base voxel `floor(p)` lies in that cell,
|
|
621
|
+
* provided every inactive leaf voxel is <= its leaf's max (stats bound active
|
|
622
|
+
* values only; true of fog volumes).
|
|
623
|
+
*/
|
|
624
|
+
export function cellBoundTrilinear(gridWords, ijk, dim, options = {}) {
|
|
625
|
+
let m = nodeMax(gridWords, ijk, dim, options);
|
|
626
|
+
for (let k = 1; k < 8; k++) {
|
|
627
|
+
const c = [ijk[0] + (k & 1) * dim, ijk[1] + ((k >> 1) & 1) * dim, ijk[2] + ((k >> 2) & 1) * dim];
|
|
628
|
+
m = Math.max(m, nodeMax(gridWords, c, dim, options));
|
|
629
|
+
}
|
|
630
|
+
return m;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Twin of the opt-in `vdbNodeAverage(acc, ijk, dim)` (helper `'nodeAverage'`,
|
|
634
|
+
* K3.2): the box mean of the aligned `dim`-cell holding `ijk` from node
|
|
635
|
+
* statistics. A cell inside one tile (or the background) is the tile's value;
|
|
636
|
+
* without stats (or `dim <= 1`) the value at `ijk`; `dim <= 8`: the leaf's
|
|
637
|
+
* `ave * activeVoxels / 512` (exact for fog leaves, whose inactive voxels are
|
|
638
|
+
* 0); larger: the lower node's `ave` (mean of its ACTIVE voxels; `dim` is meant
|
|
639
|
+
* to be 8 or 128). f32 arithmetic in WGSL order.
|
|
640
|
+
*/
|
|
641
|
+
export function nodeAverage(gridWords, ijk, dim) {
|
|
642
|
+
const g = grid(gridWords);
|
|
643
|
+
const path = locate(g, ijk);
|
|
644
|
+
const a = DIM_OF_LEVEL[path.level];
|
|
645
|
+
if ((a > 1 && dim <= a) || !g.hasStats || dim <= 1)
|
|
646
|
+
return vdbReadValueF32Cpu(gridWords, ijk);
|
|
647
|
+
if (dim <= 8) {
|
|
648
|
+
let n = 0;
|
|
649
|
+
for (let w = 0; w < 16; w++) {
|
|
650
|
+
let v = u32(g.words, path.leaf + LEAF_OFF_VALUE_MASK + 4 * w);
|
|
651
|
+
while (v) {
|
|
652
|
+
v &= v - 1;
|
|
653
|
+
n++;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return f(nodeStats(gridWords, 0, path.leaf).ave * f(n / 512));
|
|
657
|
+
}
|
|
658
|
+
return nodeStats(gridWords, 1, path.lower).ave;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* The canonical `march` walk, built only from the profile's calls (the GPU
|
|
662
|
+
* probe kernel in scripts/lib/march-probe.mjs is the same loop in WGSL):
|
|
663
|
+
*
|
|
664
|
+
* ```
|
|
665
|
+
* t = [tmin, tmax]; if !vdbRayClip(g, o, d, &t) { return; }
|
|
666
|
+
* vdbHddaInit(&h, o, t.x, d, t.y, max(vdbGetDim(&a, floor(o + d * t.x)), leafDim));
|
|
667
|
+
* loop {
|
|
668
|
+
* want = max(vdbGetDim(&a, h.voxel), leafDim); // probe the cell's corner
|
|
669
|
+
* if want != h.dim && updates < 2 { vdbHddaUpdate(&h, o, d, want); updates++; continue; }
|
|
670
|
+
* updates = 0;
|
|
671
|
+
* emit (h.voxel, h.dim, h.tmin, min(h.next, h.tmax), active, vdbNodeMax(&a, h.voxel, h.dim));
|
|
672
|
+
* if !vdbHddaStep(&h) { break; }
|
|
673
|
+
* }
|
|
674
|
+
* ```
|
|
675
|
+
*
|
|
676
|
+
* The corner decides the cell: a tile of size >= dim holding the corner holds
|
|
677
|
+
* the whole aligned cell. `vdbHddaUpdate` re-derives the cell from
|
|
678
|
+
* `floor(o + d * h.tmin)`, which on the entry face can name the previous cell;
|
|
679
|
+
* that yields a zero-length cell and the vendored forward-stepping moves on.
|
|
680
|
+
* Every emitted cell is classified from its own corner, so classification is
|
|
681
|
+
* valid even for those. At most two updates per cell keep the loop finite.
|
|
682
|
+
* `vdbHddaStep` continues while `tmin <= tmax`, so the last cell can be a
|
|
683
|
+
* zero-length one at the exit face.
|
|
684
|
+
*/
|
|
685
|
+
export function hddaWalk(gridWords, origin, direction, options = {}) {
|
|
686
|
+
const leafDim = options.leafDim ?? 8;
|
|
687
|
+
const threshold = options.threshold ?? -Infinity;
|
|
688
|
+
const maxSteps = options.maxSteps ?? 1 << 16;
|
|
689
|
+
const o = f3(origin);
|
|
690
|
+
const d = f3(direction);
|
|
691
|
+
const clip = rayClip(gridWords, o, d, [options.tmin ?? 0, options.tmax ?? 3.4e38]);
|
|
692
|
+
if (!clip.hit)
|
|
693
|
+
return [];
|
|
694
|
+
const cellDim = (ijk) => Math.max(getDim(gridWords, ijk), leafDim);
|
|
695
|
+
const start = rayStart(o, clip.t0, d);
|
|
696
|
+
const h = hddaInit(o, clip.t0, d, clip.t1, cellDim([Math.floor(start[0]), Math.floor(start[1]), Math.floor(start[2])]));
|
|
697
|
+
const out = [];
|
|
698
|
+
let updates = 0;
|
|
699
|
+
for (let i = 0; i < maxSteps; i++) {
|
|
700
|
+
const a = getDim(gridWords, h.voxel);
|
|
701
|
+
const want = Math.max(a, leafDim);
|
|
702
|
+
if (want !== h.dim && updates < 2) {
|
|
703
|
+
hddaUpdate(h, o, d, want);
|
|
704
|
+
updates++;
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
updates = 0;
|
|
708
|
+
const voxel = [h.voxel[0], h.voxel[1], h.voxel[2]];
|
|
709
|
+
const active = a >= h.dim ? isActive(gridWords, voxel) : true;
|
|
710
|
+
const max = nodeMax(gridWords, voxel, h.dim, options.valueMax === undefined ? {} : { valueMax: options.valueMax });
|
|
711
|
+
out.push({
|
|
712
|
+
level: a === 1 ? 0 : a === 8 ? 1 : a === 128 ? 2 : 3,
|
|
713
|
+
dim: h.dim,
|
|
714
|
+
voxel,
|
|
715
|
+
t0: h.tmin,
|
|
716
|
+
t1: hddaCellEnd(h),
|
|
717
|
+
active,
|
|
718
|
+
max,
|
|
719
|
+
skip: !active || max < threshold,
|
|
720
|
+
});
|
|
721
|
+
if (!hddaStep(h))
|
|
722
|
+
break;
|
|
723
|
+
}
|
|
724
|
+
return out;
|
|
725
|
+
}
|
|
726
|
+
//# sourceMappingURL=march.js.map
|