@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,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* parse.ts — top-level `.vdb` container reader (docs/archive/v1/SPEC.md §4).
|
|
3
|
+
*
|
|
4
|
+
* File layout (format facts cross-checked between `mjurczyk/openvdb`'s
|
|
5
|
+
* `OpenVDBReader`/`GridDescriptor` and `vdb-rs`'s `VdbReader::new`/
|
|
6
|
+
* `read_grid_descriptors`/`read_grid_internal`):
|
|
7
|
+
*
|
|
8
|
+
* magic(u64) file_version(u32) [lib_major(u32) lib_minor(u32)]
|
|
9
|
+
* has_grid_offsets(u8) [is_compressed(u8) if 220<=v<222] guid(36 chars)
|
|
10
|
+
* metadata_map grid_count(u32)
|
|
11
|
+
* grid_count x {
|
|
12
|
+
* unique_name type_name [instance_parent] grid_pos(u64) block_pos(u64) end_pos(u64)
|
|
13
|
+
* -- seek to grid_pos --
|
|
14
|
+
* [compression(u32) if v>=222] metadata_map transform tree_topology tree_buffers
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* Unlike both references' lazy/two-pass grid-descriptor tables (built for
|
|
18
|
+
* random access to a single named grid), `parseVdb` decodes every grid in
|
|
19
|
+
* one linear pass and defensively re-seeks to each descriptor's `end_pos`
|
|
20
|
+
* afterward — the `mjurczyk/openvdb` reader does the same "hack" for
|
|
21
|
+
* multi-grid files, and it's cheap insurance against any of our own
|
|
22
|
+
* byte-accounting bugs desyncing the stream for the next grid.
|
|
23
|
+
*/
|
|
24
|
+
import { ByteReader } from "./byte-reader.js";
|
|
25
|
+
import { compressionFromBits, FLOAT_FORMAT, HALF_FORMAT, PTDATAIDX32_FORMAT, VEC3D_FORMAT, VEC3I_FORMAT, VEC3S_FORMAT, } from "./compression.js";
|
|
26
|
+
import { VdbFormatError, VDBUnsupportedError } from "./errors.js";
|
|
27
|
+
import { createVdbGrid } from "./grid.js";
|
|
28
|
+
import { readMetadataMap } from "./metadata.js";
|
|
29
|
+
import { readTransform } from "./transform.js";
|
|
30
|
+
import { readTree } from "./tree.js";
|
|
31
|
+
const MAGIC_LOW = 0x56444220; // 'V','D','B',' ' read little-endian, low 32 bits
|
|
32
|
+
const MIN_SUPPORTED_VERSION = 213; // OPENVDB_FILE_VERSION_ROOTNODE_MAP
|
|
33
|
+
/**
|
|
34
|
+
* OPENVDB_FILE_VERSION (225, `OPENVDB_FILE_VERSION_HALF_GRID`), still current in OpenVDB v14.0.0.
|
|
35
|
+
* A newer file fails with `VDBUnsupportedError` before anything after the header is read: a
|
|
36
|
+
* future layout could misparse silently. OpenVDB 13.2+ warns for 226-299 and rejects 300+
|
|
37
|
+
* (`OPENVDB_UNSUPPORTED_FILE_VERSION`); we reject from 226 (DIVERGES V71).
|
|
38
|
+
*/
|
|
39
|
+
const MAX_SUPPORTED_VERSION = 225;
|
|
40
|
+
const VERSION_GRID_INSTANCING = 216;
|
|
41
|
+
const VERSION_BOOST_UUID = 218;
|
|
42
|
+
const VERSION_SELECTIVE_COMPRESSION = 220;
|
|
43
|
+
const VERSION_NODE_MASK_COMPRESSION = 222;
|
|
44
|
+
const VERSION_BLOSC_COMPRESSION = 223;
|
|
45
|
+
const GRID_TYPE_RE = /^Tree_([A-Za-z0-9]+)_(\d+)_(\d+)_(\d+)$/;
|
|
46
|
+
/** On-disk value types this parser reads (the `<valueType>` of the grid type), and their layout. */
|
|
47
|
+
const VALUE_FORMATS = {
|
|
48
|
+
float: FLOAT_FORMAT,
|
|
49
|
+
vec3s: VEC3S_FORMAT,
|
|
50
|
+
vec3d: VEC3D_FORMAT,
|
|
51
|
+
vec3i: VEC3I_FORMAT,
|
|
52
|
+
ptdataidx32: PTDATAIDX32_FORMAT,
|
|
53
|
+
// K7.C: OpenVDB 13+ `HalfGrid`. Values widen exactly to f32, so it parses as a float grid
|
|
54
|
+
// (`valueType: "float"`, `gridType` keeps `Tree_half_5_4_3`; DIVERGES V70).
|
|
55
|
+
half: HALF_FORMAT,
|
|
56
|
+
};
|
|
57
|
+
/** The parsed grid's `valueType` for each on-disk value type. */
|
|
58
|
+
const PARSED_VALUE_TYPE = {
|
|
59
|
+
float: "float",
|
|
60
|
+
vec3s: "vec3s",
|
|
61
|
+
vec3d: "vec3d",
|
|
62
|
+
vec3i: "vec3i",
|
|
63
|
+
ptdataidx32: "ptdataidx32",
|
|
64
|
+
half: "float",
|
|
65
|
+
};
|
|
66
|
+
function isSupportedValueType(t) {
|
|
67
|
+
return Object.prototype.hasOwnProperty.call(VALUE_FORMATS, t);
|
|
68
|
+
}
|
|
69
|
+
function readHeaderCompression(reader, fileVersion) {
|
|
70
|
+
let compression = { zip: false, activeMask: true, blosc: true }; // DEFAULT_COMPRESSION
|
|
71
|
+
if (fileVersion < VERSION_BLOSC_COMPRESSION) {
|
|
72
|
+
compression = { zip: true, activeMask: true, blosc: false };
|
|
73
|
+
}
|
|
74
|
+
if (fileVersion >= VERSION_SELECTIVE_COMPRESSION && fileVersion < VERSION_NODE_MASK_COMPRESSION) {
|
|
75
|
+
const isCompressed = reader.bool();
|
|
76
|
+
compression = isCompressed
|
|
77
|
+
? { zip: true, activeMask: false, blosc: false }
|
|
78
|
+
: { zip: false, activeMask: false, blosc: false };
|
|
79
|
+
}
|
|
80
|
+
return compression;
|
|
81
|
+
}
|
|
82
|
+
function readBBoxFromMetadata(metadata) {
|
|
83
|
+
const min = metadata["file_bbox_min"];
|
|
84
|
+
const max = metadata["file_bbox_max"];
|
|
85
|
+
if (Array.isArray(min) && Array.isArray(max) && min.length === 3 && max.length === 3) {
|
|
86
|
+
return {
|
|
87
|
+
min: [min[0], min[1], min[2]],
|
|
88
|
+
max: [max[0], max[1], max[2]],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Parses an OpenVDB `.vdb` file (float, half, vec3 and point data grids) into trees you can read, iterate or
|
|
95
|
+
* convert to NanoVDB. Returns the decoded `grids` and a `descriptors` entry for every grid in the file.
|
|
96
|
+
* Throws `VdbFormatError` for a malformed buffer, `VDBUnsupportedError` for unsupported constructs (without
|
|
97
|
+
* `select`; with it, an unsupported grid is reported in its descriptor). See {@link ParseVdbOptions.select} to list
|
|
98
|
+
* grids cheaply or decode only some of them.
|
|
99
|
+
*
|
|
100
|
+
* @param buffer The file's bytes.
|
|
101
|
+
* @param options `select`: which grids to decode.
|
|
102
|
+
*/
|
|
103
|
+
export function parseVdb(buffer, options = {}) {
|
|
104
|
+
const reader = new ByteReader(buffer);
|
|
105
|
+
if (reader.length < 8) {
|
|
106
|
+
throw new VdbFormatError("buffer too short to contain the magic number");
|
|
107
|
+
}
|
|
108
|
+
const magicLow = reader.u32();
|
|
109
|
+
const magicHigh = reader.u32();
|
|
110
|
+
if (magicLow !== MAGIC_LOW || magicHigh !== 0) {
|
|
111
|
+
throw new VdbFormatError(`bad magic number (expected 0x${MAGIC_LOW.toString(16)}, got 0x${magicLow.toString(16)}) — not a .vdb file`);
|
|
112
|
+
}
|
|
113
|
+
const fileVersion = reader.u32();
|
|
114
|
+
if (fileVersion < MIN_SUPPORTED_VERSION) {
|
|
115
|
+
throw new VDBUnsupportedError(`file version ${fileVersion} is older than the minimum supported version ${MIN_SUPPORTED_VERSION}`);
|
|
116
|
+
}
|
|
117
|
+
if (fileVersion > MAX_SUPPORTED_VERSION) {
|
|
118
|
+
throw new VDBUnsupportedError(`file version ${fileVersion} is newer than the maximum supported version ${MAX_SUPPORTED_VERSION} ` +
|
|
119
|
+
`(the file was written by a newer OpenVDB; OpenVDB v14 still writes ${MAX_SUPPORTED_VERSION}). ` +
|
|
120
|
+
`Re-save it with OpenVDB 14 or earlier.`);
|
|
121
|
+
}
|
|
122
|
+
reader.u32(); // library version major (informational only)
|
|
123
|
+
reader.u32(); // library version minor (informational only)
|
|
124
|
+
const hasGridOffsets = reader.bool();
|
|
125
|
+
if (!hasGridOffsets) {
|
|
126
|
+
throw new VDBUnsupportedError("VDB streams without grid offsets are not supported");
|
|
127
|
+
}
|
|
128
|
+
const headerCompression = readHeaderCompression(reader, fileVersion);
|
|
129
|
+
if (fileVersion < VERSION_BOOST_UUID) {
|
|
130
|
+
throw new VDBUnsupportedError(`file version ${fileVersion} predates the Boost-UUID header layout (< 218)`);
|
|
131
|
+
}
|
|
132
|
+
reader.fixedString(36); // uuid (informational only)
|
|
133
|
+
readMetadataMap(reader); // file-level metadata (informational only)
|
|
134
|
+
const gridCount = reader.u32();
|
|
135
|
+
const grids = [];
|
|
136
|
+
const descriptors = [];
|
|
137
|
+
const select = options.select;
|
|
138
|
+
const strict = !select;
|
|
139
|
+
for (let i = 0; i < gridCount; i++) {
|
|
140
|
+
const uniqueName = reader.string();
|
|
141
|
+
const name = uniqueName.split("\x1e")[0] ?? uniqueName;
|
|
142
|
+
let gridType = reader.string();
|
|
143
|
+
let savedAsHalfFloat = false;
|
|
144
|
+
if (gridType.includes("_HalfFloat")) {
|
|
145
|
+
savedAsHalfFloat = true;
|
|
146
|
+
gridType = gridType.split("_HalfFloat").join("");
|
|
147
|
+
}
|
|
148
|
+
let instanceParentName = "";
|
|
149
|
+
if (fileVersion >= VERSION_GRID_INSTANCING) {
|
|
150
|
+
instanceParentName = reader.string();
|
|
151
|
+
}
|
|
152
|
+
const instanced = instanceParentName !== "";
|
|
153
|
+
if (instanced && strict) {
|
|
154
|
+
throw new VDBUnsupportedError(`grid "${name}": instanced grids (sharing another grid's tree) are not supported`);
|
|
155
|
+
}
|
|
156
|
+
const gridPos = reader.u64AsNumber();
|
|
157
|
+
const blockPos = reader.u64AsNumber();
|
|
158
|
+
void blockPos; // not needed: we read topology+buffers in one contiguous pass
|
|
159
|
+
const endPos = reader.u64AsNumber();
|
|
160
|
+
reader.seek(gridPos);
|
|
161
|
+
const compression = fileVersion >= VERSION_NODE_MASK_COMPRESSION
|
|
162
|
+
? compressionFromBits(reader.u32())
|
|
163
|
+
: headerCompression;
|
|
164
|
+
const metadata = readMetadataMap(reader);
|
|
165
|
+
const useHalf = savedAsHalfFloat || metadata["is_saved_as_half_float"] === true;
|
|
166
|
+
const indexBBox = readBBoxFromMetadata(metadata);
|
|
167
|
+
const gridClass = typeof metadata["class"] === "string" ? metadata["class"] : "";
|
|
168
|
+
// Why this grid cannot be decoded, or null. Strict mode (no `select`) throws it; report mode records it.
|
|
169
|
+
let unsupported = null;
|
|
170
|
+
let valueType = "";
|
|
171
|
+
const match = GRID_TYPE_RE.exec(gridType);
|
|
172
|
+
if (instanced) {
|
|
173
|
+
unsupported = "instanced grids (sharing another grid's tree) are not supported";
|
|
174
|
+
}
|
|
175
|
+
else if (!match) {
|
|
176
|
+
unsupported = `unrecognized grid type "${gridType}" (expected "Tree_<valueType>_<log2dim>_<log2dim>_<log2dim>")`;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const [, vt, d0, d1, d2] = match;
|
|
180
|
+
valueType = vt;
|
|
181
|
+
if (!isSupportedValueType(valueType)) {
|
|
182
|
+
unsupported = `value type "${valueType}" is not supported (supported: ${Object.keys(VALUE_FORMATS).join(", ")})`;
|
|
183
|
+
}
|
|
184
|
+
else if (d0 !== "5" || d1 !== "4" || d2 !== "3") {
|
|
185
|
+
unsupported = `tree configuration ${d0}-${d1}-${d2} is not supported (only the 5-4-3 tree is in scope)`;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (unsupported !== null && strict)
|
|
189
|
+
throw new VDBUnsupportedError(`grid "${name}": ${unsupported}`);
|
|
190
|
+
let transform = null;
|
|
191
|
+
if (unsupported === null) {
|
|
192
|
+
try {
|
|
193
|
+
transform = readTransform(reader);
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
if (strict || !(e instanceof VDBUnsupportedError))
|
|
197
|
+
throw e;
|
|
198
|
+
unsupported = `transform: ${e.message}`;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const descriptor = {
|
|
202
|
+
name,
|
|
203
|
+
gridType,
|
|
204
|
+
valueType,
|
|
205
|
+
gridClass,
|
|
206
|
+
transform,
|
|
207
|
+
indexBBox,
|
|
208
|
+
compression: { zip: compression.zip, activeMask: compression.activeMask, blosc: compression.blosc },
|
|
209
|
+
unsupported,
|
|
210
|
+
};
|
|
211
|
+
descriptors.push(descriptor);
|
|
212
|
+
if (unsupported === null && transform !== null && (select === undefined || select(descriptor))) {
|
|
213
|
+
const vt = valueType;
|
|
214
|
+
const { background, leaves, tiles, activeVoxelCount, pointLeaves, pointOutputBudget } = readTree(reader, {
|
|
215
|
+
fileVersion,
|
|
216
|
+
compression,
|
|
217
|
+
useHalf,
|
|
218
|
+
format: VALUE_FORMATS[vt],
|
|
219
|
+
pointData: vt === "ptdataidx32",
|
|
220
|
+
});
|
|
221
|
+
grids.push(createVdbGrid({
|
|
222
|
+
name,
|
|
223
|
+
gridType,
|
|
224
|
+
valueType: PARSED_VALUE_TYPE[vt],
|
|
225
|
+
transform,
|
|
226
|
+
metadata,
|
|
227
|
+
indexBBox,
|
|
228
|
+
activeVoxelCount,
|
|
229
|
+
background,
|
|
230
|
+
leaves,
|
|
231
|
+
tiles,
|
|
232
|
+
...(pointLeaves ? { pointLeaves, pointOutputBudget } : {}),
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
// Defensive re-sync (matches the `mjurczyk/openvdb` reader's own hack):
|
|
236
|
+
// land exactly on the next grid descriptor regardless of any drift.
|
|
237
|
+
reader.seek(endPos);
|
|
238
|
+
}
|
|
239
|
+
return { fileVersion, grids, descriptors };
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/tools/vdb/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,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AAU,CAAC,CAAC,EAAE,CAAC;YAC/F,MAAM,EAAE,GAAG,SAA4B,CAAC;YACxC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE;gBACvG,WAAW;gBACX,WAAW;gBACX,OAAO;gBACP,MAAM,EAAE,aAAa,CAAC,EAAE,CAAC;gBACzB,SAAS,EAAE,EAAE,KAAK,aAAa;aAChC,CAAC,CAAC;YAEH,KAAK,CAAC,IAAI,CACR,aAAa,CAAC;gBACZ,IAAI;gBACJ,QAAQ;gBACR,SAAS,EAAE,iBAAiB,CAAC,EAAE,CAAC;gBAChC,SAAS;gBACT,QAAQ;gBACR,SAAS;gBACT,gBAAgB;gBAChB,UAAU;gBACV,MAAM;gBACN,KAAK;gBACL,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC3D,CAAC,CACH,CAAC;QACJ,CAAC;QAED,wEAAwE;QACxE,oEAAoE;QACpE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["/**\n * parse.ts — top-level `.vdb` container reader (docs/archive/v1/SPEC.md §4).\n *\n * File layout (format facts cross-checked between `mjurczyk/openvdb`'s\n * `OpenVDBReader`/`GridDescriptor` and `vdb-rs`'s `VdbReader::new`/\n * `read_grid_descriptors`/`read_grid_internal`):\n *\n * magic(u64) file_version(u32) [lib_major(u32) lib_minor(u32)]\n * has_grid_offsets(u8) [is_compressed(u8) if 220<=v<222] guid(36 chars)\n * metadata_map grid_count(u32)\n * grid_count x {\n * unique_name type_name [instance_parent] grid_pos(u64) block_pos(u64) end_pos(u64)\n * -- seek to grid_pos --\n * [compression(u32) if v>=222] metadata_map transform tree_topology tree_buffers\n * }\n *\n * Unlike both references' lazy/two-pass grid-descriptor tables (built for\n * random access to a single named grid), `parseVdb` decodes every grid in\n * one linear pass and defensively re-seeks to each descriptor's `end_pos`\n * afterward — the `mjurczyk/openvdb` reader does the same \"hack\" for\n * multi-grid files, and it's cheap insurance against any of our own\n * byte-accounting bugs desyncing the stream for the next grid.\n */\n\nimport { ByteReader } from \"./byte-reader.js\";\nimport type { CompressionFlags, ValueFormat } from \"./compression.js\";\nimport {\n compressionFromBits,\n FLOAT_FORMAT,\n HALF_FORMAT,\n PTDATAIDX32_FORMAT,\n VEC3D_FORMAT,\n VEC3I_FORMAT,\n VEC3S_FORMAT,\n} from \"./compression.js\";\nimport { VdbFormatError, VDBUnsupportedError } from \"./errors.js\";\nimport { createVdbGrid } from \"./grid.js\";\nimport { readMetadataMap } from \"./metadata.js\";\nimport { readTransform } from \"./transform.js\";\nimport { readTree } from \"./tree.js\";\nimport type { VdbBBox, VdbFile, VdbGrid, VdbGridDescriptor, VdbTransformInfo, VdbValueType } from \"./types.js\";\n\nconst MAGIC_LOW = 0x56444220; // 'V','D','B',' ' read little-endian, low 32 bits\nconst MIN_SUPPORTED_VERSION = 213; // OPENVDB_FILE_VERSION_ROOTNODE_MAP\n/**\n * OPENVDB_FILE_VERSION (225, `OPENVDB_FILE_VERSION_HALF_GRID`), still current in OpenVDB v14.0.0.\n * A newer file fails with `VDBUnsupportedError` before anything after the header is read: a\n * future layout could misparse silently. OpenVDB 13.2+ warns for 226-299 and rejects 300+\n * (`OPENVDB_UNSUPPORTED_FILE_VERSION`); we reject from 226 (DIVERGES V71).\n */\nconst MAX_SUPPORTED_VERSION = 225;\nconst VERSION_GRID_INSTANCING = 216;\nconst VERSION_BOOST_UUID = 218;\nconst VERSION_SELECTIVE_COMPRESSION = 220;\nconst VERSION_NODE_MASK_COMPRESSION = 222;\nconst VERSION_BLOSC_COMPRESSION = 223;\n\nconst GRID_TYPE_RE = /^Tree_([A-Za-z0-9]+)_(\\d+)_(\\d+)_(\\d+)$/;\n\n/** On-disk value types this parser reads (the `<valueType>` of the grid type), and their layout. */\nconst VALUE_FORMATS = {\n float: FLOAT_FORMAT,\n vec3s: VEC3S_FORMAT,\n vec3d: VEC3D_FORMAT,\n vec3i: VEC3I_FORMAT,\n ptdataidx32: PTDATAIDX32_FORMAT,\n // K7.C: OpenVDB 13+ `HalfGrid`. Values widen exactly to f32, so it parses as a float grid\n // (`valueType: \"float\"`, `gridType` keeps `Tree_half_5_4_3`; DIVERGES V70).\n half: HALF_FORMAT,\n} as const satisfies Record<string, ValueFormat>;\n\ntype OnDiskValueType = keyof typeof VALUE_FORMATS;\n\n/** The parsed grid's `valueType` for each on-disk value type. */\nconst PARSED_VALUE_TYPE: Record<OnDiskValueType, VdbValueType> = {\n float: \"float\",\n vec3s: \"vec3s\",\n vec3d: \"vec3d\",\n vec3i: \"vec3i\",\n ptdataidx32: \"ptdataidx32\",\n half: \"float\",\n};\n\nfunction isSupportedValueType(t: string): t is OnDiskValueType {\n return Object.prototype.hasOwnProperty.call(VALUE_FORMATS, t);\n}\n\nfunction readHeaderCompression(reader: ByteReader, fileVersion: number): CompressionFlags {\n let compression: CompressionFlags = { zip: false, activeMask: true, blosc: true }; // DEFAULT_COMPRESSION\n if (fileVersion < VERSION_BLOSC_COMPRESSION) {\n compression = { zip: true, activeMask: true, blosc: false };\n }\n if (fileVersion >= VERSION_SELECTIVE_COMPRESSION && fileVersion < VERSION_NODE_MASK_COMPRESSION) {\n const isCompressed = reader.bool();\n compression = isCompressed\n ? { zip: true, activeMask: false, blosc: false }\n : { zip: false, activeMask: false, blosc: false };\n }\n return compression;\n}\n\nfunction readBBoxFromMetadata(metadata: Record<string, unknown>): VdbBBox | null {\n const min = metadata[\"file_bbox_min\"];\n const max = metadata[\"file_bbox_max\"];\n if (Array.isArray(min) && Array.isArray(max) && min.length === 3 && max.length === 3) {\n return {\n min: [min[0], min[1], min[2]] as [number, number, number],\n max: [max[0], max[1], max[2]] as [number, number, number],\n };\n }\n return null;\n}\n\nexport interface ParseVdbOptions {\n /**\n * Called for every grid once its header (name, type, metadata, transform) is read, before its tree. Return `false`\n * to skip decoding that grid; it still appears in `VdbFile.descriptors`. Passing `select` also switches the\n * parser to report mode: a grid it cannot decode (unsupported value type, tree layout, transform or instancing)\n * is listed with `descriptor.unsupported` set and skipped, instead of throwing. `select` is not called for it.\n *\n * Without `select`, every grid is decoded and an unsupported grid throws `VDBUnsupportedError`, as before.\n * `select: () => false` is a cheap listing pass: no tree is decoded or decompressed.\n */\n select?: (descriptor: VdbGridDescriptor) => boolean;\n}\n\n/**\n * Parses an OpenVDB `.vdb` file (float, half, vec3 and point data grids) into trees you can read, iterate or\n * convert to NanoVDB. Returns the decoded `grids` and a `descriptors` entry for every grid in the file.\n * Throws `VdbFormatError` for a malformed buffer, `VDBUnsupportedError` for unsupported constructs (without\n * `select`; with it, an unsupported grid is reported in its descriptor). See {@link ParseVdbOptions.select} to list\n * grids cheaply or decode only some of them.\n *\n * @param buffer The file's bytes.\n * @param options `select`: which grids to decode.\n */\nexport function parseVdb(buffer: ArrayBuffer, options: ParseVdbOptions = {}): VdbFile {\n const reader = new ByteReader(buffer);\n\n if (reader.length < 8) {\n throw new VdbFormatError(\"buffer too short to contain the magic number\");\n }\n const magicLow = reader.u32();\n const magicHigh = reader.u32();\n if (magicLow !== MAGIC_LOW || magicHigh !== 0) {\n throw new VdbFormatError(\n `bad magic number (expected 0x${MAGIC_LOW.toString(16)}, got 0x${magicLow.toString(16)}) — not a .vdb file`,\n );\n }\n\n const fileVersion = reader.u32();\n if (fileVersion < MIN_SUPPORTED_VERSION) {\n throw new VDBUnsupportedError(\n `file version ${fileVersion} is older than the minimum supported version ${MIN_SUPPORTED_VERSION}`,\n );\n }\n\n if (fileVersion > MAX_SUPPORTED_VERSION) {\n throw new VDBUnsupportedError(\n `file version ${fileVersion} is newer than the maximum supported version ${MAX_SUPPORTED_VERSION} ` +\n `(the file was written by a newer OpenVDB; OpenVDB v14 still writes ${MAX_SUPPORTED_VERSION}). ` +\n `Re-save it with OpenVDB 14 or earlier.`,\n );\n }\n\n reader.u32(); // library version major (informational only)\n reader.u32(); // library version minor (informational only)\n\n const hasGridOffsets = reader.bool();\n if (!hasGridOffsets) {\n throw new VDBUnsupportedError(\"VDB streams without grid offsets are not supported\");\n }\n\n const headerCompression = readHeaderCompression(reader, fileVersion);\n\n if (fileVersion < VERSION_BOOST_UUID) {\n throw new VDBUnsupportedError(`file version ${fileVersion} predates the Boost-UUID header layout (< 218)`);\n }\n reader.fixedString(36); // uuid (informational only)\n\n readMetadataMap(reader); // file-level metadata (informational only)\n\n const gridCount = reader.u32();\n const grids: VdbGrid[] = [];\n const descriptors: VdbGridDescriptor[] = [];\n const select = options.select;\n const strict = !select;\n\n for (let i = 0; i < gridCount; i++) {\n const uniqueName = reader.string();\n const name = uniqueName.split(\"\\x1e\")[0] ?? uniqueName;\n let gridType = reader.string();\n\n let savedAsHalfFloat = false;\n if (gridType.includes(\"_HalfFloat\")) {\n savedAsHalfFloat = true;\n gridType = gridType.split(\"_HalfFloat\").join(\"\");\n }\n\n let instanceParentName = \"\";\n if (fileVersion >= VERSION_GRID_INSTANCING) {\n instanceParentName = reader.string();\n }\n const instanced = instanceParentName !== \"\";\n if (instanced && strict) {\n throw new VDBUnsupportedError(`grid \"${name}\": instanced grids (sharing another grid's tree) are not supported`);\n }\n\n const gridPos = reader.u64AsNumber();\n const blockPos = reader.u64AsNumber();\n void blockPos; // not needed: we read topology+buffers in one contiguous pass\n const endPos = reader.u64AsNumber();\n\n reader.seek(gridPos);\n\n const compression =\n fileVersion >= VERSION_NODE_MASK_COMPRESSION\n ? compressionFromBits(reader.u32())\n : headerCompression;\n\n const metadata = readMetadataMap(reader);\n const useHalf = savedAsHalfFloat || metadata[\"is_saved_as_half_float\"] === true;\n\n const indexBBox = readBBoxFromMetadata(metadata);\n const gridClass = typeof metadata[\"class\"] === \"string\" ? (metadata[\"class\"] as string) : \"\";\n\n // Why this grid cannot be decoded, or null. Strict mode (no `select`) throws it; report mode records it.\n let unsupported: string | null = null;\n let valueType = \"\";\n const match = GRID_TYPE_RE.exec(gridType);\n if (instanced) {\n unsupported = \"instanced grids (sharing another grid's tree) are not supported\";\n } else if (!match) {\n unsupported = `unrecognized grid type \"${gridType}\" (expected \"Tree_<valueType>_<log2dim>_<log2dim>_<log2dim>\")`;\n } else {\n const [, vt, d0, d1, d2] = match;\n valueType = vt!;\n if (!isSupportedValueType(valueType)) {\n unsupported = `value type \"${valueType}\" is not supported (supported: ${Object.keys(VALUE_FORMATS).join(\", \")})`;\n } else if (d0 !== \"5\" || d1 !== \"4\" || d2 !== \"3\") {\n unsupported = `tree configuration ${d0}-${d1}-${d2} is not supported (only the 5-4-3 tree is in scope)`;\n }\n }\n if (unsupported !== null && strict) throw new VDBUnsupportedError(`grid \"${name}\": ${unsupported}`);\n\n let transform: VdbTransformInfo | null = null;\n if (unsupported === null) {\n try {\n transform = readTransform(reader);\n } catch (e) {\n if (strict || !(e instanceof VDBUnsupportedError)) throw e;\n unsupported = `transform: ${e.message}`;\n }\n }\n\n const descriptor: VdbGridDescriptor = {\n name,\n gridType,\n valueType,\n gridClass,\n transform,\n indexBBox,\n compression: { zip: compression.zip, activeMask: compression.activeMask, blosc: compression.blosc },\n unsupported,\n };\n descriptors.push(descriptor);\n\n if (unsupported === null && transform !== null && (select === undefined || select(descriptor))) {\n const vt = valueType as OnDiskValueType;\n const { background, leaves, tiles, activeVoxelCount, pointLeaves, pointOutputBudget } = readTree(reader, {\n fileVersion,\n compression,\n useHalf,\n format: VALUE_FORMATS[vt],\n pointData: vt === \"ptdataidx32\",\n });\n\n grids.push(\n createVdbGrid({\n name,\n gridType,\n valueType: PARSED_VALUE_TYPE[vt],\n transform,\n metadata,\n indexBBox,\n activeVoxelCount,\n background,\n leaves,\n tiles,\n ...(pointLeaves ? { pointLeaves, pointOutputBudget } : {}),\n }),\n );\n }\n\n // Defensive re-sync (matches the `mjurczyk/openvdb` reader's own hack):\n // land exactly on the next grid descriptor regardless of any drift.\n reader.seek(endPos);\n }\n\n return { fileVersion, grids, descriptors };\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { VdbPointAttributeArray, VdbPointDataGrid } from "./types.js";
|
|
2
|
+
/** One extra attribute carried by {@link VDBPointRenderData}: values in the kept points' order. */
|
|
3
|
+
export interface VDBPointRenderAttribute {
|
|
4
|
+
/** `count * components` values, the decoder's element type (real attributes are `Float32Array`, `double` `Float64Array`). */
|
|
5
|
+
values: VdbPointAttributeArray;
|
|
6
|
+
/** Values per point (vector components times the attribute's stride). */
|
|
7
|
+
components: number;
|
|
8
|
+
}
|
|
9
|
+
/** What `VDBPoints` draws: world positions (xyz per point), optional linear RGB, the mean spacing. */
|
|
10
|
+
export interface VDBPointRenderData {
|
|
11
|
+
/** Points in the arrays. */
|
|
12
|
+
count: number;
|
|
13
|
+
/** Points in the grid before the stride. */
|
|
14
|
+
totalCount: number;
|
|
15
|
+
/** Every `stride`-th point (in the grid's point order) is kept; 1 below `maxPoints`. */
|
|
16
|
+
stride: number;
|
|
17
|
+
/** Mean distance between the kept points in world units: `voxelSize / cbrt(points per active voxel) * cbrt(stride)`. */
|
|
18
|
+
spacing: number;
|
|
19
|
+
/** World positions, `count * 3`. */
|
|
20
|
+
positions: Float32Array;
|
|
21
|
+
/** `Cd` per point (`count * 3`), or null when the grid has no 3-component real `Cd`. */
|
|
22
|
+
colors: Float32Array | null;
|
|
23
|
+
/** The attributes asked for with `attributes` that the grid has, in the same order as `positions`. */
|
|
24
|
+
attributes: Record<string, VDBPointRenderAttribute>;
|
|
25
|
+
/**
|
|
26
|
+
* `order: 'prefix'` only: `prefix[k]` (k = 0..10) is how many points the first k tenths of the arrays hold.
|
|
27
|
+
* `prefix[1]` is every 10th kept point, `prefix[5]` every 2nd, `prefix[10]` = `count`. Null for `order: 'grid'`.
|
|
28
|
+
*/
|
|
29
|
+
prefix: number[] | null;
|
|
30
|
+
/** Box of the kept positions (world units), or null without points. */
|
|
31
|
+
bounds: {
|
|
32
|
+
min: [number, number, number];
|
|
33
|
+
max: [number, number, number];
|
|
34
|
+
} | null;
|
|
35
|
+
}
|
|
36
|
+
/** Progress of {@link vdbPointRenderData}: the decode (per leaf of the grid), then the copy into render order. */
|
|
37
|
+
export interface VDBPointRenderDataProgress {
|
|
38
|
+
/** `'decode'`: the grid's attribute arrays (skipped when `grid.points()` already ran); `'copy'`: the render arrays. */
|
|
39
|
+
stage: "decode" | "copy";
|
|
40
|
+
/** Points done so far in this stage. */
|
|
41
|
+
done: number;
|
|
42
|
+
/** Points in this stage. */
|
|
43
|
+
total: number;
|
|
44
|
+
}
|
|
45
|
+
/** Options of {@link vdbPointRenderData}. */
|
|
46
|
+
export interface VDBPointRenderDataOptions {
|
|
47
|
+
/** Above this many points every `ceil(total / maxPoints)`-th point is kept (his default 4,000,000). */
|
|
48
|
+
maxPoints?: number;
|
|
49
|
+
/** Colour attribute name. Default `'Cd'`. */
|
|
50
|
+
color?: string;
|
|
51
|
+
/** Other attributes to carry, by name (e.g. `['v']`). Names the grid does not have (or could not decode) are left out. */
|
|
52
|
+
attributes?: readonly string[];
|
|
53
|
+
/**
|
|
54
|
+
* `'grid'` (default): the grid's point order. `'prefix'`: residue classes of the kept index mod 10 in the order
|
|
55
|
+
* 0, 2, 4, 6, 8, 1, 3, 5, 7, 9, so every prefix of k tenths (`prefix[k]` points) is an even subsample: drawing
|
|
56
|
+
* fewer points is an instance count, not new buffers.
|
|
57
|
+
*/
|
|
58
|
+
order?: "grid" | "prefix";
|
|
59
|
+
/** Called during the decode (per leaf) and the copy (every 2^20 points), and once at the end of each stage. */
|
|
60
|
+
onProgress?: (progress: VDBPointRenderDataProgress) => void;
|
|
61
|
+
}
|
|
62
|
+
/** His `defaultMaxPoints`. */
|
|
63
|
+
export declare const VDB_POINTS_DEFAULT_MAX = 4000000;
|
|
64
|
+
/**
|
|
65
|
+
* Builds the {@link VDBPointRenderData} of a parsed point data grid
|
|
66
|
+
* (`parseVdb(...).grids` entry with `valueType: 'ptdataidx32'`). Decodes the
|
|
67
|
+
* grid's points (`grid.points()`, cached by the grid).
|
|
68
|
+
*
|
|
69
|
+
* @param grid A point data grid from `parseVdb`.
|
|
70
|
+
* @param options Point limit, attributes, order and progress ({@link VDBPointRenderDataOptions}).
|
|
71
|
+
*/
|
|
72
|
+
export declare function vdbPointRenderData(grid: VdbPointDataGrid, options?: VDBPointRenderDataOptions): VDBPointRenderData;
|
|
73
|
+
/**
|
|
74
|
+
* The buffers of a {@link VDBPointRenderData} to pass as a `postMessage` transfer list (each once), so a worker hands
|
|
75
|
+
* the arrays to the page without a copy: `self.postMessage(data, vdbPointRenderDataTransfer(data))`.
|
|
76
|
+
*
|
|
77
|
+
* @param data Render data from {@link vdbPointRenderData}.
|
|
78
|
+
*/
|
|
79
|
+
export declare function vdbPointRenderDataTransfer(data: VDBPointRenderData): ArrayBuffer[];
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The render-ready point list of a point data grid (K3.7, G14a): world positions,
|
|
3
|
+
* optional `Cd` colours and other attributes, a subsample stride above
|
|
4
|
+
* `maxPoints`, an optional prefix-subsample order, and the mean point spacing
|
|
5
|
+
* that sizes the sprites. The input `VDBPoints` (`./three`) draws.
|
|
6
|
+
*
|
|
7
|
+
* Portions derived from mjurczyk/openvdb (MIT), commit 75e7345
|
|
8
|
+
* (`src/openvdb/utils/points.js` `createPointData`: the stride rule, the count,
|
|
9
|
+
* the spacing formula). Copyright (c) mjurczyk/openvdb contributors, MIT (see
|
|
10
|
+
* THIRD_PARTY_NOTICES.md). Changes: built on our parsed `VdbPointDataGrid.points()`
|
|
11
|
+
* (K4.2) in one pass instead of a sliced generator; `Cd` of any decoded
|
|
12
|
+
* 3-component real attribute; other attributes, a prefix order, progress and
|
|
13
|
+
* bounds (G14a) (DIVERGES.md).
|
|
14
|
+
*
|
|
15
|
+
* Worker use: everything here is plain data (typed arrays and numbers), so a
|
|
16
|
+
* worker can `parseVdb` and call {@link vdbPointRenderData}, then post the result
|
|
17
|
+
* with {@link vdbPointRenderDataTransfer} as the transfer list.
|
|
18
|
+
*/
|
|
19
|
+
import { VDBToolsError } from "../errors.js";
|
|
20
|
+
/** His `defaultMaxPoints`. */
|
|
21
|
+
export const VDB_POINTS_DEFAULT_MAX = 4_000_000;
|
|
22
|
+
/** Residue classes mod 10 in prefix order: 10 % (class 0), then to 50 % (the even classes), then the odd ones. */
|
|
23
|
+
const PREFIX_CLASSES = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9];
|
|
24
|
+
const classSize = (n, c) => (c < n ? Math.floor((n - 1 - c) / 10) + 1 : 0);
|
|
25
|
+
/**
|
|
26
|
+
* Builds the {@link VDBPointRenderData} of a parsed point data grid
|
|
27
|
+
* (`parseVdb(...).grids` entry with `valueType: 'ptdataidx32'`). Decodes the
|
|
28
|
+
* grid's points (`grid.points()`, cached by the grid).
|
|
29
|
+
*
|
|
30
|
+
* @param grid A point data grid from `parseVdb`.
|
|
31
|
+
* @param options Point limit, attributes, order and progress ({@link VDBPointRenderDataOptions}).
|
|
32
|
+
*/
|
|
33
|
+
export function vdbPointRenderData(grid, options = {}) {
|
|
34
|
+
if (grid?.valueType !== "ptdataidx32" || typeof grid.points !== "function") {
|
|
35
|
+
throw new VDBToolsError("VDB_UNSUPPORTED_GRID_TYPE", "vdbPointRenderData: grid must be a parsed point data grid (valueType 'ptdataidx32').");
|
|
36
|
+
}
|
|
37
|
+
const maxPoints = options.maxPoints ?? VDB_POINTS_DEFAULT_MAX;
|
|
38
|
+
if (!(maxPoints >= 1))
|
|
39
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `vdbPointRenderData: maxPoints must be >= 1, got ${maxPoints}.`);
|
|
40
|
+
const order = options.order ?? "grid";
|
|
41
|
+
if (order !== "grid" && order !== "prefix")
|
|
42
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `vdbPointRenderData: order must be 'grid' or 'prefix', got ${JSON.stringify(order)}.`);
|
|
43
|
+
const onProgress = options.onProgress;
|
|
44
|
+
const list = grid.points(onProgress ? { onProgress: (done, total) => onProgress({ stage: "decode", done, total }) } : undefined);
|
|
45
|
+
const totalCount = list.count;
|
|
46
|
+
const stride = Math.max(1, Math.ceil(totalCount / maxPoints));
|
|
47
|
+
const count = totalCount > 0 ? Math.floor((totalCount - 1) / stride) + 1 : 0;
|
|
48
|
+
const positions = new Float32Array(count * 3);
|
|
49
|
+
const name = options.color ?? "Cd";
|
|
50
|
+
const cd = list.attributes[name];
|
|
51
|
+
const shape = list.attributeShapes[name];
|
|
52
|
+
const hasColors = cd !== undefined && shape?.components === 3 && shape.stride === 1 && (cd instanceof Float32Array || cd instanceof Float64Array);
|
|
53
|
+
const colors = hasColors ? new Float32Array(count * 3) : null;
|
|
54
|
+
const extra = [];
|
|
55
|
+
const attributes = {};
|
|
56
|
+
for (const a of options.attributes ?? []) {
|
|
57
|
+
const src = list.attributes[a];
|
|
58
|
+
const s = list.attributeShapes[a];
|
|
59
|
+
if (!src || !s || attributes[a])
|
|
60
|
+
continue;
|
|
61
|
+
const k = s.components * s.stride;
|
|
62
|
+
const dst = new src.constructor(count * k);
|
|
63
|
+
attributes[a] = { values: dst, components: k };
|
|
64
|
+
extra.push({ src, dst, k });
|
|
65
|
+
}
|
|
66
|
+
const min = [Infinity, Infinity, Infinity];
|
|
67
|
+
const max = [-Infinity, -Infinity, -Infinity];
|
|
68
|
+
const src = list.positions;
|
|
69
|
+
const copy = (i, j) => {
|
|
70
|
+
for (let c = 0; c < 3; c++) {
|
|
71
|
+
const p = src[i * 3 + c];
|
|
72
|
+
positions[j * 3 + c] = p;
|
|
73
|
+
if (p < min[c])
|
|
74
|
+
min[c] = p;
|
|
75
|
+
if (p > max[c])
|
|
76
|
+
max[c] = p;
|
|
77
|
+
}
|
|
78
|
+
if (colors) {
|
|
79
|
+
const c = cd;
|
|
80
|
+
colors[j * 3] = c[i * 3];
|
|
81
|
+
colors[j * 3 + 1] = c[i * 3 + 1];
|
|
82
|
+
colors[j * 3 + 2] = c[i * 3 + 2];
|
|
83
|
+
}
|
|
84
|
+
for (const e of extra)
|
|
85
|
+
for (let c = 0; c < e.k; c++)
|
|
86
|
+
e.dst[j * e.k + c] = e.src[i * e.k + c];
|
|
87
|
+
};
|
|
88
|
+
const tick = (j) => {
|
|
89
|
+
if (onProgress && (j & 0xfffff) === 0 && j > 0)
|
|
90
|
+
onProgress({ stage: "copy", done: j, total: count });
|
|
91
|
+
};
|
|
92
|
+
let prefix = null;
|
|
93
|
+
if (order === "prefix") {
|
|
94
|
+
// Kept index q = 0..count-1 (grid point q * stride), output position by residue class of q.
|
|
95
|
+
prefix = [0];
|
|
96
|
+
let j = 0;
|
|
97
|
+
for (const c of PREFIX_CLASSES) {
|
|
98
|
+
for (let q = c; q < count; q += 10, j++) {
|
|
99
|
+
copy(q * stride, j);
|
|
100
|
+
tick(j);
|
|
101
|
+
}
|
|
102
|
+
prefix.push(prefix[prefix.length - 1] + classSize(count, c));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
for (let i = 0, j = 0; i < totalCount; i += stride, j++) {
|
|
107
|
+
copy(i, j);
|
|
108
|
+
tick(j);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
onProgress?.({ stage: "copy", done: count, total: count });
|
|
112
|
+
const [sx, sy, sz] = grid.transform.voxelSize;
|
|
113
|
+
const voxelSize = Math.cbrt(Math.abs(sx * sy * sz));
|
|
114
|
+
const activeVoxels = Number(grid.activeVoxelCount);
|
|
115
|
+
const pointsPerVoxel = activeVoxels > 0 ? totalCount / activeVoxels : 1;
|
|
116
|
+
const spacing = (voxelSize / Math.cbrt(pointsPerVoxel)) * Math.cbrt(stride);
|
|
117
|
+
return { count, totalCount, stride, spacing, positions, colors, attributes, prefix, bounds: count > 0 ? { min, max } : null };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The buffers of a {@link VDBPointRenderData} to pass as a `postMessage` transfer list (each once), so a worker hands
|
|
121
|
+
* the arrays to the page without a copy: `self.postMessage(data, vdbPointRenderDataTransfer(data))`.
|
|
122
|
+
*
|
|
123
|
+
* @param data Render data from {@link vdbPointRenderData}.
|
|
124
|
+
*/
|
|
125
|
+
export function vdbPointRenderDataTransfer(data) {
|
|
126
|
+
const out = new Set();
|
|
127
|
+
const add = (a) => {
|
|
128
|
+
if (a && a.buffer instanceof ArrayBuffer)
|
|
129
|
+
out.add(a.buffer);
|
|
130
|
+
};
|
|
131
|
+
add(data.positions);
|
|
132
|
+
add(data.colors);
|
|
133
|
+
for (const a of Object.values(data.attributes))
|
|
134
|
+
add(a.values);
|
|
135
|
+
return [...out];
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=point-render-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"point-render-data.js","sourceRoot":"","sources":["../../../src/tools/vdb/point-render-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAgE7C,8BAA8B;AAC9B,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAS,CAAC;AAEhD,kHAAkH;AAClH,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAU,CAAC;AAC/D,MAAM,SAAS,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnG;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAsB,E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CAAC,CAAC,MAAM,YAAY,WAAW;YAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9D,CAAC,CAAC;IACF,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACpB,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjB,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;QAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9D,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC;AAClB,CAAC","sourcesContent":["/**\n * The render-ready point list of a point data grid (K3.7, G14a): world positions,\n * optional `Cd` colours and other attributes, a subsample stride above\n * `maxPoints`, an optional prefix-subsample order, and the mean point spacing\n * that sizes the sprites. The input `VDBPoints` (`./three`) draws.\n *\n * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345\n * (`src/openvdb/utils/points.js` `createPointData`: the stride rule, the count,\n * the spacing formula). Copyright (c) mjurczyk/openvdb contributors, MIT (see\n * THIRD_PARTY_NOTICES.md). Changes: built on our parsed `VdbPointDataGrid.points()`\n * (K4.2) in one pass instead of a sliced generator; `Cd` of any decoded\n * 3-component real attribute; other attributes, a prefix order, progress and\n * bounds (G14a) (DIVERGES.md).\n *\n * Worker use: everything here is plain data (typed arrays and numbers), so a\n * worker can `parseVdb` and call {@link vdbPointRenderData}, then post the result\n * with {@link vdbPointRenderDataTransfer} as the transfer list.\n */\nimport { VDBToolsError } from \"../errors.js\";\nimport type { VdbPointAttributeArray, VdbPointDataGrid } from \"./types.js\";\n\n/** One extra attribute carried by {@link VDBPointRenderData}: values in the kept points' order. */\nexport interface VDBPointRenderAttribute {\n /** `count * components` values, the decoder's element type (real attributes are `Float32Array`, `double` `Float64Array`). */\n values: VdbPointAttributeArray;\n /** Values per point (vector components times the attribute's stride). */\n components: number;\n}\n\n/** What `VDBPoints` draws: world positions (xyz per point), optional linear RGB, the mean spacing. */\nexport interface VDBPointRenderData {\n /** Points in the arrays. */\n count: number;\n /** Points in the grid before the stride. */\n totalCount: number;\n /** Every `stride`-th point (in the grid's point order) is kept; 1 below `maxPoints`. */\n stride: number;\n /** Mean distance between the kept points in world units: `voxelSize / cbrt(points per active voxel) * cbrt(stride)`. */\n spacing: number;\n /** World positions, `count * 3`. */\n positions: Float32Array;\n /** `Cd` per point (`count * 3`), or null when the grid has no 3-component real `Cd`. */\n colors: Float32Array | null;\n /** The attributes asked for with `attributes` that the grid has, in the same order as `positions`. */\n attributes: Record<string, VDBPointRenderAttribute>;\n /**\n * `order: 'prefix'` only: `prefix[k]` (k = 0..10) is how many points the first k tenths of the arrays hold.\n * `prefix[1]` is every 10th kept point, `prefix[5]` every 2nd, `prefix[10]` = `count`. Null for `order: 'grid'`.\n */\n prefix: number[] | null;\n /** Box of the kept positions (world units), or null without points. */\n bounds: { min: [number, number, number]; max: [number, number, number] } | null;\n}\n\n/** Progress of {@link vdbPointRenderData}: the decode (per leaf of the grid), then the copy into render order. */\nexport interface VDBPointRenderDataProgress {\n /** `'decode'`: the grid's attribute arrays (skipped when `grid.points()` already ran); `'copy'`: the render arrays. */\n stage: \"decode\" | \"copy\";\n /** Points done so far in this stage. */\n done: number;\n /** Points in this stage. */\n total: number;\n}\n\n/** Options of {@link vdbPointRenderData}. */\nexport interface VDBPointRenderDataOptions {\n /** Above this many points every `ceil(total / maxPoints)`-th point is kept (his default 4,000,000). */\n maxPoints?: number;\n /** Colour attribute name. Default `'Cd'`. */\n color?: string;\n /** Other attributes to carry, by name (e.g. `['v']`). Names the grid does not have (or could not decode) are left out. */\n attributes?: readonly string[];\n /**\n * `'grid'` (default): the grid's point order. `'prefix'`: residue classes of the kept index mod 10 in the order\n * 0, 2, 4, 6, 8, 1, 3, 5, 7, 9, so every prefix of k tenths (`prefix[k]` points) is an even subsample: drawing\n * fewer points is an instance count, not new buffers.\n */\n order?: \"grid\" | \"prefix\";\n /** Called during the decode (per leaf) and the copy (every 2^20 points), and once at the end of each stage. */\n onProgress?: (progress: VDBPointRenderDataProgress) => void;\n}\n\n/** His `defaultMaxPoints`. */\nexport const VDB_POINTS_DEFAULT_MAX = 4_000_000;\n\n/** Residue classes mod 10 in prefix order: 10 % (class 0), then to 50 % (the even classes), then the odd ones. */\nconst PREFIX_CLASSES = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9] as const;\nconst classSize = (n: number, c: number): number => (c < n ? Math.floor((n - 1 - c) / 10) + 1 : 0);\n\n/**\n * Builds the {@link VDBPointRenderData} of a parsed point data grid\n * (`parseVdb(...).grids` entry with `valueType: 'ptdataidx32'`). Decodes the\n * grid's points (`grid.points()`, cached by the grid).\n *\n * @param grid A point data grid from `parseVdb`.\n * @param options Point limit, attributes, order and progress ({@link VDBPointRenderDataOptions}).\n */\nexport function vdbPointRenderData(grid: VdbPointDataGrid, options: VDBPointRenderDataOptions = {}): VDBPointRenderData {\n if (grid?.valueType !== \"ptdataidx32\" || typeof grid.points !== \"function\") {\n throw new VDBToolsError(\"VDB_UNSUPPORTED_GRID_TYPE\", \"vdbPointRenderData: grid must be a parsed point data grid (valueType 'ptdataidx32').\");\n }\n const maxPoints = options.maxPoints ?? VDB_POINTS_DEFAULT_MAX;\n if (!(maxPoints >= 1)) throw new VDBToolsError(\"VDB_BAD_OPTION\", `vdbPointRenderData: maxPoints must be >= 1, got ${maxPoints}.`);\n const order = options.order ?? \"grid\";\n if (order !== \"grid\" && order !== \"prefix\") throw new VDBToolsError(\"VDB_BAD_OPTION\", `vdbPointRenderData: order must be 'grid' or 'prefix', got ${JSON.stringify(order)}.`);\n const onProgress = options.onProgress;\n const list = grid.points(onProgress ? { onProgress: (done, total) => onProgress({ stage: \"decode\", done, total }) } : undefined);\n const totalCount = list.count;\n const stride = Math.max(1, Math.ceil(totalCount / maxPoints));\n const count = totalCount > 0 ? Math.floor((totalCount - 1) / stride) + 1 : 0;\n const positions = new Float32Array(count * 3);\n const name = options.color ?? \"Cd\";\n const cd = list.attributes[name];\n const shape = list.attributeShapes[name];\n const hasColors = cd !== undefined && shape?.components === 3 && shape.stride === 1 && (cd instanceof Float32Array || cd instanceof Float64Array);\n const colors = hasColors ? new Float32Array(count * 3) : null;\n const extra: { src: VdbPointAttributeArray; dst: VdbPointAttributeArray; k: number }[] = [];\n const attributes: Record<string, VDBPointRenderAttribute> = {};\n for (const a of options.attributes ?? []) {\n const src = list.attributes[a];\n const s = list.attributeShapes[a];\n if (!src || !s || attributes[a]) continue;\n const k = s.components * s.stride;\n const dst = new (src.constructor as new (n: number) => VdbPointAttributeArray)(count * k);\n attributes[a] = { values: dst, components: k };\n extra.push({ src, dst, k });\n }\n const min: [number, number, number] = [Infinity, Infinity, Infinity];\n const max: [number, number, number] = [-Infinity, -Infinity, -Infinity];\n const src = list.positions;\n const copy = (i: number, j: number): void => {\n for (let c = 0; c < 3; c++) {\n const p = src[i * 3 + c]!;\n positions[j * 3 + c] = p;\n if (p < min[c]!) min[c] = p;\n if (p > max[c]!) max[c] = p;\n }\n if (colors) {\n const c = cd as Float32Array | Float64Array;\n colors[j * 3] = c[i * 3]!;\n colors[j * 3 + 1] = c[i * 3 + 1]!;\n colors[j * 3 + 2] = c[i * 3 + 2]!;\n }\n for (const e of extra) for (let c = 0; c < e.k; c++) (e.dst as Float32Array)[j * e.k + c] = (e.src as Float32Array)[i * e.k + c]!;\n };\n const tick = (j: number): void => {\n if (onProgress && (j & 0xfffff) === 0 && j > 0) onProgress({ stage: \"copy\", done: j, total: count });\n };\n let prefix: number[] | null = null;\n if (order === \"prefix\") {\n // Kept index q = 0..count-1 (grid point q * stride), output position by residue class of q.\n prefix = [0];\n let j = 0;\n for (const c of PREFIX_CLASSES) {\n for (let q = c; q < count; q += 10, j++) {\n copy(q * stride, j);\n tick(j);\n }\n prefix.push(prefix[prefix.length - 1]! + classSize(count, c));\n }\n } else {\n for (let i = 0, j = 0; i < totalCount; i += stride, j++) {\n copy(i, j);\n tick(j);\n }\n }\n onProgress?.({ stage: \"copy\", done: count, total: count });\n const [sx, sy, sz] = grid.transform.voxelSize;\n const voxelSize = Math.cbrt(Math.abs(sx * sy * sz));\n const activeVoxels = Number(grid.activeVoxelCount);\n const pointsPerVoxel = activeVoxels > 0 ? totalCount / activeVoxels : 1;\n const spacing = (voxelSize / Math.cbrt(pointsPerVoxel)) * Math.cbrt(stride);\n return { count, totalCount, stride, spacing, positions, colors, attributes, prefix, bounds: count > 0 ? { min, max } : null };\n}\n\n/**\n * The buffers of a {@link VDBPointRenderData} to pass as a `postMessage` transfer list (each once), so a worker hands\n * the arrays to the page without a copy: `self.postMessage(data, vdbPointRenderDataTransfer(data))`.\n *\n * @param data Render data from {@link vdbPointRenderData}.\n */\nexport function vdbPointRenderDataTransfer(data: VDBPointRenderData): ArrayBuffer[] {\n const out = new Set<ArrayBuffer>();\n const add = (a: ArrayBufferView | null): void => {\n if (a && a.buffer instanceof ArrayBuffer) out.add(a.buffer);\n };\n add(data.positions);\n add(data.colors);\n for (const a of Object.values(data.attributes)) add(a.values);\n return [...out];\n}\n"]}
|