@pmndrs/vdb 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +137 -0
- package/LICENSE +21 -0
- package/README.md +448 -2
- package/THIRD_PARTY_NOTICES.md +147 -0
- package/dist/core/compute/atlas.d.ts +94 -0
- package/dist/core/compute/atlas.js +98 -0
- package/dist/core/compute/atlas.js.map +1 -0
- package/dist/core/compute/index.d.ts +13 -0
- package/dist/core/compute/index.js +9 -0
- package/dist/core/compute/index.js.map +1 -0
- package/dist/core/compute/pyramid.d.ts +105 -0
- package/dist/core/compute/pyramid.js +455 -0
- package/dist/core/compute/pyramid.js.map +1 -0
- package/dist/core/compute/shared.d.ts +115 -0
- package/dist/core/compute/shared.js +211 -0
- package/dist/core/compute/shared.js.map +1 -0
- package/dist/core/compute/stats.d.ts +71 -0
- package/dist/core/compute/stats.js +188 -0
- package/dist/core/compute/stats.js.map +1 -0
- package/dist/core/compute/value-transform.d.ts +23 -0
- package/dist/core/compute/value-transform.js +58 -0
- package/dist/core/compute/value-transform.js.map +1 -0
- package/dist/core/errors.d.ts +11 -0
- package/dist/core/errors.js +9 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +30 -0
- package/dist/core/index.js +27 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/internal.d.ts +15 -0
- package/dist/core/internal.js +15 -0
- package/dist/core/internal.js.map +1 -0
- package/dist/core/pool/affine.d.ts +34 -0
- package/dist/core/pool/affine.js +100 -0
- package/dist/core/pool/affine.js.map +1 -0
- package/dist/core/pool/allocator.d.ts +32 -0
- package/dist/core/pool/allocator.js +81 -0
- package/dist/core/pool/allocator.js.map +1 -0
- package/dist/core/pool/image-header.d.ts +82 -0
- package/dist/core/pool/image-header.js +175 -0
- package/dist/core/pool/image-header.js.map +1 -0
- package/dist/core/pool/layout.d.ts +164 -0
- package/dist/core/pool/layout.js +267 -0
- package/dist/core/pool/layout.js.map +1 -0
- package/dist/core/pool/limits.d.ts +40 -0
- package/dist/core/pool/limits.js +79 -0
- package/dist/core/pool/limits.js.map +1 -0
- package/dist/core/pool/pool.d.ts +279 -0
- package/dist/core/pool/pool.js +953 -0
- package/dist/core/pool/pool.js.map +1 -0
- package/dist/core/source/dense.d.ts +19 -0
- package/dist/core/source/dense.js +287 -0
- package/dist/core/source/dense.js.map +1 -0
- package/dist/core/source/types.d.ts +63 -0
- package/dist/core/source/types.js +9 -0
- package/dist/core/source/types.js.map +1 -0
- package/dist/core/types.d.ts +28 -0
- package/dist/core/types.js +28 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/wgsl/api.d.ts +41 -0
- package/dist/core/wgsl/api.js +463 -0
- package/dist/core/wgsl/api.js.map +1 -0
- package/dist/core/wgsl/generate.d.ts +82 -0
- package/dist/core/wgsl/generate.js +505 -0
- package/dist/core/wgsl/generate.js.map +1 -0
- package/dist/core/wgsl/level-set.d.ts +54 -0
- package/dist/core/wgsl/level-set.js +194 -0
- package/dist/core/wgsl/level-set.js.map +1 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +330 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
- package/dist/core/wgsl/reserved.d.ts +9 -0
- package/dist/core/wgsl/reserved.js +26 -0
- package/dist/core/wgsl/reserved.js.map +1 -0
- package/dist/core/wgsl/types.d.ts +104 -0
- package/dist/core/wgsl/types.js +2 -0
- package/dist/core/wgsl/types.js.map +1 -0
- package/dist/three/coarse-first.d.ts +162 -0
- package/dist/three/coarse-first.js +187 -0
- package/dist/three/coarse-first.js.map +1 -0
- package/dist/three/compute.d.ts +63 -0
- package/dist/three/compute.js +56 -0
- package/dist/three/compute.js.map +1 -0
- package/dist/three/device.d.ts +59 -0
- package/dist/three/device.js +59 -0
- package/dist/three/device.js.map +1 -0
- package/dist/three/frame/blackbody.d.ts +42 -0
- package/dist/three/frame/blackbody.js +74 -0
- package/dist/three/frame/blackbody.js.map +1 -0
- package/dist/three/frame/chunks.d.ts +157 -0
- package/dist/three/frame/chunks.js +559 -0
- package/dist/three/frame/chunks.js.map +1 -0
- package/dist/three/frame/density-material.d.ts +53 -0
- package/dist/three/frame/density-material.js +353 -0
- package/dist/three/frame/density-material.js.map +1 -0
- package/dist/three/frame/emission-light.d.ts +167 -0
- package/dist/three/frame/emission-light.js +655 -0
- package/dist/three/frame/emission-light.js.map +1 -0
- package/dist/three/frame/environment-grid-material.d.ts +21 -0
- package/dist/three/frame/environment-grid-material.js +184 -0
- package/dist/three/frame/environment-grid-material.js.map +1 -0
- package/dist/three/frame/environment-material.d.ts +22 -0
- package/dist/three/frame/environment-material.js +87 -0
- package/dist/three/frame/environment-material.js.map +1 -0
- package/dist/three/frame/grid-mip-material.d.ts +12 -0
- package/dist/three/frame/grid-mip-material.js +61 -0
- package/dist/three/frame/grid-mip-material.js.map +1 -0
- package/dist/three/frame/index.d.ts +39 -0
- package/dist/three/frame/index.js +35 -0
- package/dist/three/frame/index.js.map +1 -0
- package/dist/three/frame/inject-material.d.ts +56 -0
- package/dist/three/frame/inject-material.js +424 -0
- package/dist/three/frame/inject-material.js.map +1 -0
- package/dist/three/frame/integrate-material.d.ts +26 -0
- package/dist/three/frame/integrate-material.js +198 -0
- package/dist/three/frame/integrate-material.js.map +1 -0
- package/dist/three/frame/layout.d.ts +34 -0
- package/dist/three/frame/layout.js +48 -0
- package/dist/three/frame/layout.js.map +1 -0
- package/dist/three/frame/lighting-material.d.ts +41 -0
- package/dist/three/frame/lighting-material.js +257 -0
- package/dist/three/frame/lighting-material.js.map +1 -0
- package/dist/three/frame/lights.d.ts +11 -0
- package/dist/three/frame/lights.js +16 -0
- package/dist/three/frame/lights.js.map +1 -0
- package/dist/three/frame/medium.d.ts +21 -0
- package/dist/three/frame/medium.js +29 -0
- package/dist/three/frame/medium.js.map +1 -0
- package/dist/three/frame/neural.d.ts +14 -0
- package/dist/three/frame/neural.js +105 -0
- package/dist/three/frame/neural.js.map +1 -0
- package/dist/three/frame/phase.d.ts +44 -0
- package/dist/three/frame/phase.js +80 -0
- package/dist/three/frame/phase.js.map +1 -0
- package/dist/three/frame/renderer.d.ts +493 -0
- package/dist/three/frame/renderer.js +1498 -0
- package/dist/three/frame/renderer.js.map +1 -0
- package/dist/three/frame/shadow-density-material.d.ts +30 -0
- package/dist/three/frame/shadow-density-material.js +123 -0
- package/dist/three/frame/shadow-density-material.js.map +1 -0
- package/dist/three/frame/spectrum.d.ts +18 -0
- package/dist/three/frame/spectrum.js +36 -0
- package/dist/three/frame/spectrum.js.map +1 -0
- package/dist/three/frame/temporal-material.d.ts +29 -0
- package/dist/three/frame/temporal-material.js +152 -0
- package/dist/three/frame/temporal-material.js.map +1 -0
- package/dist/three/frame/three-internals.d.ts +65 -0
- package/dist/three/frame/three-internals.js +150 -0
- package/dist/three/frame/three-internals.js.map +1 -0
- package/dist/three/frame/transmittance-material.d.ts +31 -0
- package/dist/three/frame/transmittance-material.js +315 -0
- package/dist/three/frame/transmittance-material.js.map +1 -0
- package/dist/three/frame/view.d.ts +103 -0
- package/dist/three/frame/view.js +296 -0
- package/dist/three/frame/view.js.map +1 -0
- package/dist/three/frame/volume-shadow-material.d.ts +36 -0
- package/dist/three/frame/volume-shadow-material.js +128 -0
- package/dist/three/frame/volume-shadow-material.js.map +1 -0
- package/dist/three/frame/volume-shadows.d.ts +153 -0
- package/dist/three/frame/volume-shadows.js +756 -0
- package/dist/three/frame/volume-shadows.js.map +1 -0
- package/dist/three/frame/volume.d.ts +172 -0
- package/dist/three/frame/volume.js +256 -0
- package/dist/three/frame/volume.js.map +1 -0
- package/dist/three/grid-node.d.ts +196 -0
- package/dist/three/grid-node.js +510 -0
- package/dist/three/grid-node.js.map +1 -0
- package/dist/three/index.d.ts +43 -0
- package/dist/three/index.js +49 -0
- package/dist/three/index.js.map +1 -0
- package/dist/three/internal.d.ts +14 -0
- package/dist/three/internal.js +14 -0
- package/dist/three/internal.js.map +1 -0
- package/dist/three/level-set-material.d.ts +112 -0
- package/dist/three/level-set-material.js +204 -0
- package/dist/three/level-set-material.js.map +1 -0
- package/dist/three/material.d.ts +194 -0
- package/dist/three/material.js +359 -0
- package/dist/three/material.js.map +1 -0
- package/dist/three/points.d.ts +84 -0
- package/dist/three/points.js +130 -0
- package/dist/three/points.js.map +1 -0
- package/dist/three/sequence.d.ts +317 -0
- package/dist/three/sequence.js +526 -0
- package/dist/three/sequence.js.map +1 -0
- package/dist/three/sparse-source.d.ts +233 -0
- package/dist/three/sparse-source.js +876 -0
- package/dist/three/sparse-source.js.map +1 -0
- package/dist/three/volume-source.d.ts +167 -0
- package/dist/three/volume-source.js +353 -0
- package/dist/three/volume-source.js.map +1 -0
- package/dist/tools/cpu/compute.d.ts +97 -0
- package/dist/tools/cpu/compute.js +218 -0
- package/dist/tools/cpu/compute.js.map +1 -0
- package/dist/tools/cpu/level-set.d.ts +72 -0
- package/dist/tools/cpu/level-set.js +261 -0
- package/dist/tools/cpu/level-set.js.map +1 -0
- package/dist/tools/cpu/march.d.ts +206 -0
- package/dist/tools/cpu/march.js +575 -0
- package/dist/tools/cpu/march.js.map +1 -0
- package/dist/tools/cpu/probe-coords.d.ts +70 -0
- package/dist/tools/cpu/probe-coords.js +116 -0
- package/dist/tools/cpu/probe-coords.js.map +1 -0
- package/dist/tools/cpu/read-value.d.ts +31 -0
- package/dist/tools/cpu/read-value.js +336 -0
- package/dist/tools/cpu/read-value.js.map +1 -0
- package/dist/tools/cpu/sample-trilinear.d.ts +30 -0
- package/dist/tools/cpu/sample-trilinear.js +156 -0
- package/dist/tools/cpu/sample-trilinear.js.map +1 -0
- package/dist/tools/cpu/stride-tables.d.ts +56 -0
- package/dist/tools/cpu/stride-tables.generated.d.ts +1058 -0
- package/dist/tools/cpu/stride-tables.generated.js +1266 -0
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
- package/dist/tools/cpu/stride-tables.js +78 -0
- package/dist/tools/cpu/stride-tables.js.map +1 -0
- package/dist/tools/errors.d.ts +57 -0
- package/dist/tools/errors.js +58 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/frame/blackbody.d.ts +42 -0
- package/dist/tools/frame/blackbody.js +116 -0
- package/dist/tools/frame/blackbody.js.map +1 -0
- package/dist/tools/frame/emission.d.ts +128 -0
- package/dist/tools/frame/emission.js +282 -0
- package/dist/tools/frame/emission.js.map +1 -0
- package/dist/tools/frame/environment.d.ts +105 -0
- package/dist/tools/frame/environment.js +268 -0
- package/dist/tools/frame/environment.js.map +1 -0
- package/dist/tools/frame/grid.d.ts +302 -0
- package/dist/tools/frame/grid.js +703 -0
- package/dist/tools/frame/grid.js.map +1 -0
- package/dist/tools/frame/index.d.ts +136 -0
- package/dist/tools/frame/index.js +348 -0
- package/dist/tools/frame/index.js.map +1 -0
- package/dist/tools/frame/medium.d.ts +61 -0
- package/dist/tools/frame/medium.js +99 -0
- package/dist/tools/frame/medium.js.map +1 -0
- package/dist/tools/frame/mie-table.d.ts +6 -0
- package/dist/tools/frame/mie-table.js +16 -0
- package/dist/tools/frame/mie-table.js.map +1 -0
- package/dist/tools/frame/mie.d.ts +54 -0
- package/dist/tools/frame/mie.js +176 -0
- package/dist/tools/frame/mie.js.map +1 -0
- package/dist/tools/frame/neural-weights.d.ts +9 -0
- package/dist/tools/frame/neural-weights.js +245 -0
- package/dist/tools/frame/neural-weights.js.map +1 -0
- package/dist/tools/frame/neural.d.ts +80 -0
- package/dist/tools/frame/neural.js +150 -0
- package/dist/tools/frame/neural.js.map +1 -0
- package/dist/tools/frame/pyramid-layout.d.ts +38 -0
- package/dist/tools/frame/pyramid-layout.js +53 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -0
- package/dist/tools/frame/shadows.d.ts +80 -0
- package/dist/tools/frame/shadows.js +182 -0
- package/dist/tools/frame/shadows.js.map +1 -0
- package/dist/tools/frame/sparse.d.ts +65 -0
- package/dist/tools/frame/sparse.js +191 -0
- package/dist/tools/frame/sparse.js.map +1 -0
- package/dist/tools/frame/spectral.d.ts +203 -0
- package/dist/tools/frame/spectral.js +550 -0
- package/dist/tools/frame/spectral.js.map +1 -0
- package/dist/tools/index.d.ts +106 -0
- package/dist/tools/index.js +88 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internal.d.ts +46 -0
- package/dist/tools/internal.js +31 -0
- package/dist/tools/internal.js.map +1 -0
- package/dist/tools/nanovdb/build-from-vdb.d.ts +50 -0
- package/dist/tools/nanovdb/build-from-vdb.js +92 -0
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
- package/dist/tools/nanovdb/bytes.d.ts +220 -0
- package/dist/tools/nanovdb/bytes.js +345 -0
- package/dist/tools/nanovdb/bytes.js.map +1 -0
- package/dist/tools/nanovdb/coarse-first.d.ts +62 -0
- package/dist/tools/nanovdb/coarse-first.js +86 -0
- package/dist/tools/nanovdb/coarse-first.js.map +1 -0
- package/dist/tools/nanovdb/index.d.ts +32 -0
- package/dist/tools/nanovdb/index.js +24 -0
- package/dist/tools/nanovdb/index.js.map +1 -0
- package/dist/tools/nanovdb/inspect.d.ts +24 -0
- package/dist/tools/nanovdb/inspect.js +63 -0
- package/dist/tools/nanovdb/inspect.js.map +1 -0
- package/dist/tools/nanovdb/leaf-codec.d.ts +85 -0
- package/dist/tools/nanovdb/leaf-codec.js +320 -0
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
- package/dist/tools/nanovdb/quantize.d.ts +43 -0
- package/dist/tools/nanovdb/quantize.js +277 -0
- package/dist/tools/nanovdb/quantize.js.map +1 -0
- package/dist/tools/nanovdb/resample.d.ts +160 -0
- package/dist/tools/nanovdb/resample.js +679 -0
- package/dist/tools/nanovdb/resample.js.map +1 -0
- package/dist/tools/nanovdb/serialize.d.ts +145 -0
- package/dist/tools/nanovdb/serialize.js +395 -0
- package/dist/tools/nanovdb/serialize.js.map +1 -0
- package/dist/tools/nanovdb/stats.d.ts +58 -0
- package/dist/tools/nanovdb/stats.js +149 -0
- package/dist/tools/nanovdb/stats.js.map +1 -0
- package/dist/tools/nanovdb/transform.d.ts +26 -0
- package/dist/tools/nanovdb/transform.js +91 -0
- package/dist/tools/nanovdb/transform.js.map +1 -0
- package/dist/tools/nanovdb/tree.d.ts +175 -0
- package/dist/tools/nanovdb/tree.js +518 -0
- package/dist/tools/nanovdb/tree.js.map +1 -0
- package/dist/tools/nanovdb/write-nvdb.d.ts +39 -0
- package/dist/tools/nanovdb/write-nvdb.js +210 -0
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
- package/dist/tools/nvdb-file.d.ts +195 -0
- package/dist/tools/nvdb-file.js +606 -0
- package/dist/tools/nvdb-file.js.map +1 -0
- package/dist/tools/nvdb-stream.d.ts +138 -0
- package/dist/tools/nvdb-stream.js +365 -0
- package/dist/tools/nvdb-stream.js.map +1 -0
- package/dist/tools/vdb/bit-utils.d.ts +20 -0
- package/dist/tools/vdb/bit-utils.js +42 -0
- package/dist/tools/vdb/bit-utils.js.map +1 -0
- package/dist/tools/vdb/blosc.d.ts +56 -0
- package/dist/tools/vdb/blosc.js +231 -0
- package/dist/tools/vdb/blosc.js.map +1 -0
- package/dist/tools/vdb/byte-reader.d.ts +40 -0
- package/dist/tools/vdb/byte-reader.js +139 -0
- package/dist/tools/vdb/byte-reader.js.map +1 -0
- package/dist/tools/vdb/compression.d.ts +73 -0
- package/dist/tools/vdb/compression.js +249 -0
- package/dist/tools/vdb/compression.js.map +1 -0
- package/dist/tools/vdb/errors.d.ts +10 -0
- package/dist/tools/vdb/errors.js +11 -0
- package/dist/tools/vdb/errors.js.map +1 -0
- package/dist/tools/vdb/grid.d.ts +37 -0
- package/dist/tools/vdb/grid.js +147 -0
- package/dist/tools/vdb/grid.js.map +1 -0
- package/dist/tools/vdb/half-float.d.ts +9 -0
- package/dist/tools/vdb/half-float.js +24 -0
- package/dist/tools/vdb/half-float.js.map +1 -0
- package/dist/tools/vdb/index.d.ts +3 -0
- package/dist/tools/vdb/index.js +3 -0
- package/dist/tools/vdb/index.js.map +1 -0
- package/dist/tools/vdb/inflate.d.ts +24 -0
- package/dist/tools/vdb/inflate.js +334 -0
- package/dist/tools/vdb/inflate.js.map +1 -0
- package/dist/tools/vdb/metadata.d.ts +17 -0
- package/dist/tools/vdb/metadata.js +72 -0
- package/dist/tools/vdb/metadata.js.map +1 -0
- package/dist/tools/vdb/parse.d.ts +25 -0
- package/dist/tools/vdb/parse.js +171 -0
- package/dist/tools/vdb/parse.js.map +1 -0
- package/dist/tools/vdb/point-render-data.d.ts +31 -0
- package/dist/tools/vdb/point-render-data.js +57 -0
- package/dist/tools/vdb/point-render-data.js.map +1 -0
- package/dist/tools/vdb/points.d.ts +160 -0
- package/dist/tools/vdb/points.js +794 -0
- package/dist/tools/vdb/points.js.map +1 -0
- package/dist/tools/vdb/transform.d.ts +23 -0
- package/dist/tools/vdb/transform.js +54 -0
- package/dist/tools/vdb/transform.js.map +1 -0
- package/dist/tools/vdb/tree.d.ts +111 -0
- package/dist/tools/vdb/tree.js +228 -0
- package/dist/tools/vdb/tree.js.map +1 -0
- package/dist/tools/vdb/types.d.ts +138 -0
- package/dist/tools/vdb/types.js +3 -0
- package/dist/tools/vdb/types.js.map +1 -0
- package/dist/tools/wvdb/bake.d.ts +116 -0
- package/dist/tools/wvdb/bake.js +311 -0
- package/dist/tools/wvdb/bake.js.map +1 -0
- package/dist/tools/wvdb/dense.d.ts +112 -0
- package/dist/tools/wvdb/dense.js +309 -0
- package/dist/tools/wvdb/dense.js.map +1 -0
- package/dist/tools/wvdb/format.d.ts +161 -0
- package/dist/tools/wvdb/format.js +303 -0
- package/dist/tools/wvdb/format.js.map +1 -0
- package/dist/tools/wvdb/index.d.ts +13 -0
- package/dist/tools/wvdb/index.js +14 -0
- package/dist/tools/wvdb/index.js.map +1 -0
- package/dist/tools/wvdb/level-set.d.ts +48 -0
- package/dist/tools/wvdb/level-set.js +153 -0
- package/dist/tools/wvdb/level-set.js.map +1 -0
- package/dist/tools/wvdb/nanovdb.d.ts +54 -0
- package/dist/tools/wvdb/nanovdb.js +60 -0
- package/dist/tools/wvdb/nanovdb.js.map +1 -0
- package/dist/tools/wvdb/read.d.ts +260 -0
- package/dist/tools/wvdb/read.js +743 -0
- package/dist/tools/wvdb/read.js.map +1 -0
- package/dist/tools/wvdb/sha256.d.ts +7 -0
- package/dist/tools/wvdb/sha256.js +76 -0
- package/dist/tools/wvdb/sha256.js.map +1 -0
- package/dist/tools/wvdb/write.d.ts +127 -0
- package/dist/tools/wvdb/write.js +396 -0
- package/dist/tools/wvdb/write.js.map +1 -0
- package/package.json +82 -4
- package/vendor/LICENSE +201 -0
- package/vendor/NOTICE +19 -0
- package/vendor/VENDOR.md +85 -0
- package/vendor/pnanovdb.wgsl +1539 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `vdbStreamCoarseFirst` (K4.16): stream a coarse-first `.nvdb`
|
|
3
|
+
* (`vdbBakeCoarseFirst`, docs/dev/design/K4-5-coarse-first.md option a) into one
|
|
4
|
+
* pool id. The preview is added as soon as its bytes are in, with the full
|
|
5
|
+
* grid's size reserved, and each finer grid replaces it in place:
|
|
6
|
+
*
|
|
7
|
+
* const res = await fetch(url);
|
|
8
|
+
* const { id } = await vdbStreamCoarseFirst(pool, res, {
|
|
9
|
+
* onGrid: (e) => { if (e.final) material.densityScale.value = base; },
|
|
10
|
+
* });
|
|
11
|
+
*
|
|
12
|
+
* 1. `id = pool.add(preview, { capacity })`, where `capacity` is the largest
|
|
13
|
+
* grid of the family announced so far (a segment lists every grid's
|
|
14
|
+
* FileMetaData before any data, so the full grid's size is known);
|
|
15
|
+
* 2. `pool.replace(id, finer)` for each finer grid, the full grid last.
|
|
16
|
+
*
|
|
17
|
+
* The id, its bind-group slot and any instance transform stay. Each image's
|
|
18
|
+
* own Map places it, and a preview covers the full grid's world box, so the
|
|
19
|
+
* world placement is unchanged. Things the caller re-derives after a swap
|
|
20
|
+
* (the `onGrid` callback is the place, or the opt-in `bind` option, which does these
|
|
21
|
+
* three steps for you after every swap):
|
|
22
|
+
* - `replace` drops a brick majorant: call `pool.setMajorant` again;
|
|
23
|
+
* - `VDBVolumeMaterial` marches in index voxels, so a preview with k-times
|
|
24
|
+
* larger voxels has 1/k the optical depth at the same `densityScale`;
|
|
25
|
+
* scale it by `voxelRatio` while a preview shows, and back to 1 at `final`;
|
|
26
|
+
* - the proxy mesh: a new `vdbProxyGeometry(pool.info(id))` (the preview's
|
|
27
|
+
* box is the full box grown to whole preview voxels).
|
|
28
|
+
*
|
|
29
|
+
* Into the froxel renderer (G16a): at the first event make the `VDBGridNode`
|
|
30
|
+
* with `types: event.types` (every grid type of the family) and the sparse
|
|
31
|
+
* source with `followImage: true`; the source re-reads its boxes after each
|
|
32
|
+
* swap and the `VDBFrameVolume` follows, with no new node, source, volume or
|
|
33
|
+
* shader. Froxels integrate in world space: no `voxelRatio` scale there.
|
|
34
|
+
*
|
|
35
|
+
* Without `bind` it touches only `pool.add` / `pool.replace`, so it works with
|
|
36
|
+
* any `VDBGridPool` host. It lives in `./three` because `tools` may not import
|
|
37
|
+
* the core (D20).
|
|
38
|
+
*/
|
|
39
|
+
import type * as THREE from "three";
|
|
40
|
+
import type { VDBBrickMajorant } from "../core/index.js";
|
|
41
|
+
import { type VDBGridTypeName } from "../core/types.js";
|
|
42
|
+
import { type VDBProxyGridInfo } from "./material.js";
|
|
43
|
+
import { type NvdbProgress, type NvdbStreamGrid, type NvdbStreamReaderOptions } from "../tools/index.js";
|
|
44
|
+
/** The part of a `VDBGridPool` the loader uses. */
|
|
45
|
+
export interface VDBCoarseFirstPoolLike {
|
|
46
|
+
add(image: Uint32Array, options?: {
|
|
47
|
+
capacity?: number;
|
|
48
|
+
label?: string;
|
|
49
|
+
}): number;
|
|
50
|
+
replace(id: number, image: Uint32Array): void;
|
|
51
|
+
}
|
|
52
|
+
/** The extra pool calls `bind` makes (a `VDBGridPool` has them all). */
|
|
53
|
+
export interface VDBCoarseFirstBindPoolLike {
|
|
54
|
+
flush(): void;
|
|
55
|
+
info(id: number): VDBProxyGridInfo;
|
|
56
|
+
setMajorant(id: number, majorant: VDBBrickMajorant | null): void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* What to keep in step with the pool id after each swap (K5.4c). Every member is optional; the fields are read at
|
|
60
|
+
* each swap, so they may be assigned later (for example in `onGrid`, once the first grid exists).
|
|
61
|
+
*/
|
|
62
|
+
export interface VDBCoarseFirstBind {
|
|
63
|
+
/**
|
|
64
|
+
* A material to scale: `material.densityScale.value = base * event.voxelRatio`, so a preview with k-times larger
|
|
65
|
+
* voxels keeps the full grid's optical depth and the full grid gets `base` back. `base` is `densityScale` below,
|
|
66
|
+
* else the material's value the first time `bind` is applied to it.
|
|
67
|
+
*/
|
|
68
|
+
material?: {
|
|
69
|
+
densityScale: {
|
|
70
|
+
value: number;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
/** The base density scale for `material`. Default: the material's current value at the first swap. */
|
|
74
|
+
densityScale?: number;
|
|
75
|
+
/** A proxy mesh: its geometry is replaced (and the old one disposed) with `vdbProxyGeometry(pool.info(id))`. */
|
|
76
|
+
mesh?: {
|
|
77
|
+
geometry: THREE.BufferGeometry;
|
|
78
|
+
};
|
|
79
|
+
/** `vdbProxyGeometry` padding for `mesh` (default 0). */
|
|
80
|
+
proxyPad?: number;
|
|
81
|
+
/** A `VDBGridNode`: `pool.flush()` then `grids.update()`, so its shaders see the swapped grid. */
|
|
82
|
+
grids?: {
|
|
83
|
+
update(): void;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Brick majorant for the grid just shown (`replace` drops the old one). Return `null` / `undefined` to leave the grid
|
|
87
|
+
* without one, e.g. for a preview.
|
|
88
|
+
*/
|
|
89
|
+
majorant?: (event: VDBCoarseFirstEvent) => VDBBrickMajorant | null | undefined;
|
|
90
|
+
}
|
|
91
|
+
/** What a coarse-first stream delivers. */
|
|
92
|
+
export type VDBCoarseFirstSource = Response | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
93
|
+
/** One grid shown in the pool. */
|
|
94
|
+
export interface VDBCoarseFirstEvent {
|
|
95
|
+
/** The pool id (the same for every grid of the family). */
|
|
96
|
+
id: number;
|
|
97
|
+
/** The grid as the stream reader emitted it (`lod` is null for the full grid). */
|
|
98
|
+
grid: NvdbStreamGrid;
|
|
99
|
+
/** True for the full grid: the last swap. */
|
|
100
|
+
final: boolean;
|
|
101
|
+
/** `'add'` for the first grid shown, `'replace'` after. */
|
|
102
|
+
action: "add" | "replace";
|
|
103
|
+
/** File bytes received when the grid was shown (decoded bytes; see the e2e for compressed counts). */
|
|
104
|
+
bytesReceived: number;
|
|
105
|
+
/** Expected file size when the grid was shown, or null if unknown (K4.20; see `NvdbProgress.bytesTotal`). */
|
|
106
|
+
bytesTotal: number | null;
|
|
107
|
+
/** This grid's voxel size over the full grid's (x axis): 1 for the full grid, > 1 for a preview. */
|
|
108
|
+
voxelRatio: number;
|
|
109
|
+
/**
|
|
110
|
+
* G16a: the grid types of the family's grids (the file lists every grid's metadata before any data, so this holds
|
|
111
|
+
* the full grid's type from the first event on), in `VDB_GRID_TYPE_NAMES` order (`float, fp4, fp8, fp16, fpn`, not
|
|
112
|
+
* alphabetical), each once. A `VDBGridNode` made with `types: event.types` decodes the
|
|
113
|
+
* preview and the full grid with one module (a baked FpN preview and an Fp8 full grid differ), so a source made
|
|
114
|
+
* with `followImage` swaps without a recompile.
|
|
115
|
+
*/
|
|
116
|
+
types: VDBGridTypeName[];
|
|
117
|
+
}
|
|
118
|
+
export interface VDBCoarseFirstOptions {
|
|
119
|
+
/** Which family to load, by the full grid's name. Default: the first grid's family. */
|
|
120
|
+
gridName?: string;
|
|
121
|
+
/** Pool label for the id. Default: the full grid's name. */
|
|
122
|
+
label?: string;
|
|
123
|
+
/** Limits for the stream reader. */
|
|
124
|
+
reader?: NvdbStreamReaderOptions;
|
|
125
|
+
/**
|
|
126
|
+
* Keeps a material, proxy mesh, grid node and majorant in step with each swap, before `onGrid` runs (see
|
|
127
|
+
* {@link VDBCoarseFirstBind} and {@link vdbCoarseFirstApply}). Needs a pool with `flush` / `info` / `setMajorant`
|
|
128
|
+
* (a `VDBGridPool`).
|
|
129
|
+
*/
|
|
130
|
+
bind?: VDBCoarseFirstBind;
|
|
131
|
+
/** Called after each `pool.add` / `pool.replace` (preview, then finer grids, then the full grid), after `bind`. */
|
|
132
|
+
onGrid?: (event: VDBCoarseFirstEvent) => void;
|
|
133
|
+
/** Called after every received chunk with the byte progress (K4.20). `bytesTotal` is the Response's Content-Length, else derived from the file's metadata. */
|
|
134
|
+
onProgress?: (progress: NvdbProgress) => void;
|
|
135
|
+
/** Aborts the read (rejects with the signal's reason; the id, if added, stays in the pool). */
|
|
136
|
+
signal?: AbortSignal;
|
|
137
|
+
}
|
|
138
|
+
export interface VDBCoarseFirstResult {
|
|
139
|
+
id: number;
|
|
140
|
+
/** Every grid shown, in order (the preview(s), then the full grid). */
|
|
141
|
+
shown: VDBCoarseFirstEvent[];
|
|
142
|
+
/** File bytes received when the first grid was added. */
|
|
143
|
+
firstBytes: number;
|
|
144
|
+
/** File bytes received when the full grid replaced the preview. */
|
|
145
|
+
fullBytes: number;
|
|
146
|
+
/** Expected file size when the full grid arrived, or null if unknown. */
|
|
147
|
+
bytesTotal: number | null;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The work `bind` does after a swap, callable on its own from an async `onGrid` (or any code that shows a
|
|
151
|
+
* {@link VDBCoarseFirstEvent}): majorant, proxy geometry, `pool.flush()` + `grids.update()`, density scale. It never
|
|
152
|
+
* touches what `bind` leaves out.
|
|
153
|
+
*/
|
|
154
|
+
export declare function vdbCoarseFirstApply(pool: VDBCoarseFirstPoolLike & Partial<VDBCoarseFirstBindPoolLike>, event: VDBCoarseFirstEvent, bind: VDBCoarseFirstBind): void;
|
|
155
|
+
/**
|
|
156
|
+
* Streams a coarse-first `.nvdb` into one pool id: `add` the first grid of the
|
|
157
|
+
* family with the family's largest size reserved, then `replace` with each
|
|
158
|
+
* finer grid. Resolves when the full grid is in the pool (the rest of the
|
|
159
|
+
* stream is cancelled). Rejects with the reader's `NvdbFormatError` on bad
|
|
160
|
+
* or truncated data.
|
|
161
|
+
*/
|
|
162
|
+
export declare function vdbStreamCoarseFirst(pool: VDBCoarseFirstPoolLike & Partial<VDBCoarseFirstBindPoolLike>, source: VDBCoarseFirstSource, options?: VDBCoarseFirstOptions): Promise<VDBCoarseFirstResult>;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `vdbStreamCoarseFirst` (K4.16): stream a coarse-first `.nvdb`
|
|
3
|
+
* (`vdbBakeCoarseFirst`, docs/dev/design/K4-5-coarse-first.md option a) into one
|
|
4
|
+
* pool id. The preview is added as soon as its bytes are in, with the full
|
|
5
|
+
* grid's size reserved, and each finer grid replaces it in place:
|
|
6
|
+
*
|
|
7
|
+
* const res = await fetch(url);
|
|
8
|
+
* const { id } = await vdbStreamCoarseFirst(pool, res, {
|
|
9
|
+
* onGrid: (e) => { if (e.final) material.densityScale.value = base; },
|
|
10
|
+
* });
|
|
11
|
+
*
|
|
12
|
+
* 1. `id = pool.add(preview, { capacity })`, where `capacity` is the largest
|
|
13
|
+
* grid of the family announced so far (a segment lists every grid's
|
|
14
|
+
* FileMetaData before any data, so the full grid's size is known);
|
|
15
|
+
* 2. `pool.replace(id, finer)` for each finer grid, the full grid last.
|
|
16
|
+
*
|
|
17
|
+
* The id, its bind-group slot and any instance transform stay. Each image's
|
|
18
|
+
* own Map places it, and a preview covers the full grid's world box, so the
|
|
19
|
+
* world placement is unchanged. Things the caller re-derives after a swap
|
|
20
|
+
* (the `onGrid` callback is the place, or the opt-in `bind` option, which does these
|
|
21
|
+
* three steps for you after every swap):
|
|
22
|
+
* - `replace` drops a brick majorant: call `pool.setMajorant` again;
|
|
23
|
+
* - `VDBVolumeMaterial` marches in index voxels, so a preview with k-times
|
|
24
|
+
* larger voxels has 1/k the optical depth at the same `densityScale`;
|
|
25
|
+
* scale it by `voxelRatio` while a preview shows, and back to 1 at `final`;
|
|
26
|
+
* - the proxy mesh: a new `vdbProxyGeometry(pool.info(id))` (the preview's
|
|
27
|
+
* box is the full box grown to whole preview voxels).
|
|
28
|
+
*
|
|
29
|
+
* Into the froxel renderer (G16a): at the first event make the `VDBGridNode`
|
|
30
|
+
* with `types: event.types` (every grid type of the family) and the sparse
|
|
31
|
+
* source with `followImage: true`; the source re-reads its boxes after each
|
|
32
|
+
* swap and the `VDBFrameVolume` follows, with no new node, source, volume or
|
|
33
|
+
* shader. Froxels integrate in world space: no `voxelRatio` scale there.
|
|
34
|
+
*
|
|
35
|
+
* Without `bind` it touches only `pool.add` / `pool.replace`, so it works with
|
|
36
|
+
* any `VDBGridPool` host. It lives in `./three` because `tools` may not import
|
|
37
|
+
* the core (D20).
|
|
38
|
+
*/
|
|
39
|
+
import { VDBError } from "../core/errors.js";
|
|
40
|
+
import { VDB_GRID_TYPE_NAMES } from "../core/types.js";
|
|
41
|
+
import { vdbProxyGeometry } from "./material.js";
|
|
42
|
+
import { NvdbStreamReader, nvdbResponseLength, parseNvdbLodName, } from "../tools/index.js";
|
|
43
|
+
/** The base density scale of each bound material (the value seen at its first swap, unless `bind.densityScale` says). */
|
|
44
|
+
const baseScale = new WeakMap();
|
|
45
|
+
/**
|
|
46
|
+
* The work `bind` does after a swap, callable on its own from an async `onGrid` (or any code that shows a
|
|
47
|
+
* {@link VDBCoarseFirstEvent}): majorant, proxy geometry, `pool.flush()` + `grids.update()`, density scale. It never
|
|
48
|
+
* touches what `bind` leaves out.
|
|
49
|
+
*/
|
|
50
|
+
export function vdbCoarseFirstApply(pool, event, bind) {
|
|
51
|
+
const need = (name) => {
|
|
52
|
+
const fn = pool[name];
|
|
53
|
+
if (typeof fn !== "function") {
|
|
54
|
+
throw new VDBError("VDB_BAD_OPTION", `vdbStreamCoarseFirst: \`bind\` needs a pool with ${name}() (a VDBGridPool).`);
|
|
55
|
+
}
|
|
56
|
+
return fn.bind(pool);
|
|
57
|
+
};
|
|
58
|
+
if (bind.majorant) {
|
|
59
|
+
const majorant = bind.majorant(event);
|
|
60
|
+
if (majorant)
|
|
61
|
+
need("setMajorant")(event.id, majorant);
|
|
62
|
+
}
|
|
63
|
+
if (bind.mesh) {
|
|
64
|
+
const next = vdbProxyGeometry(need("info")(event.id), bind.proxyPad === undefined ? {} : { pad: bind.proxyPad });
|
|
65
|
+
bind.mesh.geometry.dispose();
|
|
66
|
+
bind.mesh.geometry = next;
|
|
67
|
+
}
|
|
68
|
+
if (bind.grids) {
|
|
69
|
+
need("flush")();
|
|
70
|
+
bind.grids.update();
|
|
71
|
+
}
|
|
72
|
+
const material = bind.material;
|
|
73
|
+
if (material) {
|
|
74
|
+
const base = bind.densityScale ?? baseScale.get(material) ?? material.densityScale.value;
|
|
75
|
+
baseScale.set(material, base);
|
|
76
|
+
material.densityScale.value = base * event.voxelRatio;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const familyOf = (name) => parseNvdbLodName(name).baseName;
|
|
80
|
+
/** Finest first: the full grid (lod null) beats any preview; a larger resolution beats a smaller. */
|
|
81
|
+
function finer(a, b) {
|
|
82
|
+
if (b === null)
|
|
83
|
+
return true;
|
|
84
|
+
if (b.lod === null)
|
|
85
|
+
return false;
|
|
86
|
+
if (a.lod === null)
|
|
87
|
+
return true;
|
|
88
|
+
return a.lod > b.lod;
|
|
89
|
+
}
|
|
90
|
+
function chunks(source) {
|
|
91
|
+
const stream = source instanceof Response ? source.body : source;
|
|
92
|
+
if (source instanceof Response && !source.ok) {
|
|
93
|
+
throw new VDBError("VDB_BAD_OPTION", `vdbStreamCoarseFirst: the response is ${source.status} ${source.statusText} (${source.url}).`);
|
|
94
|
+
}
|
|
95
|
+
if (stream === null)
|
|
96
|
+
throw new VDBError("VDB_BAD_OPTION", "vdbStreamCoarseFirst: the response has no body.");
|
|
97
|
+
if (typeof stream.getReader === "function") {
|
|
98
|
+
const reader = stream.getReader();
|
|
99
|
+
return {
|
|
100
|
+
iterate: {
|
|
101
|
+
async *[Symbol.asyncIterator]() {
|
|
102
|
+
for (;;) {
|
|
103
|
+
const { done, value } = await reader.read();
|
|
104
|
+
if (done)
|
|
105
|
+
return;
|
|
106
|
+
yield value;
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
cancel: () => reader.cancel().catch(() => undefined),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const iterable = stream;
|
|
114
|
+
return { iterate: iterable, cancel: async () => undefined };
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Streams a coarse-first `.nvdb` into one pool id: `add` the first grid of the
|
|
118
|
+
* family with the family's largest size reserved, then `replace` with each
|
|
119
|
+
* finer grid. Resolves when the full grid is in the pool (the rest of the
|
|
120
|
+
* stream is cancelled). Rejects with the reader's `NvdbFormatError` on bad
|
|
121
|
+
* or truncated data.
|
|
122
|
+
*/
|
|
123
|
+
export async function vdbStreamCoarseFirst(pool, source, options = {}) {
|
|
124
|
+
const signal = options.signal;
|
|
125
|
+
signal?.throwIfAborted();
|
|
126
|
+
const wire = source instanceof Response ? nvdbResponseLength(source) : null;
|
|
127
|
+
const reader = new NvdbStreamReader({
|
|
128
|
+
...options.reader,
|
|
129
|
+
...(wire !== null && options.reader?.bytesTotal === undefined ? { bytesTotal: wire } : {}),
|
|
130
|
+
...(options.onProgress ? { onProgress: options.onProgress } : {}),
|
|
131
|
+
});
|
|
132
|
+
const { iterate, cancel } = chunks(source);
|
|
133
|
+
let family = options.gridName ?? null;
|
|
134
|
+
let id = -1;
|
|
135
|
+
let current = null;
|
|
136
|
+
const shown = [];
|
|
137
|
+
const familyGrids = () => reader.grids.filter((g) => familyOf(g.name) === family);
|
|
138
|
+
const fullVoxel = (grid) => {
|
|
139
|
+
const full = familyGrids().find((g) => g.name === family);
|
|
140
|
+
return full ? grid.metadata.voxelSize[0] / full.voxelSize[0] : 1;
|
|
141
|
+
};
|
|
142
|
+
// The reader accepts only the pool's scalar types (Float, Fp4, Fp8, Fp16, FpN: the names in lower case).
|
|
143
|
+
const familyTypes = () => {
|
|
144
|
+
const names = new Set(familyGrids().map((g) => g.gridType.toLowerCase()));
|
|
145
|
+
return VDB_GRID_TYPE_NAMES.filter((t) => names.has(t));
|
|
146
|
+
};
|
|
147
|
+
try {
|
|
148
|
+
for await (const chunk of iterate) {
|
|
149
|
+
signal?.throwIfAborted();
|
|
150
|
+
for (const grid of reader.push(chunk)) {
|
|
151
|
+
family ??= grid.baseName;
|
|
152
|
+
if (grid.baseName !== family || !finer(grid, current))
|
|
153
|
+
continue;
|
|
154
|
+
const final = grid.lod === null;
|
|
155
|
+
let action;
|
|
156
|
+
if (id < 0) {
|
|
157
|
+
const capacity = Math.max(...familyGrids().map((g) => g.gridByteSize));
|
|
158
|
+
id = pool.add(grid.image, { capacity, label: options.label ?? family });
|
|
159
|
+
action = "add";
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
pool.replace(id, grid.image);
|
|
163
|
+
action = "replace";
|
|
164
|
+
}
|
|
165
|
+
current = grid;
|
|
166
|
+
const event = { id, grid, final, action, bytesReceived: grid.bytesReceived, bytesTotal: grid.bytesTotal, voxelRatio: fullVoxel(grid), types: familyTypes() };
|
|
167
|
+
shown.push(event);
|
|
168
|
+
if (options.bind)
|
|
169
|
+
vdbCoarseFirstApply(pool, event, options.bind);
|
|
170
|
+
options.onGrid?.(event);
|
|
171
|
+
if (final) {
|
|
172
|
+
await cancel();
|
|
173
|
+
return { id, shown, firstBytes: shown[0].bytesReceived, fullBytes: grid.bytesReceived, bytesTotal: grid.bytesTotal };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
reader.end();
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
await cancel();
|
|
181
|
+
throw err;
|
|
182
|
+
}
|
|
183
|
+
throw new VDBError("VDB_BAD_IMAGE", family === null
|
|
184
|
+
? "vdbStreamCoarseFirst: the stream held no grid."
|
|
185
|
+
: `vdbStreamCoarseFirst: the stream ended without the full grid "${family}" (grids: ${reader.grids.map((g) => g.name).join(", ")}).`);
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=coarse-first.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coarse-first.js","sourceRoot":"","sources":["../../src/three/coarse-first.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAwB,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAyB,MAAM,eAAe,CAAC;AACxE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GAKjB,MAAM,mBAAmB,CAAC;AAuG3B,yHAAyH;AACzH,MAAM,SAAS,GAAG,IAAI,OAAO,EAAkB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAkE,EAClE,KAA0B,EAC1B,IAAwB;IAExB,MAAM,IAAI,GAAG,CAA6C,IAAO,EAA8C,EAAE;QAC/G,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;YAC7B,MAAM,IAAI,QAAQ,CAAC,gBAAgB,EAAE,oDAAoD,IAAI,qBAAqB,CAAC,CAAC;QACtH,CAAC;QACD,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAA+C,CAAC;IACrE,CAAC,CAAC;IACF,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,QAAQ;YAAE,IAAI,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,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ACD,MAAM,IAAI,QAAQ,CAChB,eAAe,EACf,MAAM,KAAK,IAAI;QACb,CAAC,CAAC,gDAAgD;QAClD,CAAC,CAAC,iEAAiE,MAAM,aAAa,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CACvI,CAAC;AACJ,CAAC","sourcesContent":["/**\n * `vdbStreamCoarseFirst` (K4.16): stream a coarse-first `.nvdb`\n * (`vdbBakeCoarseFirst`, docs/dev/design/K4-5-coarse-first.md option a) into one\n * pool id. The preview is added as soon as its bytes are in, with the full\n * grid's size reserved, and each finer grid replaces it in place:\n *\n * const res = await fetch(url);\n * const { id } = await vdbStreamCoarseFirst(pool, res, {\n * onGrid: (e) => { if (e.final) material.densityScale.value = base; },\n * });\n *\n * 1. `id = pool.add(preview, { capacity })`, where `capacity` is the largest\n * grid of the family announced so far (a segment lists every grid's\n * FileMetaData before any data, so the full grid's size is known);\n * 2. `pool.replace(id, finer)` for each finer grid, the full grid last.\n *\n * The id, its bind-group slot and any instance transform stay. Each image's\n * own Map places it, and a preview covers the full grid's world box, so the\n * world placement is unchanged. Things the caller re-derives after a swap\n * (the `onGrid` callback is the place, or the opt-in `bind` option, which does these\n * three steps for you after every swap):\n * - `replace` drops a brick majorant: call `pool.setMajorant` again;\n * - `VDBVolumeMaterial` marches in index voxels, so a preview with k-times\n * larger voxels has 1/k the optical depth at the same `densityScale`;\n * scale it by `voxelRatio` while a preview shows, and back to 1 at `final`;\n * - the proxy mesh: a new `vdbProxyGeometry(pool.info(id))` (the preview's\n * box is the full box grown to whole preview voxels).\n *\n * Into the froxel renderer (G16a): at the first event make the `VDBGridNode`\n * with `types: event.types` (every grid type of the family) and the sparse\n * source with `followImage: true`; the source re-reads its boxes after each\n * swap and the `VDBFrameVolume` follows, with no new node, source, volume or\n * shader. Froxels integrate in world space: no `voxelRatio` scale there.\n *\n * Without `bind` it touches only `pool.add` / `pool.replace`, so it works with\n * any `VDBGridPool` host. It lives in `./three` because `tools` may not import\n * the core (D20).\n */\n\nimport type * as THREE from \"three\";\n\nimport { VDBError } from \"../core/errors.js\";\nimport type { VDBBrickMajorant } from \"../core/index.js\";\nimport { VDB_GRID_TYPE_NAMES, type VDBGridTypeName } from \"../core/types.js\";\nimport { vdbProxyGeometry, type VDBProxyGridInfo } from \"./material.js\";\nimport {\n NvdbStreamReader,\n nvdbResponseLength,\n parseNvdbLodName,\n type NvdbGridMetadata,\n type NvdbProgress,\n type NvdbStreamGrid,\n type NvdbStreamReaderOptions,\n} from \"../tools/index.js\";\n\n/** The part of a `VDBGridPool` the loader uses. */\nexport interface VDBCoarseFirstPoolLike {\n add(image: Uint32Array, options?: { capacity?: number; label?: string }): number;\n replace(id: number, image: Uint32Array): void;\n}\n\n/** The extra pool calls `bind` makes (a `VDBGridPool` has them all). */\nexport interface VDBCoarseFirstBindPoolLike {\n flush(): void;\n info(id: number): VDBProxyGridInfo;\n setMajorant(id: number, majorant: VDBBrickMajorant | null): void;\n}\n\n/**\n * What to keep in step with the pool id after each swap (K5.4c). Every member is optional; the fields are read at\n * each swap, so they may be assigned later (for example in `onGrid`, once the first grid exists).\n */\nexport interface VDBCoarseFirstBind {\n /**\n * A material to scale: `material.densityScale.value = base * event.voxelRatio`, so a preview with k-times larger\n * voxels keeps the full grid's optical depth and the full grid gets `base` back. `base` is `densityScale` below,\n * else the material's value the first time `bind` is applied to it.\n */\n material?: { densityScale: { value: number } };\n /** The base density scale for `material`. Default: the material's current value at the first swap. */\n densityScale?: number;\n /** A proxy mesh: its geometry is replaced (and the old one disposed) with `vdbProxyGeometry(pool.info(id))`. */\n mesh?: { geometry: THREE.BufferGeometry };\n /** `vdbProxyGeometry` padding for `mesh` (default 0). */\n proxyPad?: number;\n /** A `VDBGridNode`: `pool.flush()` then `grids.update()`, so its shaders see the swapped grid. */\n grids?: { update(): void };\n /**\n * Brick majorant for the grid just shown (`replace` drops the old one). Return `null` / `undefined` to leave the grid\n * without one, e.g. for a preview.\n */\n majorant?: (event: VDBCoarseFirstEvent) => VDBBrickMajorant | null | undefined;\n}\n\n/** What a coarse-first stream delivers. */\nexport type VDBCoarseFirstSource = Response | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;\n\n/** One grid shown in the pool. */\nexport interface VDBCoarseFirstEvent {\n /** The pool id (the same for every grid of the family). */\n id: number;\n /** The grid as the stream reader emitted it (`lod` is null for the full grid). */\n grid: NvdbStreamGrid;\n /** True for the full grid: the last swap. */\n final: boolean;\n /** `'add'` for the first grid shown, `'replace'` after. */\n action: \"add\" | \"replace\";\n /** File bytes received when the grid was shown (decoded bytes; see the e2e for compressed counts). */\n bytesReceived: number;\n /** Expected file size when the grid was shown, or null if unknown (K4.20; see `NvdbProgress.bytesTotal`). */\n bytesTotal: number | null;\n /** This grid's voxel size over the full grid's (x axis): 1 for the full grid, > 1 for a preview. */\n voxelRatio: number;\n /**\n * G16a: the grid types of the family's grids (the file lists every grid's metadata before any data, so this holds\n * the full grid's type from the first event on), in `VDB_GRID_TYPE_NAMES` order (`float, fp4, fp8, fp16, fpn`, not\n * alphabetical), each once. A `VDBGridNode` made with `types: event.types` decodes the\n * preview and the full grid with one module (a baked FpN preview and an Fp8 full grid differ), so a source made\n * with `followImage` swaps without a recompile.\n */\n types: VDBGridTypeName[];\n}\n\nexport interface VDBCoarseFirstOptions {\n /** Which family to load, by the full grid's name. Default: the first grid's family. */\n gridName?: string;\n /** Pool label for the id. Default: the full grid's name. */\n label?: string;\n /** Limits for the stream reader. */\n reader?: NvdbStreamReaderOptions;\n /**\n * Keeps a material, proxy mesh, grid node and majorant in step with each swap, before `onGrid` runs (see\n * {@link VDBCoarseFirstBind} and {@link vdbCoarseFirstApply}). Needs a pool with `flush` / `info` / `setMajorant`\n * (a `VDBGridPool`).\n */\n bind?: VDBCoarseFirstBind;\n /** Called after each `pool.add` / `pool.replace` (preview, then finer grids, then the full grid), after `bind`. */\n onGrid?: (event: VDBCoarseFirstEvent) => void;\n /** Called after every received chunk with the byte progress (K4.20). `bytesTotal` is the Response's Content-Length, else derived from the file's metadata. */\n onProgress?: (progress: NvdbProgress) => void;\n /** Aborts the read (rejects with the signal's reason; the id, if added, stays in the pool). */\n signal?: AbortSignal;\n}\n\nexport interface VDBCoarseFirstResult {\n id: number;\n /** Every grid shown, in order (the preview(s), then the full grid). */\n shown: VDBCoarseFirstEvent[];\n /** File bytes received when the first grid was added. */\n firstBytes: number;\n /** File bytes received when the full grid replaced the preview. */\n fullBytes: number;\n /** Expected file size when the full grid arrived, or null if unknown. */\n bytesTotal: number | null;\n}\n\n/** The base density scale of each bound material (the value seen at its first swap, unless `bind.densityScale` says). */\nconst baseScale = new WeakMap<object, number>();\n\n/**\n * The work `bind` does after a swap, callable on its own from an async `onGrid` (or any code that shows a\n * {@link VDBCoarseFirstEvent}): majorant, proxy geometry, `pool.flush()` + `grids.update()`, density scale. It never\n * touches what `bind` leaves out.\n */\nexport function vdbCoarseFirstApply(\n pool: VDBCoarseFirstPoolLike & Partial<VDBCoarseFirstBindPoolLike>,\n event: VDBCoarseFirstEvent,\n bind: VDBCoarseFirstBind,\n): void {\n const need = <K extends keyof VDBCoarseFirstBindPoolLike>(name: K): NonNullable<VDBCoarseFirstBindPoolLike[K]> => {\n const fn = pool[name];\n if (typeof fn !== \"function\") {\n throw new VDBError(\"VDB_BAD_OPTION\", `vdbStreamCoarseFirst: \\`bind\\` needs a pool with ${name}() (a VDBGridPool).`);\n }\n return fn.bind(pool) as NonNullable<VDBCoarseFirstBindPoolLike[K]>;\n };\n if (bind.majorant) {\n const majorant = bind.majorant(event);\n if (majorant) need(\"setMajorant\")(event.id, majorant);\n }\n if (bind.mesh) {\n const next = vdbProxyGeometry(need(\"info\")(event.id), bind.proxyPad === undefined ? {} : { pad: bind.proxyPad });\n bind.mesh.geometry.dispose();\n bind.mesh.geometry = next;\n }\n if (bind.grids) {\n need(\"flush\")();\n bind.grids.update();\n }\n const material = bind.material;\n if (material) {\n const base = bind.densityScale ?? baseScale.get(material) ?? material.densityScale.value;\n baseScale.set(material, base);\n material.densityScale.value = base * event.voxelRatio;\n }\n}\n\nconst familyOf = (name: string): string => parseNvdbLodName(name).baseName;\n\n/** Finest first: the full grid (lod null) beats any preview; a larger resolution beats a smaller. */\nfunction finer(a: NvdbStreamGrid, b: NvdbStreamGrid | null): boolean {\n if (b === null) return true;\n if (b.lod === null) return false;\n if (a.lod === null) return true;\n return a.lod > b.lod;\n}\n\nfunction chunks(source: VDBCoarseFirstSource): { iterate: AsyncIterable<Uint8Array>; cancel: () => Promise<void> } {\n const stream = source instanceof Response ? source.body : source;\n if (source instanceof Response && !source.ok) {\n throw new VDBError(\"VDB_BAD_OPTION\", `vdbStreamCoarseFirst: the response is ${source.status} ${source.statusText} (${source.url}).`);\n }\n if (stream === null) throw new VDBError(\"VDB_BAD_OPTION\", \"vdbStreamCoarseFirst: the response has no body.\");\n if (typeof (stream as ReadableStream<Uint8Array>).getReader === \"function\") {\n const reader = (stream as ReadableStream<Uint8Array>).getReader();\n return {\n iterate: {\n async *[Symbol.asyncIterator]() {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) return;\n yield value;\n }\n },\n },\n cancel: () => reader.cancel().catch(() => undefined),\n };\n }\n const iterable = stream as AsyncIterable<Uint8Array>;\n return { iterate: iterable, cancel: async () => undefined };\n}\n\n/**\n * Streams a coarse-first `.nvdb` into one pool id: `add` the first grid of the\n * family with the family's largest size reserved, then `replace` with each\n * finer grid. Resolves when the full grid is in the pool (the rest of the\n * stream is cancelled). Rejects with the reader's `NvdbFormatError` on bad\n * or truncated data.\n */\nexport async function vdbStreamCoarseFirst(\n pool: VDBCoarseFirstPoolLike & Partial<VDBCoarseFirstBindPoolLike>,\n source: VDBCoarseFirstSource,\n options: VDBCoarseFirstOptions = {},\n): Promise<VDBCoarseFirstResult> {\n const signal = options.signal;\n signal?.throwIfAborted();\n const wire = source instanceof Response ? nvdbResponseLength(source) : null;\n const reader = new NvdbStreamReader({\n ...options.reader,\n ...(wire !== null && options.reader?.bytesTotal === undefined ? { bytesTotal: wire } : {}),\n ...(options.onProgress ? { onProgress: options.onProgress } : {}),\n });\n const { iterate, cancel } = chunks(source);\n\n let family = options.gridName ?? null;\n let id = -1;\n let current: NvdbStreamGrid | null = null;\n const shown: VDBCoarseFirstEvent[] = [];\n\n const familyGrids = (): NvdbGridMetadata[] => reader.grids.filter((g) => familyOf(g.name) === family);\n const fullVoxel = (grid: NvdbStreamGrid): number => {\n const full = familyGrids().find((g) => g.name === family);\n return full ? grid.metadata.voxelSize[0] / full.voxelSize[0] : 1;\n };\n // The reader accepts only the pool's scalar types (Float, Fp4, Fp8, Fp16, FpN: the names in lower case).\n const familyTypes = (): VDBGridTypeName[] => {\n const names = new Set(familyGrids().map((g) => g.gridType.toLowerCase()));\n return VDB_GRID_TYPE_NAMES.filter((t) => names.has(t));\n };\n\n try {\n for await (const chunk of iterate) {\n signal?.throwIfAborted();\n for (const grid of reader.push(chunk)) {\n family ??= grid.baseName;\n if (grid.baseName !== family || !finer(grid, current)) continue;\n const final = grid.lod === null;\n let action: \"add\" | \"replace\";\n if (id < 0) {\n const capacity = Math.max(...familyGrids().map((g) => g.gridByteSize));\n id = pool.add(grid.image, { capacity, label: options.label ?? family });\n action = \"add\";\n } else {\n pool.replace(id, grid.image);\n action = \"replace\";\n }\n current = grid;\n const event: VDBCoarseFirstEvent = { id, grid, final, action, bytesReceived: grid.bytesReceived, bytesTotal: grid.bytesTotal, voxelRatio: fullVoxel(grid), types: familyTypes() };\n shown.push(event);\n if (options.bind) vdbCoarseFirstApply(pool, event, options.bind);\n options.onGrid?.(event);\n if (final) {\n await cancel();\n return { id, shown, firstBytes: shown[0]!.bytesReceived, fullBytes: grid.bytesReceived, bytesTotal: grid.bytesTotal };\n }\n }\n }\n reader.end();\n } catch (err) {\n await cancel();\n throw err;\n }\n throw new VDBError(\n \"VDB_BAD_IMAGE\",\n family === null\n ? \"vdbStreamCoarseFirst: the stream held no grid.\"\n : `vdbStreamCoarseFirst: the stream ended without the full grid \"${family}\" (grids: ${reader.grids.map((g) => g.name).join(\", \")}).`,\n );\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* three.js wrappers over the core compute tools (K2.3). v1's raw-WebGPU
|
|
3
|
+
* kernels (`gridStats`, `valueTransform`, `decodeToAtlas` over a
|
|
4
|
+
* `NanoVDBGrid` and the vendored WGSL text) moved into the engine-free core
|
|
5
|
+
* (`core/compute/`) and now read grids from a `VDBGridPool`; these wrappers
|
|
6
|
+
* take the renderer instead of a device (`getDevice(renderer)`), submit their
|
|
7
|
+
* own encoder and return a promise.
|
|
8
|
+
*
|
|
9
|
+
* | v1 | core (`@pmndrs/vdb`) | this file (`@pmndrs/vdb/three`) |
|
|
10
|
+
* |---|---|---|
|
|
11
|
+
* | `vdbGridStatsGpu(device, grid, pnanovdbSource, opts)` | `vdbGridStatsGpu(device, pool, id, opts)` → `VDBReadback` | `vdbGridStats(renderer, pool, id, opts)` → `Promise` |
|
|
12
|
+
* | `vdbDecodeToAtlasGpu(device, grid, pnanovdbSource, opts)` | `vdbDecodeToAtlasGpu(device, pool, id, opts)` → `VDBAtlasReadback` | `vdbDecodeToAtlas(renderer, pool, id, opts)` → `Promise`, plus a ready `Data3DTexture` |
|
|
13
|
+
* | `valueTransform(device, grid, pnanovdbSource, wgslBodyOrPreset)` | `vdbApplyValueTransform(pool, id, sourceImage, fnOrPreset)` (CPU + `pool.replace`) | — (use the core function) |
|
|
14
|
+
*
|
|
15
|
+
* The `vdb` prefix keeps these apart from the core functions of the same job
|
|
16
|
+
* (D17). For recording into your own encoder (the D8 pattern), use the core
|
|
17
|
+
* functions directly with `getDevice(renderer)`; then submit, and
|
|
18
|
+
* `job.submitted().read()`.
|
|
19
|
+
*/
|
|
20
|
+
import { Data3DTexture } from "three";
|
|
21
|
+
import type { VDBGridPool } from "../core/pool/pool.js";
|
|
22
|
+
import { type VDBGridStats } from "../core/compute/stats.js";
|
|
23
|
+
import { type VDBAtlas, type VDBDecodeToAtlasOptions } from "../core/compute/atlas.js";
|
|
24
|
+
import { type VDBThreeRendererLike } from "./device.js";
|
|
25
|
+
/** Options of {@link vdbGridStats}. */
|
|
26
|
+
export interface VDBThreeGridStatsOptions {
|
|
27
|
+
/** Histogram bins over `[rootMin, rootMax]`. Default 256. */
|
|
28
|
+
histogramBins?: number;
|
|
29
|
+
}
|
|
30
|
+
/** What {@link vdbGridStats} resolves with: the core's `VDBGridStats` (v1's result plus the histogram `range`). */
|
|
31
|
+
export type VDBGridStatsResult = VDBGridStats;
|
|
32
|
+
/**
|
|
33
|
+
* Statistics of grid `gridId`: active-voxel min/max/mean/count and a histogram
|
|
34
|
+
* (see the core `gridStats`). The grid must be resident (`pool.flush()` or an
|
|
35
|
+
* update submitted) and the pool must live on the renderer's device. Records
|
|
36
|
+
* into its own encoder and submits it. Rejects (never throws) on bad input.
|
|
37
|
+
*/
|
|
38
|
+
export declare function vdbGridStats(renderer: VDBThreeRendererLike, pool: VDBGridPool, gridId: number, options?: VDBThreeGridStatsOptions): Promise<VDBGridStatsResult>;
|
|
39
|
+
/** Options of {@link vdbDecodeToAtlas}: the core's, without the encoder/readback plumbing. */
|
|
40
|
+
export type VDBThreeDecodeToAtlasOptions = Omit<VDBDecodeToAtlasOptions, "encoder" | "readback">;
|
|
41
|
+
/** v1's result plus a `Data3DTexture` over `data`. */
|
|
42
|
+
export interface VDBDecodeToAtlasResult extends VDBAtlas {
|
|
43
|
+
/**
|
|
44
|
+
* `data` as a three `Data3DTexture`: `RedFormat`, `UnsignedByteType`
|
|
45
|
+
* (`uint8`) or `FloatType` (`float32`), linear filtering, `unpackAlignment`
|
|
46
|
+
* 1, `needsUpdate` set. Sample it with TSL `texture3D(texture, uvw).r`.
|
|
47
|
+
* Linear filtering of a `float32` atlas needs the `float32-filterable`
|
|
48
|
+
* feature; use `uint8` (the default) otherwise. Dispose it yourself.
|
|
49
|
+
*
|
|
50
|
+
* Texel `i` of an axis with `n` texels holds the grid at index
|
|
51
|
+
* `min + (i + 0.5) * (max - min + 1) / n - 0.5`: voxel `min + i` at full
|
|
52
|
+
* resolution (K2.6). The texture spans the voxel-centred box
|
|
53
|
+
* `[min - 0.5, max + 0.5]` of the index bbox (world: that box times the
|
|
54
|
+
* voxel size, through the grid transform).
|
|
55
|
+
*/
|
|
56
|
+
texture: Data3DTexture;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Dense decode of grid `gridId`'s index bbox (see the core `decodeToAtlas`,
|
|
60
|
+
* including its voxel-centre sample convention), read back and wrapped in a
|
|
61
|
+
* `Data3DTexture`. Records into its own encoder and submits it.
|
|
62
|
+
*/
|
|
63
|
+
export declare function vdbDecodeToAtlas(renderer: VDBThreeRendererLike, pool: VDBGridPool, gridId: number, options?: VDBThreeDecodeToAtlasOptions): Promise<VDBDecodeToAtlasResult>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* three.js wrappers over the core compute tools (K2.3). v1's raw-WebGPU
|
|
3
|
+
* kernels (`gridStats`, `valueTransform`, `decodeToAtlas` over a
|
|
4
|
+
* `NanoVDBGrid` and the vendored WGSL text) moved into the engine-free core
|
|
5
|
+
* (`core/compute/`) and now read grids from a `VDBGridPool`; these wrappers
|
|
6
|
+
* take the renderer instead of a device (`getDevice(renderer)`), submit their
|
|
7
|
+
* own encoder and return a promise.
|
|
8
|
+
*
|
|
9
|
+
* | v1 | core (`@pmndrs/vdb`) | this file (`@pmndrs/vdb/three`) |
|
|
10
|
+
* |---|---|---|
|
|
11
|
+
* | `vdbGridStatsGpu(device, grid, pnanovdbSource, opts)` | `vdbGridStatsGpu(device, pool, id, opts)` → `VDBReadback` | `vdbGridStats(renderer, pool, id, opts)` → `Promise` |
|
|
12
|
+
* | `vdbDecodeToAtlasGpu(device, grid, pnanovdbSource, opts)` | `vdbDecodeToAtlasGpu(device, pool, id, opts)` → `VDBAtlasReadback` | `vdbDecodeToAtlas(renderer, pool, id, opts)` → `Promise`, plus a ready `Data3DTexture` |
|
|
13
|
+
* | `valueTransform(device, grid, pnanovdbSource, wgslBodyOrPreset)` | `vdbApplyValueTransform(pool, id, sourceImage, fnOrPreset)` (CPU + `pool.replace`) | — (use the core function) |
|
|
14
|
+
*
|
|
15
|
+
* The `vdb` prefix keeps these apart from the core functions of the same job
|
|
16
|
+
* (D17). For recording into your own encoder (the D8 pattern), use the core
|
|
17
|
+
* functions directly with `getDevice(renderer)`; then submit, and
|
|
18
|
+
* `job.submitted().read()`.
|
|
19
|
+
*/
|
|
20
|
+
import { Data3DTexture, FloatType, LinearFilter, RedFormat, UnsignedByteType } from "three";
|
|
21
|
+
import { vdbGridStatsGpu } from "../core/compute/stats.js";
|
|
22
|
+
import { vdbDecodeToAtlasGpu } from "../core/compute/atlas.js";
|
|
23
|
+
import { getDevice } from "./device.js";
|
|
24
|
+
/**
|
|
25
|
+
* Statistics of grid `gridId`: active-voxel min/max/mean/count and a histogram
|
|
26
|
+
* (see the core `gridStats`). The grid must be resident (`pool.flush()` or an
|
|
27
|
+
* update submitted) and the pool must live on the renderer's device. Records
|
|
28
|
+
* into its own encoder and submits it. Rejects (never throws) on bad input.
|
|
29
|
+
*/
|
|
30
|
+
export function vdbGridStats(renderer, pool, gridId, options = {}) {
|
|
31
|
+
try {
|
|
32
|
+
return vdbGridStatsGpu(getDevice(renderer), pool, gridId, options.histogramBins === undefined ? {} : { histogramBins: options.histogramBins }).read();
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
return Promise.reject(e);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Dense decode of grid `gridId`'s index bbox (see the core `decodeToAtlas`,
|
|
40
|
+
* including its voxel-centre sample convention), read back and wrapped in a
|
|
41
|
+
* `Data3DTexture`. Records into its own encoder and submits it.
|
|
42
|
+
*/
|
|
43
|
+
export async function vdbDecodeToAtlas(renderer, pool, gridId, options = {}) {
|
|
44
|
+
const { encoder: _e, readback: _r, ...rest } = options;
|
|
45
|
+
const atlas = await vdbDecodeToAtlasGpu(getDevice(renderer), pool, gridId, rest).read();
|
|
46
|
+
const [dx, dy, dz] = atlas.dims;
|
|
47
|
+
const texture = new Data3DTexture(atlas.data, dx, dy, dz);
|
|
48
|
+
texture.format = RedFormat;
|
|
49
|
+
texture.type = atlas.data instanceof Uint8Array ? UnsignedByteType : FloatType;
|
|
50
|
+
texture.minFilter = LinearFilter;
|
|
51
|
+
texture.magFilter = LinearFilter;
|
|
52
|
+
texture.unpackAlignment = 1;
|
|
53
|
+
texture.needsUpdate = true;
|
|
54
|
+
return { ...atlas, texture };
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=compute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute.js","sourceRoot":"","sources":["../../src/three/compute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAE5F,OAAO,EAAE,eAAe,EAAqB,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAA+C,MAAM,0BAA0B,CAAC;AAC5G,OAAO,EAAE,SAAS,EAA6B,MAAM,aAAa,CAAC;AAWnE;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,QAA8B,EAC9B,IAAiB,EACjB,MAAc,EACd,UAAoC,EAAE;IAEtC,IAAI,CAAC;QACH,OAAO,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC;AAuBD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAA8B,EAC9B,IAAiB,EACjB,MAAc,EACd,UAAwC,EAAE;IAE1C,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,OAAkC,CAAC;IAClF,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IACxF,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC;IAChC,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC1D,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,OAAO,CAAC,SAAS,GAAG,YAAY,CAAC;IACjC,OAAO,CAAC,SAAS,GAAG,YAAY,CAAC;IACjC,OAAO,CAAC,eAAe,GAAG,CAAC,CAAC;IAC5B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["/**\n * three.js wrappers over the core compute tools (K2.3). v1's raw-WebGPU\n * kernels (`gridStats`, `valueTransform`, `decodeToAtlas` over a\n * `NanoVDBGrid` and the vendored WGSL text) moved into the engine-free core\n * (`core/compute/`) and now read grids from a `VDBGridPool`; these wrappers\n * take the renderer instead of a device (`getDevice(renderer)`), submit their\n * own encoder and return a promise.\n *\n * | v1 | core (`@pmndrs/vdb`) | this file (`@pmndrs/vdb/three`) |\n * |---|---|---|\n * | `vdbGridStatsGpu(device, grid, pnanovdbSource, opts)` | `vdbGridStatsGpu(device, pool, id, opts)` → `VDBReadback` | `vdbGridStats(renderer, pool, id, opts)` → `Promise` |\n * | `vdbDecodeToAtlasGpu(device, grid, pnanovdbSource, opts)` | `vdbDecodeToAtlasGpu(device, pool, id, opts)` → `VDBAtlasReadback` | `vdbDecodeToAtlas(renderer, pool, id, opts)` → `Promise`, plus a ready `Data3DTexture` |\n * | `valueTransform(device, grid, pnanovdbSource, wgslBodyOrPreset)` | `vdbApplyValueTransform(pool, id, sourceImage, fnOrPreset)` (CPU + `pool.replace`) | — (use the core function) |\n *\n * The `vdb` prefix keeps these apart from the core functions of the same job\n * (D17). For recording into your own encoder (the D8 pattern), use the core\n * functions directly with `getDevice(renderer)`; then submit, and\n * `job.submitted().read()`.\n */\nimport { Data3DTexture, FloatType, LinearFilter, RedFormat, UnsignedByteType } from \"three\";\nimport type { VDBGridPool } from \"../core/pool/pool.js\";\nimport { vdbGridStatsGpu, type VDBGridStats } from \"../core/compute/stats.js\";\nimport { vdbDecodeToAtlasGpu, type VDBAtlas, type VDBDecodeToAtlasOptions } from \"../core/compute/atlas.js\";\nimport { getDevice, type VDBThreeRendererLike } from \"./device.js\";\n\n/** Options of {@link vdbGridStats}. */\nexport interface VDBThreeGridStatsOptions {\n /** Histogram bins over `[rootMin, rootMax]`. Default 256. */\n histogramBins?: number;\n}\n\n/** What {@link vdbGridStats} resolves with: the core's `VDBGridStats` (v1's result plus the histogram `range`). */\nexport type VDBGridStatsResult = VDBGridStats;\n\n/**\n * Statistics of grid `gridId`: active-voxel min/max/mean/count and a histogram\n * (see the core `gridStats`). The grid must be resident (`pool.flush()` or an\n * update submitted) and the pool must live on the renderer's device. Records\n * into its own encoder and submits it. Rejects (never throws) on bad input.\n */\nexport function vdbGridStats(\n renderer: VDBThreeRendererLike,\n pool: VDBGridPool,\n gridId: number,\n options: VDBThreeGridStatsOptions = {},\n): Promise<VDBGridStatsResult> {\n try {\n return vdbGridStatsGpu(getDevice(renderer), pool, gridId, options.histogramBins === undefined ? {} : { histogramBins: options.histogramBins }).read();\n } catch (e) {\n return Promise.reject(e);\n }\n}\n\n/** Options of {@link vdbDecodeToAtlas}: the core's, without the encoder/readback plumbing. */\nexport type VDBThreeDecodeToAtlasOptions = Omit<VDBDecodeToAtlasOptions, \"encoder\" | \"readback\">;\n\n/** v1's result plus a `Data3DTexture` over `data`. */\nexport interface VDBDecodeToAtlasResult extends VDBAtlas {\n /**\n * `data` as a three `Data3DTexture`: `RedFormat`, `UnsignedByteType`\n * (`uint8`) or `FloatType` (`float32`), linear filtering, `unpackAlignment`\n * 1, `needsUpdate` set. Sample it with TSL `texture3D(texture, uvw).r`.\n * Linear filtering of a `float32` atlas needs the `float32-filterable`\n * feature; use `uint8` (the default) otherwise. Dispose it yourself.\n *\n * Texel `i` of an axis with `n` texels holds the grid at index\n * `min + (i + 0.5) * (max - min + 1) / n - 0.5`: voxel `min + i` at full\n * resolution (K2.6). The texture spans the voxel-centred box\n * `[min - 0.5, max + 0.5]` of the index bbox (world: that box times the\n * voxel size, through the grid transform).\n */\n texture: Data3DTexture;\n}\n\n/**\n * Dense decode of grid `gridId`'s index bbox (see the core `decodeToAtlas`,\n * including its voxel-centre sample convention), read back and wrapped in a\n * `Data3DTexture`. Records into its own encoder and submits it.\n */\nexport async function vdbDecodeToAtlas(\n renderer: VDBThreeRendererLike,\n pool: VDBGridPool,\n gridId: number,\n options: VDBThreeDecodeToAtlasOptions = {},\n): Promise<VDBDecodeToAtlasResult> {\n const { encoder: _e, readback: _r, ...rest } = options as VDBDecodeToAtlasOptions;\n const atlas = await vdbDecodeToAtlasGpu(getDevice(renderer), pool, gridId, rest).read();\n const [dx, dy, dz] = atlas.dims;\n const texture = new Data3DTexture(atlas.data, dx, dy, dz);\n texture.format = RedFormat;\n texture.type = atlas.data instanceof Uint8Array ? UnsignedByteType : FloatType;\n texture.minFilter = LinearFilter;\n texture.magFilter = LinearFilter;\n texture.unpackAlignment = 1;\n texture.needsUpdate = true;\n return { ...atlas, texture };\n}\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The raw WebGPU handles behind a three.js `WebGPURenderer` (task K2.1).
|
|
3
|
+
*
|
|
4
|
+
* Same helpers and semantics as `@pmndrs/upscaler` and `@pmndrs/denoiser`
|
|
5
|
+
* (`getDevice`, `getGPUTexture`), so every pmndrs tool in a frame shares the
|
|
6
|
+
* renderer's one `GPUDevice`: create the pool with
|
|
7
|
+
* `VDBGridPool.create(getDevice(renderer))`.
|
|
8
|
+
*
|
|
9
|
+
* Typed structurally (`VDBThreeRendererLike`, the downsampler's pattern), so this
|
|
10
|
+
* file needs nothing from three at runtime. It reads two backend internals,
|
|
11
|
+
* checked against three r187 (the peer range):
|
|
12
|
+
* - `renderer.backend.device`: the `GPUDevice` (null until `renderer.init()`
|
|
13
|
+
* resolves; absent on the WebGL fallback backend);
|
|
14
|
+
* - `renderer.backend.get(texture).texture`: the `GPUTexture` behind a three
|
|
15
|
+
* texture once it is allocated.
|
|
16
|
+
*
|
|
17
|
+
* A renderer built without a `device` parameter owns its device and destroys
|
|
18
|
+
* it in `renderer.dispose()`, and with it every buffer on it (the pool's
|
|
19
|
+
* too). To keep a pool alive past the renderer, create the device yourself and
|
|
20
|
+
* pass it: `new WebGPURenderer({ device })`.
|
|
21
|
+
*/
|
|
22
|
+
/** The parts of three's WebGPU backend the adapter reads (structural, three r187). */
|
|
23
|
+
export interface VDBThreeBackendLike {
|
|
24
|
+
readonly isWebGPUBackend?: boolean;
|
|
25
|
+
readonly device?: GPUDevice | null;
|
|
26
|
+
get(object: object): {
|
|
27
|
+
texture?: GPUTexture;
|
|
28
|
+
buffer?: GPUBuffer;
|
|
29
|
+
} & Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The part of a three.js `WebGPURenderer` the adapter uses (structural, so
|
|
33
|
+
* `three` stays an optional peer). `backend` is typed loosely because
|
|
34
|
+
* `@types/three` does not declare the internals read here (`get`); they are
|
|
35
|
+
* checked at runtime instead.
|
|
36
|
+
*/
|
|
37
|
+
export interface VDBThreeRendererLike {
|
|
38
|
+
readonly backend: object;
|
|
39
|
+
}
|
|
40
|
+
/** Throws unless `renderer` is an initialized `WebGPURenderer` on its WebGPU backend; returns that backend. */
|
|
41
|
+
export declare function webgpuBackendOf(renderer: unknown, what?: string): VDBThreeBackendLike & {
|
|
42
|
+
readonly device: GPUDevice;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* The `GPUDevice` an initialized `WebGPURenderer` renders with. Create the
|
|
46
|
+
* pool (and the other pmndrs tools) on it so they share one device.
|
|
47
|
+
*
|
|
48
|
+
* @throws VDBError `VDB_UNSUPPORTED_DEVICE` before `await renderer.init()`, or on the WebGL fallback backend.
|
|
49
|
+
*/
|
|
50
|
+
export declare function getDevice(renderer: VDBThreeRendererLike): GPUDevice;
|
|
51
|
+
/**
|
|
52
|
+
* The raw `GPUTexture` behind a three texture (render-target attachment,
|
|
53
|
+
* `DepthTexture`, `StorageTexture`...). It must already be allocated: render to
|
|
54
|
+
* it once or call `renderer.initTexture(texture)`.
|
|
55
|
+
*
|
|
56
|
+
* @throws VDBError `VDB_UNSUPPORTED_DEVICE` for an uninitialized or non-WebGPU
|
|
57
|
+
* renderer; `VDB_BAD_OPTION` if the texture has no GPU allocation yet.
|
|
58
|
+
*/
|
|
59
|
+
export declare function getGPUTexture(renderer: VDBThreeRendererLike, texture: object): GPUTexture;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The raw WebGPU handles behind a three.js `WebGPURenderer` (task K2.1).
|
|
3
|
+
*
|
|
4
|
+
* Same helpers and semantics as `@pmndrs/upscaler` and `@pmndrs/denoiser`
|
|
5
|
+
* (`getDevice`, `getGPUTexture`), so every pmndrs tool in a frame shares the
|
|
6
|
+
* renderer's one `GPUDevice`: create the pool with
|
|
7
|
+
* `VDBGridPool.create(getDevice(renderer))`.
|
|
8
|
+
*
|
|
9
|
+
* Typed structurally (`VDBThreeRendererLike`, the downsampler's pattern), so this
|
|
10
|
+
* file needs nothing from three at runtime. It reads two backend internals,
|
|
11
|
+
* checked against three r187 (the peer range):
|
|
12
|
+
* - `renderer.backend.device`: the `GPUDevice` (null until `renderer.init()`
|
|
13
|
+
* resolves; absent on the WebGL fallback backend);
|
|
14
|
+
* - `renderer.backend.get(texture).texture`: the `GPUTexture` behind a three
|
|
15
|
+
* texture once it is allocated.
|
|
16
|
+
*
|
|
17
|
+
* A renderer built without a `device` parameter owns its device and destroys
|
|
18
|
+
* it in `renderer.dispose()`, and with it every buffer on it (the pool's
|
|
19
|
+
* too). To keep a pool alive past the renderer, create the device yourself and
|
|
20
|
+
* pass it: `new WebGPURenderer({ device })`.
|
|
21
|
+
*/
|
|
22
|
+
import { VDBError } from "../core/errors.js";
|
|
23
|
+
/** Throws unless `renderer` is an initialized `WebGPURenderer` on its WebGPU backend; returns that backend. */
|
|
24
|
+
export function webgpuBackendOf(renderer, what = "getDevice") {
|
|
25
|
+
const backend = renderer?.backend;
|
|
26
|
+
if (backend?.isWebGPUBackend !== true || !backend.device || typeof backend.get !== "function") {
|
|
27
|
+
throw new VDBError("VDB_UNSUPPORTED_DEVICE", `three adapter: ${what} requires an initialized WebGPURenderer (await renderer.init()) on its WebGPU backend; ` +
|
|
28
|
+
"the WebGL fallback backend has no GPUDevice.");
|
|
29
|
+
}
|
|
30
|
+
return backend;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The `GPUDevice` an initialized `WebGPURenderer` renders with. Create the
|
|
34
|
+
* pool (and the other pmndrs tools) on it so they share one device.
|
|
35
|
+
*
|
|
36
|
+
* @throws VDBError `VDB_UNSUPPORTED_DEVICE` before `await renderer.init()`, or on the WebGL fallback backend.
|
|
37
|
+
*/
|
|
38
|
+
export function getDevice(renderer) {
|
|
39
|
+
return webgpuBackendOf(renderer, "getDevice").device;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The raw `GPUTexture` behind a three texture (render-target attachment,
|
|
43
|
+
* `DepthTexture`, `StorageTexture`...). It must already be allocated: render to
|
|
44
|
+
* it once or call `renderer.initTexture(texture)`.
|
|
45
|
+
*
|
|
46
|
+
* @throws VDBError `VDB_UNSUPPORTED_DEVICE` for an uninitialized or non-WebGPU
|
|
47
|
+
* renderer; `VDB_BAD_OPTION` if the texture has no GPU allocation yet.
|
|
48
|
+
*/
|
|
49
|
+
export function getGPUTexture(renderer, texture) {
|
|
50
|
+
const backend = webgpuBackendOf(renderer, "getGPUTexture");
|
|
51
|
+
const gpuTexture = backend.get(texture)?.texture;
|
|
52
|
+
if (!gpuTexture) {
|
|
53
|
+
const named = texture;
|
|
54
|
+
throw new VDBError("VDB_BAD_OPTION", `three adapter: no GPUTexture behind "${named.name || named.uuid || "texture"}" yet. ` +
|
|
55
|
+
"Render to it once or call renderer.initTexture(texture) first.");
|
|
56
|
+
}
|
|
57
|
+
return gpuTexture;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=device.js.map
|