@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 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/source/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG","sourcesContent":["/**\n * The volume-source seam of the K3 renderer (R1 §4.2): the renderer's shading\n * reads density, mask, albedo and emission through one interface, with two\n * sources behind it, the sparse `VDBGridPool` (K3.2) and dense `.wvdb` levels\n * (`vdbDenseSource`, K3.0). It mirrors mjurczyk's `createVolumeNodes()`\n * (frameShaderChunks.js L834–1028), so his materials port with call-site edits.\n */\n\nimport type { VDBSlot } from \"../types.js\";\n\n/** Optional channels of a source; absent channels compile to constants (mask 1, albedo 1, emission 0). */\nexport interface VDBVolumeChannels {\n readonly mask: boolean;\n readonly albedo: boolean;\n readonly emission: boolean;\n}\n\n/** The descriptive half of a source: what every adapter needs, whatever it binds. */\nexport interface VDBVolumeSourceInfo {\n readonly kind: \"sparse\" | \"dense\";\n /** Voxels across the box at lod 0 (dense: the texture size; sparse: the index bbox extent). */\n readonly texels: readonly [number, number, number];\n /** Prefiltered levels available above level 0 (0 = level 0 only). */\n readonly lodLevels: number;\n readonly channels: VDBVolumeChannels;\n /** `meanNonZero` feeds `normalizeDensity`; `max` bounds the density; `activeVoxels` counts non-zero voxels. */\n readonly stats: { readonly meanNonZero: number; readonly max: number; readonly activeVoxels: number };\n /** Column-major 4x4: local unit box [-0.5, 0.5]³ → source space (dense: uvw in [0, 1]³; sparse: index space). */\n readonly boxToSource: Float32Array;\n /** Bumps when bindings must be rebuilt (new textures after a LOD swap, pool growth). */\n readonly version: number;\n}\n\n/** Options of {@link VDBVolumeSource.wgsl}. */\nexport interface VDBVolumeSourceWgslOptions {\n readonly slot: VDBSlot;\n /** `march` adds `vdbSrcSkipEmpty` and `vdbSrcMaxIn`. */\n readonly profile: \"sample\" | \"march\";\n /** Turn channels the source has off (compiled to constants). Channels it lacks are always constants. */\n readonly channels?: Partial<VDBVolumeChannels>;\n}\n\n/**\n * A volume source for raw WebGPU kernels. Generated WGSL (all names `vdbSrc*`):\n *\n * fn vdbSrcDensity (v: u32, uvw: vec3f, lod: f32) -> f32; // dense: [0, 1]\n * fn vdbSrcMask (v: u32, uvw: vec3f, lod: f32) -> f32; // 1.0 when absent\n * fn vdbSrcAlbedo (v: u32, uvw: vec3f, lod: f32) -> vec3f; // vec3(1) when absent\n * fn vdbSrcEmission(v: u32, uvw: vec3f, lod: f32) -> f32; // 0.0 when absent\n * fn vdbSrcTexels (v: u32) -> vec3f;\n * fn vdbSrcLodLevels(v: u32) -> f32;\n * // profile 'march':\n * fn vdbSrcSkipEmpty(v: u32, o: vec3f, d: vec3f, t0: f32, t1: f32) -> f32;\n * fn vdbSrcMaxIn (v: u32, uvwMin: vec3f, uvwMax: vec3f) -> f32;\n *\n * `uvw` is in [0, 1]³ of the source box, already offset and wrapped by the\n * caller; `lod` is in levels (log2 of the footprint in lod-0 voxels).\n */\nexport interface VDBVolumeSource extends VDBVolumeSourceInfo {\n wgsl(o: VDBVolumeSourceWgslOptions): string;\n layoutEntries(slot: VDBSlot, visibility?: GPUShaderStageFlags): GPUBindGroupLayoutEntry[];\n bindEntries(slot: VDBSlot): GPUBindGroupEntry[];\n dispose(): void;\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types and tables shared by the pool (`pool/`) and the WGSL generator
|
|
3
|
+
* (`wgsl/`). One home so the two cannot drift (K1 integration).
|
|
4
|
+
*/
|
|
5
|
+
/** Grid value types the pool can hold and the generated WGSL can decode (NanoVDB `GridType` ids 1, 13-16). */
|
|
6
|
+
export type VDBGridTypeName = "float" | "fp4" | "fp8" | "fp16" | "fpn";
|
|
7
|
+
/**
|
|
8
|
+
* NanoVDB `GridType` id per name (`PNANOVDB_GRID_TYPE_*` in the vendored module).
|
|
9
|
+
* `test/core/types.test.ts` checks it against the vendored stride tables, the
|
|
10
|
+
* vendored WGSL constants and `tools`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const VDB_GRID_TYPE_IDS: Readonly<Record<VDBGridTypeName, number>>;
|
|
13
|
+
/** Canonical order; the generator sorts `types` into it so equal sets give equal bytes. */
|
|
14
|
+
export declare const VDB_GRID_TYPE_NAMES: readonly VDBGridTypeName[];
|
|
15
|
+
/**
|
|
16
|
+
* Every scalar grid type the pool can hold, for
|
|
17
|
+
* `vdbModuleWgsl({ types: VDB_ALL_SCALAR_TYPES, ... })`: a module that reads
|
|
18
|
+
* any grid a host may add later, so it never has to be regenerated and its
|
|
19
|
+
* pipeline rebuilt. The price is the largest module (every decoder); a host
|
|
20
|
+
* that knows its types up front should list just those. Same contents and
|
|
21
|
+
* order as {@link VDB_GRID_TYPE_NAMES}.
|
|
22
|
+
*/
|
|
23
|
+
export declare const VDB_ALL_SCALAR_TYPES: readonly VDBGridTypeName[];
|
|
24
|
+
/** Where a kernel binds the pool: `@group(group) @binding(firstBinding)`. Layout 1 uses one binding (D10). */
|
|
25
|
+
export interface VDBSlot {
|
|
26
|
+
readonly group: number;
|
|
27
|
+
readonly firstBinding: number;
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types and tables shared by the pool (`pool/`) and the WGSL generator
|
|
3
|
+
* (`wgsl/`). One home so the two cannot drift (K1 integration).
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* NanoVDB `GridType` id per name (`PNANOVDB_GRID_TYPE_*` in the vendored module).
|
|
7
|
+
* `test/core/types.test.ts` checks it against the vendored stride tables, the
|
|
8
|
+
* vendored WGSL constants and `tools`.
|
|
9
|
+
*/
|
|
10
|
+
export const VDB_GRID_TYPE_IDS = {
|
|
11
|
+
float: 1,
|
|
12
|
+
fp4: 13,
|
|
13
|
+
fp8: 14,
|
|
14
|
+
fp16: 15,
|
|
15
|
+
fpn: 16,
|
|
16
|
+
};
|
|
17
|
+
/** Canonical order; the generator sorts `types` into it so equal sets give equal bytes. */
|
|
18
|
+
export const VDB_GRID_TYPE_NAMES = ["float", "fp4", "fp8", "fp16", "fpn"];
|
|
19
|
+
/**
|
|
20
|
+
* Every scalar grid type the pool can hold, for
|
|
21
|
+
* `vdbModuleWgsl({ types: VDB_ALL_SCALAR_TYPES, ... })`: a module that reads
|
|
22
|
+
* any grid a host may add later, so it never has to be regenerated and its
|
|
23
|
+
* pipeline rebuilt. The price is the largest module (every decoder); a host
|
|
24
|
+
* that knows its types up front should list just those. Same contents and
|
|
25
|
+
* order as {@link VDB_GRID_TYPE_NAMES}.
|
|
26
|
+
*/
|
|
27
|
+
export const VDB_ALL_SCALAR_TYPES = Object.freeze([...VDB_GRID_TYPE_NAMES]);
|
|
28
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA8C;IAC1E,KAAK,EAAE,CAAC;IACR,GAAG,EAAE,EAAE;IACP,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,EAAE;IACR,GAAG,EAAE,EAAE;CACR,CAAC;AAEF,2FAA2F;AAC3F,MAAM,CAAC,MAAM,mBAAmB,GAA+B,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAEtG;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA+B,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Types and tables shared by the pool (`pool/`) and the WGSL generator\n * (`wgsl/`). One home so the two cannot drift (K1 integration).\n */\n\n/** Grid value types the pool can hold and the generated WGSL can decode (NanoVDB `GridType` ids 1, 13-16). */\nexport type VDBGridTypeName = \"float\" | \"fp4\" | \"fp8\" | \"fp16\" | \"fpn\";\n\n/**\n * NanoVDB `GridType` id per name (`PNANOVDB_GRID_TYPE_*` in the vendored module).\n * `test/core/types.test.ts` checks it against the vendored stride tables, the\n * vendored WGSL constants and `tools`.\n */\nexport const VDB_GRID_TYPE_IDS: Readonly<Record<VDBGridTypeName, number>> = {\n float: 1,\n fp4: 13,\n fp8: 14,\n fp16: 15,\n fpn: 16,\n};\n\n/** Canonical order; the generator sorts `types` into it so equal sets give equal bytes. */\nexport const VDB_GRID_TYPE_NAMES: readonly VDBGridTypeName[] = [\"float\", \"fp4\", \"fp8\", \"fp16\", \"fpn\"];\n\n/**\n * Every scalar grid type the pool can hold, for\n * `vdbModuleWgsl({ types: VDB_ALL_SCALAR_TYPES, ... })`: a module that reads\n * any grid a host may add later, so it never has to be regenerated and its\n * pipeline rebuilt. The price is the largest module (every decoder); a host\n * that knows its types up front should list just those. Same contents and\n * order as {@link VDB_GRID_TYPE_NAMES}.\n */\nexport const VDB_ALL_SCALAR_TYPES: readonly VDBGridTypeName[] = Object.freeze([...VDB_GRID_TYPE_NAMES]);\n\n/** Where a kernel binds the pool: `@group(group) @binding(firstBinding)`. Layout 1 uses one binding (D10). */\nexport interface VDBSlot {\n readonly group: number;\n readonly firstBinding: number;\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public `vdb*` WGSL API layered over the vendored traversal
|
|
3
|
+
* (docs/dev/design/K1-core.md §3.2). Written in the generated module's final names:
|
|
4
|
+
* vendored declarations appear renamed (`vdb_*`, `VDB_*`), and the generator
|
|
5
|
+
* pulls in exactly the vendored declarations this text references.
|
|
6
|
+
*
|
|
7
|
+
* Every pool read goes through `vdb_load`, the module's one buffer access,
|
|
8
|
+
* which the generator emits for the chosen binding mode.
|
|
9
|
+
*
|
|
10
|
+
* Layers stack: `sample` includes `read`, `march` includes `sample`
|
|
11
|
+
* (`majorant` is deferred past 0.1, D22). Each layer is a function of the
|
|
12
|
+
* normalized options and the profile rank.
|
|
13
|
+
*
|
|
14
|
+
* Conventions every layer keeps:
|
|
15
|
+
* - A grid id is usable when it is below `vdbGridCount()` and its record is
|
|
16
|
+
* live. Every per-grid function checks that first: a dead or out-of-range
|
|
17
|
+
* id never reads a zeroed record or image bytes as a record.
|
|
18
|
+
* - Voxel centres sit at integer index coordinates (the vendored trilinear and
|
|
19
|
+
* NanoVDB `SampleFromVoxels`); HDDA cells are floor-based, so voxel `i`
|
|
20
|
+
* occupies `[i, i + 1)` for ray clipping and traversal.
|
|
21
|
+
*/
|
|
22
|
+
import type { VDBGridTypeName } from "../types.js";
|
|
23
|
+
import type { VDBModuleHelper } from "./types.js";
|
|
24
|
+
/** Options the API layer depends on (normalized by the generator). */
|
|
25
|
+
export interface ApiOptions {
|
|
26
|
+
readonly types: readonly VDBGridTypeName[];
|
|
27
|
+
readonly isActive: boolean;
|
|
28
|
+
readonly sampler: "trilinear" | "nearest";
|
|
29
|
+
readonly outside: "background" | "zero";
|
|
30
|
+
/** Opt-in helpers, canonical order; the generator has checked each one's profile. */
|
|
31
|
+
readonly helpers: readonly VDBModuleHelper[];
|
|
32
|
+
}
|
|
33
|
+
/** Vendored grid-type constant names (after the rename) per compiled type. */
|
|
34
|
+
export declare const GRID_TYPE_CONSTANT: Readonly<Record<VDBGridTypeName, string>>;
|
|
35
|
+
/**
|
|
36
|
+
* API layers in profile order. A profile's API is every layer up to and
|
|
37
|
+
* including its own (`majorant`, rank 3, is deferred past 0.1, D22).
|
|
38
|
+
*/
|
|
39
|
+
export declare const API_LAYERS: readonly ((o: ApiOptions, profileRank: number) => string)[];
|
|
40
|
+
/** The public API text for the profile at `profileRank` (0 = read, 1 = sample, 2 = march), then the requested helpers. */
|
|
41
|
+
export declare function apiWgsl(profileRank: number, o: ApiOptions): string;
|
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public `vdb*` WGSL API layered over the vendored traversal
|
|
3
|
+
* (docs/dev/design/K1-core.md §3.2). Written in the generated module's final names:
|
|
4
|
+
* vendored declarations appear renamed (`vdb_*`, `VDB_*`), and the generator
|
|
5
|
+
* pulls in exactly the vendored declarations this text references.
|
|
6
|
+
*
|
|
7
|
+
* Every pool read goes through `vdb_load`, the module's one buffer access,
|
|
8
|
+
* which the generator emits for the chosen binding mode.
|
|
9
|
+
*
|
|
10
|
+
* Layers stack: `sample` includes `read`, `march` includes `sample`
|
|
11
|
+
* (`majorant` is deferred past 0.1, D22). Each layer is a function of the
|
|
12
|
+
* normalized options and the profile rank.
|
|
13
|
+
*
|
|
14
|
+
* Conventions every layer keeps:
|
|
15
|
+
* - A grid id is usable when it is below `vdbGridCount()` and its record is
|
|
16
|
+
* live. Every per-grid function checks that first: a dead or out-of-range
|
|
17
|
+
* id never reads a zeroed record or image bytes as a record.
|
|
18
|
+
* - Voxel centres sit at integer index coordinates (the vendored trilinear and
|
|
19
|
+
* NanoVDB `SampleFromVoxels`); HDDA cells are floor-based, so voxel `i`
|
|
20
|
+
* occupies `[i, i + 1)` for ray clipping and traversal.
|
|
21
|
+
*/
|
|
22
|
+
import { levelSetWgsl } from "./level-set.js";
|
|
23
|
+
/** Vendored grid-type constant names (after the rename) per compiled type. */
|
|
24
|
+
export const GRID_TYPE_CONSTANT = {
|
|
25
|
+
float: "VDB_GRID_TYPE_FLOAT",
|
|
26
|
+
fp4: "VDB_GRID_TYPE_FP4",
|
|
27
|
+
fp8: "VDB_GRID_TYPE_FP8",
|
|
28
|
+
fp16: "VDB_GRID_TYPE_FP16",
|
|
29
|
+
fpn: "VDB_GRID_TYPE_FPN",
|
|
30
|
+
};
|
|
31
|
+
/** Whether the accessor carries the index bbox (only `sample`+ with `outside: 'zero'`). */
|
|
32
|
+
function carriesBBox(profileRank, o) {
|
|
33
|
+
return profileRank >= 1 && o.outside === "zero";
|
|
34
|
+
}
|
|
35
|
+
/** Whether the accessor carries the stats flag and `valueMax` (`march`+). */
|
|
36
|
+
function carriesStats(profileRank) {
|
|
37
|
+
return profileRank >= 2;
|
|
38
|
+
}
|
|
39
|
+
function readLayer(o, profileRank) {
|
|
40
|
+
const bbox = carriesBBox(profileRank, o);
|
|
41
|
+
const stats = carriesStats(profileRank);
|
|
42
|
+
const typeOk = o.types.map((t) => `t == ${GRID_TYPE_CONSTANT[t]}`).join(" || ");
|
|
43
|
+
const extraFields = (bbox ? "\n lo: vec3i,\n hi: vec3i," : "") + (stats ? "\n stats: bool,\n vmax: f32," : "");
|
|
44
|
+
const extraInit = (bbox ? "\n a.lo = vdbIndexMin(g);\n a.hi = vdbIndexMax(g);" : "") +
|
|
45
|
+
(stats
|
|
46
|
+
? "\n a.stats = (vdb_rec(g, VDB_REC_FLAGS) & VDB_REC_FLAG_HAS_STATS) != 0u;\n a.vmax = bitcast<f32>(vdb_rec(g, VDB_REC_VALUE_MAX));"
|
|
47
|
+
: "");
|
|
48
|
+
const parts = [
|
|
49
|
+
`struct VdbAccessor {
|
|
50
|
+
buf: vdb_buf_t,
|
|
51
|
+
gridType: u32,
|
|
52
|
+
ok: bool,
|
|
53
|
+
inner: vdb_readaccessor_t,${extraFields}
|
|
54
|
+
}`,
|
|
55
|
+
`fn vdb_rec(g: u32, w: u32) -> u32 {
|
|
56
|
+
return vdb_load(VDB_POOL_TABLE_WORD + g * VDB_POOL_RECORD_WORDS + w);
|
|
57
|
+
}`,
|
|
58
|
+
`fn vdb_type_ok(t: u32) -> bool {
|
|
59
|
+
return ${typeOk};
|
|
60
|
+
}`,
|
|
61
|
+
`fn vdbGridCount() -> u32 {
|
|
62
|
+
return vdb_load(VDB_HEADER_GRID_COUNT);
|
|
63
|
+
}`,
|
|
64
|
+
`fn vdb_live(g: u32) -> bool {
|
|
65
|
+
return g < vdbGridCount() && (vdb_rec(g, VDB_REC_FLAGS) & VDB_REC_FLAG_LIVE) != 0u;
|
|
66
|
+
}`,
|
|
67
|
+
`fn vdbGridType(g: u32) -> u32 {
|
|
68
|
+
if !vdb_live(g) {
|
|
69
|
+
return 0u;
|
|
70
|
+
}
|
|
71
|
+
return vdb_rec(g, VDB_REC_GRID_TYPE);
|
|
72
|
+
}`,
|
|
73
|
+
`fn vdbIndexMin(g: u32) -> vec3i {
|
|
74
|
+
if !vdb_live(g) {
|
|
75
|
+
return vec3i(0);
|
|
76
|
+
}
|
|
77
|
+
return bitcast<vec3i>(vec3u(vdb_rec(g, VDB_REC_INDEX_BBOX_MIN), vdb_rec(g, VDB_REC_INDEX_BBOX_MIN + 1u), vdb_rec(g, VDB_REC_INDEX_BBOX_MIN + 2u)));
|
|
78
|
+
}`,
|
|
79
|
+
`fn vdbIndexMax(g: u32) -> vec3i {
|
|
80
|
+
if !vdb_live(g) {
|
|
81
|
+
return vec3i(-1);
|
|
82
|
+
}
|
|
83
|
+
return bitcast<vec3i>(vec3u(vdb_rec(g, VDB_REC_INDEX_BBOX_MAX), vdb_rec(g, VDB_REC_INDEX_BBOX_MAX + 1u), vdb_rec(g, VDB_REC_INDEX_BBOX_MAX + 2u)));
|
|
84
|
+
}`,
|
|
85
|
+
`fn vdbAccessorInit(g: u32) -> VdbAccessor {
|
|
86
|
+
var a: VdbAccessor;
|
|
87
|
+
a.gridType = vdbGridType(g);
|
|
88
|
+
a.ok = vdb_type_ok(a.gridType);
|
|
89
|
+
var root = vdb_root_handle_t(0u);
|
|
90
|
+
if a.ok {
|
|
91
|
+
a.buf = vdb_make_buffer(vdb_rec(g, VDB_REC_IMAGE_OFFSET), vdb_rec(g, VDB_REC_IMAGE_BYTES) >> 2u);
|
|
92
|
+
root = vdb_tree_get_root(a.buf, vdb_grid_get_tree(vdb_grid_handle_t(0u)));${extraInit}
|
|
93
|
+
}
|
|
94
|
+
var inner: vdb_readaccessor_t;
|
|
95
|
+
vdb_readaccessor_init(&inner, root);
|
|
96
|
+
a.inner = inner;
|
|
97
|
+
return a;
|
|
98
|
+
}`,
|
|
99
|
+
`fn vdbReadValue(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> f32 {
|
|
100
|
+
if !(*acc).ok {
|
|
101
|
+
return 0.0;
|
|
102
|
+
}
|
|
103
|
+
var inner = (*acc).inner;
|
|
104
|
+
let v = vdb_readaccessor_get_value_float((*acc).gridType, (*acc).buf, &inner, ijk);
|
|
105
|
+
(*acc).inner = inner;
|
|
106
|
+
return v;
|
|
107
|
+
}`,
|
|
108
|
+
];
|
|
109
|
+
if (o.isActive) {
|
|
110
|
+
parts.push(`fn vdbIsActive(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> bool {
|
|
111
|
+
if !(*acc).ok {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
var inner = (*acc).inner;
|
|
115
|
+
let v = vdb_readaccessor_is_active((*acc).gridType, (*acc).buf, &inner, ijk);
|
|
116
|
+
(*acc).inner = inner;
|
|
117
|
+
return v;
|
|
118
|
+
}`);
|
|
119
|
+
}
|
|
120
|
+
return parts.join("\n");
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* `vdbSample` per sampler and `outside` mode.
|
|
124
|
+
*
|
|
125
|
+
* `outside: 'background'` reads the tree everywhere (NanoVDB: outside the
|
|
126
|
+
* tree the background value).
|
|
127
|
+
*
|
|
128
|
+
* `outside: 'zero'` samples the field that equals the tree inside the index
|
|
129
|
+
* bbox `[min, max]` (voxels, inclusive) and 0 outside it, so both samplers
|
|
130
|
+
* see the same box with voxel centres at integers:
|
|
131
|
+
* - trilinear: each of the 8 taps outside `[min, max]` reads 0. A point is
|
|
132
|
+
* 0 unless its base voxel `floor(xyz)` lies in `[min - 1, max]` (some tap
|
|
133
|
+
* inside), i.e. `xyz` in `[min - 1, max + 1)`.
|
|
134
|
+
* - nearest: the voxel `floor(xyz + 0.5)` must lie in `[min, max]`, i.e.
|
|
135
|
+
* `xyz` in `[min - 0.5, max + 0.5)`; else 0.
|
|
136
|
+
* CPU twins: `tools` `vdbSampleTrilinear` / `vdbSampleNearest` with `{ outside: 'zero' }`.
|
|
137
|
+
*/
|
|
138
|
+
function sampleFunction(o, profileRank) {
|
|
139
|
+
const read = (ijk) => `vdb_readaccessor_get_value_float((*acc).gridType, (*acc).buf, &inner, ${ijk})`;
|
|
140
|
+
if (!carriesBBox(profileRank, o)) {
|
|
141
|
+
const lookup = o.sampler === "trilinear" ? "vdb_sample_trilinear_typed((*acc).gridType, (*acc).buf, &inner, xyz)" : read("vec3i(floor(xyz + vec3f(0.5)))");
|
|
142
|
+
return [
|
|
143
|
+
`fn vdbSample(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {
|
|
144
|
+
if !(*acc).ok {
|
|
145
|
+
return 0.0;
|
|
146
|
+
}
|
|
147
|
+
var inner = (*acc).inner;
|
|
148
|
+
let v = ${lookup};
|
|
149
|
+
(*acc).inner = inner;
|
|
150
|
+
return v;
|
|
151
|
+
}`,
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
if (o.sampler === "nearest") {
|
|
155
|
+
return [
|
|
156
|
+
`fn vdbSample(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {
|
|
157
|
+
let ijk = vec3i(floor(xyz + vec3f(0.5)));
|
|
158
|
+
if !(*acc).ok || any(ijk < (*acc).lo) || any(ijk > (*acc).hi) {
|
|
159
|
+
return 0.0;
|
|
160
|
+
}
|
|
161
|
+
var inner = (*acc).inner;
|
|
162
|
+
let v = ${read("ijk")};
|
|
163
|
+
(*acc).inner = inner;
|
|
164
|
+
return v;
|
|
165
|
+
}`,
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
// Same tap order and lerp structure as the vendored sample_trilinear_typed.
|
|
169
|
+
return [
|
|
170
|
+
`fn vdb_tap0(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> f32 {
|
|
171
|
+
if any(ijk < (*acc).lo) || any(ijk > (*acc).hi) {
|
|
172
|
+
return 0.0;
|
|
173
|
+
}
|
|
174
|
+
var inner = (*acc).inner;
|
|
175
|
+
let v = ${read("ijk")};
|
|
176
|
+
(*acc).inner = inner;
|
|
177
|
+
return v;
|
|
178
|
+
}`,
|
|
179
|
+
`fn vdbSample(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {
|
|
180
|
+
let b = vec3i(floor(xyz));
|
|
181
|
+
if !(*acc).ok || any(b < (*acc).lo - vec3i(1)) || any(b > (*acc).hi) {
|
|
182
|
+
return 0.0;
|
|
183
|
+
}
|
|
184
|
+
let u = xyz - vec3f(b);
|
|
185
|
+
let x00 = mix(vdb_tap0(acc, b), vdb_tap0(acc, b + vec3i(1, 0, 0)), u.x);
|
|
186
|
+
let x10 = mix(vdb_tap0(acc, b + vec3i(0, 1, 0)), vdb_tap0(acc, b + vec3i(1, 1, 0)), u.x);
|
|
187
|
+
let x01 = mix(vdb_tap0(acc, b + vec3i(0, 0, 1)), vdb_tap0(acc, b + vec3i(1, 0, 1)), u.x);
|
|
188
|
+
let x11 = mix(vdb_tap0(acc, b + vec3i(0, 1, 1)), vdb_tap0(acc, b + vec3i(1, 1, 1)), u.x);
|
|
189
|
+
return mix(mix(x00, x10, u.y), mix(x01, x11, u.y), u.z);
|
|
190
|
+
}`,
|
|
191
|
+
];
|
|
192
|
+
}
|
|
193
|
+
function sampleLayer(o, profileRank) {
|
|
194
|
+
return [
|
|
195
|
+
`fn vdb_row(b: u32) -> vec4f {
|
|
196
|
+
return bitcast<vec4f>(vec4u(vdb_load(b), vdb_load(b + 1u), vdb_load(b + 2u), vdb_load(b + 3u)));
|
|
197
|
+
}`,
|
|
198
|
+
`fn vdb_affine(g: u32, w: u32, p: vec4f) -> vec3f {
|
|
199
|
+
if !vdb_live(g) {
|
|
200
|
+
return vec3f(0.0);
|
|
201
|
+
}
|
|
202
|
+
let b = VDB_POOL_TABLE_WORD + g * VDB_POOL_RECORD_WORDS + w;
|
|
203
|
+
return vec3f(dot(vdb_row(b), p), dot(vdb_row(b + 4u), p), dot(vdb_row(b + 8u), p));
|
|
204
|
+
}`,
|
|
205
|
+
`fn vdbWorldToIndex(g: u32, p: vec3f) -> vec3f {
|
|
206
|
+
return vdb_affine(g, VDB_REC_WORLD_TO_INDEX, vec4f(p, 1.0));
|
|
207
|
+
}`,
|
|
208
|
+
`fn vdbWorldToIndexDir(g: u32, d: vec3f) -> vec3f {
|
|
209
|
+
return vdb_affine(g, VDB_REC_WORLD_TO_INDEX, vec4f(d, 0.0));
|
|
210
|
+
}`,
|
|
211
|
+
`fn vdbIndexToWorld(g: u32, p: vec3f) -> vec3f {
|
|
212
|
+
return vdb_affine(g, VDB_REC_INDEX_TO_WORLD, vec4f(p, 1.0));
|
|
213
|
+
}`,
|
|
214
|
+
`fn vdbIndexToWorldDir(g: u32, d: vec3f) -> vec3f {
|
|
215
|
+
return vdb_affine(g, VDB_REC_INDEX_TO_WORLD, vec4f(d, 0.0));
|
|
216
|
+
}`,
|
|
217
|
+
...sampleFunction(o, profileRank),
|
|
218
|
+
`fn vdbRayClip(g: u32, o: vec3f, d: vec3f, t: ptr<function, vec2f>) -> bool {
|
|
219
|
+
if !vdb_live(g) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
var t0 = (*t).x;
|
|
223
|
+
var t1 = (*t).y;
|
|
224
|
+
let hit = vdb_hdda_ray_clip(vec3f(vdbIndexMin(g)), vec3f(vdbIndexMax(g) + vec3i(1)), o, &t0, d, &t1);
|
|
225
|
+
*t = vec2f(t0, t1);
|
|
226
|
+
return hit && t0 <= t1;
|
|
227
|
+
}`,
|
|
228
|
+
].join("\n");
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* `march` (design note §3.2): the vendored HDDA, the accessor's node size at a
|
|
232
|
+
* voxel, and node stats.
|
|
233
|
+
*
|
|
234
|
+
* `vdbGetDim(acc, ijk)` is the vendored `readaccessor_get_dim`: 1 inside a
|
|
235
|
+
* leaf, 8 in a lower-node tile, 128 in an upper-node tile, 4096 in a root tile
|
|
236
|
+
* or the background (and 4096 for a grid the accessor can't read, so a walk
|
|
237
|
+
* ends after one cell instead of stalling at dim 0).
|
|
238
|
+
*
|
|
239
|
+
* `vdbNodeMax(acc, ijk, dim)` bounds the aligned cell of size `dim` holding
|
|
240
|
+
* `ijk`. With `a = vdbGetDim(acc, ijk)`:
|
|
241
|
+
* - `a > 1` and `dim <= a`: the cell lies in one tile; returns its value
|
|
242
|
+
* (exact, active or not).
|
|
243
|
+
* - otherwise the max statistic of the smallest node spanning the cell: the
|
|
244
|
+
* leaf for `dim <= 8`, lower for `<= 128`, upper for `<= 4096`, else root.
|
|
245
|
+
* NanoVDB stats cover ACTIVE values only: the result bounds the active
|
|
246
|
+
* voxels and active tiles of that node, not inactive values, and not a
|
|
247
|
+
* trilinear sample, whose taps reach one voxel into the neighbours.
|
|
248
|
+
* - without stats (record flag b1 clear) the stats branches return the
|
|
249
|
+
* record's `valueMax`: the caller's bound from `pool.add`, else +Infinity
|
|
250
|
+
* (the pool convention for "no bound"). Test `vdbHasStats(g)` rather than
|
|
251
|
+
* relying on infinity arithmetic.
|
|
252
|
+
* The node handles come from the accessor cache that `vdbGetDim` just filled
|
|
253
|
+
* along `ijk`'s path (leaf, lower and upper are all valid whenever the level
|
|
254
|
+
* below them is, see the vendored `readaccessor_iscached*`).
|
|
255
|
+
*/
|
|
256
|
+
function marchLayer() {
|
|
257
|
+
return [
|
|
258
|
+
`alias VdbHdda = vdb_hdda_t;`,
|
|
259
|
+
`fn vdbHddaInit(h: ptr<function, VdbHdda>, o: vec3f, tmin: f32, d: vec3f, tmax: f32, dim: u32) {
|
|
260
|
+
vdb_hdda_init(h, o, tmin, d, tmax, i32(dim));
|
|
261
|
+
}`,
|
|
262
|
+
`fn vdbHddaUpdate(h: ptr<function, VdbHdda>, o: vec3f, d: vec3f, dim: u32) -> bool {
|
|
263
|
+
return vdb_hdda_update(h, o, d, i32(dim));
|
|
264
|
+
}`,
|
|
265
|
+
`fn vdbHddaStep(h: ptr<function, VdbHdda>) -> bool {
|
|
266
|
+
return vdb_hdda_step(h);
|
|
267
|
+
}`,
|
|
268
|
+
`fn vdbGetDim(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> u32 {
|
|
269
|
+
if !(*acc).ok {
|
|
270
|
+
return 4096u;
|
|
271
|
+
}
|
|
272
|
+
var inner = (*acc).inner;
|
|
273
|
+
let v = vdb_readaccessor_get_dim((*acc).gridType, (*acc).buf, &inner, ijk);
|
|
274
|
+
(*acc).inner = inner;
|
|
275
|
+
return v;
|
|
276
|
+
}`,
|
|
277
|
+
`fn vdbHasStats(g: u32) -> bool {
|
|
278
|
+
return vdb_live(g) && (vdb_rec(g, VDB_REC_FLAGS) & VDB_REC_FLAG_HAS_STATS) != 0u;
|
|
279
|
+
}`,
|
|
280
|
+
`fn vdbValueMax(g: u32) -> f32 {
|
|
281
|
+
if !vdb_live(g) {
|
|
282
|
+
return 0.0;
|
|
283
|
+
}
|
|
284
|
+
return bitcast<f32>(vdb_rec(g, VDB_REC_VALUE_MAX));
|
|
285
|
+
}`,
|
|
286
|
+
`fn vdbNodeMax(acc: ptr<function, VdbAccessor>, ijk: vec3i, dim: u32) -> f32 {
|
|
287
|
+
if !(*acc).ok {
|
|
288
|
+
return 0.0;
|
|
289
|
+
}
|
|
290
|
+
let a = vdbGetDim(acc, ijk);
|
|
291
|
+
if a > 1u && dim <= a {
|
|
292
|
+
return vdbReadValue(acc, ijk);
|
|
293
|
+
}
|
|
294
|
+
if !(*acc).stats {
|
|
295
|
+
return (*acc).vmax;
|
|
296
|
+
}
|
|
297
|
+
let t = (*acc).gridType;
|
|
298
|
+
let b = (*acc).buf;
|
|
299
|
+
if dim <= 8u {
|
|
300
|
+
return vdb_leaf_get_max_float(t, b, (*acc).inner.leaf);
|
|
301
|
+
}
|
|
302
|
+
if dim <= 128u {
|
|
303
|
+
return vdb_lower_get_max_float(t, b, (*acc).inner.lower);
|
|
304
|
+
}
|
|
305
|
+
if dim <= 4096u {
|
|
306
|
+
return vdb_upper_get_max_float(t, b, (*acc).inner.upper);
|
|
307
|
+
}
|
|
308
|
+
return vdb_root_get_max_float(t, b, (*acc).inner.root);
|
|
309
|
+
}`,
|
|
310
|
+
].join("\n");
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Opt-in helpers (K1.7a, the `helpers` option). Each is emitted only when
|
|
314
|
+
* asked for, so modules without helpers keep their bytes (the size snapshot).
|
|
315
|
+
*
|
|
316
|
+
* `vdbCellBoundTrilinear(acc, ijk, dim)`: the max of `vdbNodeMax` over the
|
|
317
|
+
* 2x2x2 block of aligned `dim`-cells whose min corner is the cell holding
|
|
318
|
+
* `ijk` (that cell and its +x/+y/+z neighbours). A trilinear sample at `p`
|
|
319
|
+
* reads voxels `floor(p) + {0,1}^3`, so when `floor(p)` lies in the cell every
|
|
320
|
+
* tap lies in the block and the result bounds the sample, with `vdbNodeMax`'s
|
|
321
|
+
* caveat: stats bound ACTIVE values, so inactive leaf voxels must be <= their
|
|
322
|
+
* leaf's max (true of fog volumes). With `outside: 'zero'` and a negative
|
|
323
|
+
* field, also take max(result, 0). This is the skip test a march needs; the
|
|
324
|
+
* cell's own `vdbNodeMax` is not one (CLAUDE.md Traps). CPU twin: `tools`
|
|
325
|
+
* `cellBoundTrilinear`.
|
|
326
|
+
*
|
|
327
|
+
* `vdbHddaCellEnd(h)`: the ray `t` where the HDDA's current cell ends,
|
|
328
|
+
* `min(next.x, next.y, next.z, tmax)` of the vendored state, so a host
|
|
329
|
+
* needn't name `VdbHdda`'s vendored fields. CPU twin: `tools` `hddaCellEnd`.
|
|
330
|
+
*
|
|
331
|
+
* `vdbNodeAverage(acc, ijk, dim)` (K3.2): the box mean of the aligned
|
|
332
|
+
* `dim`-cell holding `ijk`, from node statistics instead of voxels (the
|
|
333
|
+
* sparse volume source's `'node-average'` LOD). A cell inside one tile (or the
|
|
334
|
+
* background) is that tile's value, exactly. Otherwise, for `dim <= 8`, the
|
|
335
|
+
* leaf's average times its active fraction (`countOneBits` of the value mask
|
|
336
|
+
* / 512): the exact mean when the leaf's inactive voxels are 0 (fog); for
|
|
337
|
+
* `dim <= 128`, the lower node's average, which is the mean of its ACTIVE
|
|
338
|
+
* voxels (NanoVDB stores no active count per lower node), so it overstates a
|
|
339
|
+
* partly empty lower node; larger cells read the lower node too (`dim` is
|
|
340
|
+
* meant to be 8 or 128; no upper level, to keep the module small). Without stats it is the value at `ijk` (no
|
|
341
|
+
* prefilter). CPU twin: `tools` `nodeAverage`.
|
|
342
|
+
*
|
|
343
|
+
* `vdbRayClipSupport(g, o, d, t)`: `vdbRayClip` against the box where
|
|
344
|
+
* `vdbSample` can read the grid's voxels: `[min - 1, max + 1]` for trilinear
|
|
345
|
+
* (the taps of a point in `[min - 1, min)` reach voxel `min`) and
|
|
346
|
+
* `[min - 0.5, max + 0.5]` for nearest. `vdbRayClip`'s box, `[min, max + 1]`,
|
|
347
|
+
* is the voxel-cell box the HDDA walks; it cuts the min-side half voxel of the
|
|
348
|
+
* trilinear support. CPU twin: `tools` `rayClipSupport`.
|
|
349
|
+
*/
|
|
350
|
+
function helperFunctions(o) {
|
|
351
|
+
const out = [];
|
|
352
|
+
if (o.helpers.includes("rayClipSupport")) {
|
|
353
|
+
const pad = o.sampler === "nearest" ? "0.5" : "1.0";
|
|
354
|
+
out.push(`fn vdbRayClipSupport(g: u32, o: vec3f, d: vec3f, t: ptr<function, vec2f>) -> bool {
|
|
355
|
+
if !vdb_live(g) {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
var t0 = (*t).x;
|
|
359
|
+
var t1 = (*t).y;
|
|
360
|
+
let hit = vdb_hdda_ray_clip(vec3f(vdbIndexMin(g)) - vec3f(${pad}), vec3f(vdbIndexMax(g)) + vec3f(${pad}), o, &t0, d, &t1);
|
|
361
|
+
*t = vec2f(t0, t1);
|
|
362
|
+
return hit && t0 <= t1;
|
|
363
|
+
}`);
|
|
364
|
+
}
|
|
365
|
+
if (o.helpers.includes("cellBoundTrilinear")) {
|
|
366
|
+
out.push(`fn vdbCellBoundTrilinear(acc: ptr<function, VdbAccessor>, ijk: vec3i, dim: u32) -> f32 {
|
|
367
|
+
var m = vdbNodeMax(acc, ijk, dim);
|
|
368
|
+
for (var k = 1u; k < 8u; k++) {
|
|
369
|
+
let c = vec3i(vec3u(k & 1u, (k >> 1u) & 1u, (k >> 2u) & 1u)) * i32(dim);
|
|
370
|
+
m = max(m, vdbNodeMax(acc, ijk + c, dim));
|
|
371
|
+
}
|
|
372
|
+
return m;
|
|
373
|
+
}`);
|
|
374
|
+
}
|
|
375
|
+
if (o.helpers.includes("hddaCellEnd")) {
|
|
376
|
+
out.push(`fn vdbHddaCellEnd(h: ptr<function, VdbHdda>) -> f32 {
|
|
377
|
+
return min(min((*h).next.x, (*h).next.y), min((*h).next.z, (*h).tmax));
|
|
378
|
+
}`);
|
|
379
|
+
}
|
|
380
|
+
if (o.helpers.includes("fastTrilinear")) {
|
|
381
|
+
// Only trilinear has 8 taps to share (the generator rejects the helper with 'nearest').
|
|
382
|
+
const inside = carriesBBox(1, o) ? " || any(b < (*acc).lo) || any(b >= (*acc).hi)" : "";
|
|
383
|
+
// Uniform per-tap work (no per-lane choice between a leaf read and a descent: lanes of a SIMD group that
|
|
384
|
+
// disagree would run both). All 8 taps lie in the base voxel's lower node (128-block) unless the base is
|
|
385
|
+
// on its +x/+y/+z face; each tap is then one lower-node child lookup (the same words for taps in the same
|
|
386
|
+
// leaf), never a tree walk. The vendored taps instead thrash the accessor's one-leaf cache when the cell
|
|
387
|
+
// straddles leaves (x-fastest tap order alternates them).
|
|
388
|
+
// A tap: one lower-node child lookup (the caching variant the accessor already uses, on a scratch cache).
|
|
389
|
+
// vdbSampleFast: the lower node holding the base is the accessor's cached one, else a descent (which caches
|
|
390
|
+
// it); at level 2+ the base's 128-block, which holds all 8 taps, is one tile (or the background): one value.
|
|
391
|
+
// c0 holds taps 0-3 (z = 0), c1 taps 4-7 (z = 1), x fastest: the vendored c000, c100, c010, c110, c001, ...
|
|
392
|
+
// No comments inside the WGSL: generated modules carry only the banner.
|
|
393
|
+
out.push(`fn vdb_lower_tap(t: u32, buf: vdb_buf_t, node: vdb_lower_handle_t, b: vec3i, k: u32) -> f32 {
|
|
394
|
+
let ijk = b + vec3i(vec3u(k & 1u, (k >> 1u) & 1u, k >> 2u));
|
|
395
|
+
var s: vdb_readaccessor_t;
|
|
396
|
+
let al = vdb_lower_get_value_address_and_level_and_cache(t, buf, node, ijk, &s);
|
|
397
|
+
return vdb_read_float_typed(t, buf, al.address, ijk, al.level);
|
|
398
|
+
}`);
|
|
399
|
+
const taps = (from) => [0, 1, 2, 3].map((k) => `vdb_lower_tap(t, buf, n, b, ${from + k}u)`).join(", ");
|
|
400
|
+
out.push(`fn vdbSampleFast(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {
|
|
401
|
+
let b = vec3i(floor(xyz));
|
|
402
|
+
if !(*acc).ok || any((b & vec3i(127)) == vec3i(127))${inside} {
|
|
403
|
+
return vdbSample(acc, xyz);
|
|
404
|
+
}
|
|
405
|
+
let t = (*acc).gridType;
|
|
406
|
+
let buf = (*acc).buf;
|
|
407
|
+
var inner = (*acc).inner;
|
|
408
|
+
var lower = vdb_readaccessor_iscached1(&inner, vdb_readaccessor_computedirty(&inner, b));
|
|
409
|
+
var v = 0.0;
|
|
410
|
+
if !lower {
|
|
411
|
+
let al = vdb_readaccessor_get_value_address_and_level(t, buf, &inner, b);
|
|
412
|
+
lower = al.level <= 1u;
|
|
413
|
+
v = vdb_read_float_typed(t, buf, al.address, b, al.level);
|
|
414
|
+
}
|
|
415
|
+
(*acc).inner = inner;
|
|
416
|
+
var c0 = vec4f(v);
|
|
417
|
+
var c1 = vec4f(v);
|
|
418
|
+
if lower {
|
|
419
|
+
let n = inner.lower;
|
|
420
|
+
c0 = vec4f(${taps(0)});
|
|
421
|
+
c1 = vec4f(${taps(4)});
|
|
422
|
+
}
|
|
423
|
+
let u = xyz - vec3f(b);
|
|
424
|
+
return mix(mix(mix(c0.x, c0.y, u.x), mix(c0.z, c0.w, u.x), u.y), mix(mix(c1.x, c1.y, u.x), mix(c1.z, c1.w, u.x), u.y), u.z);
|
|
425
|
+
}`);
|
|
426
|
+
}
|
|
427
|
+
if (o.helpers.includes("nodeAverage")) {
|
|
428
|
+
out.push(`fn vdbNodeAverage(acc: ptr<function, VdbAccessor>, ijk: vec3i, dim: u32) -> f32 {
|
|
429
|
+
if !(*acc).ok {
|
|
430
|
+
return 0.0;
|
|
431
|
+
}
|
|
432
|
+
let a = vdbGetDim(acc, ijk);
|
|
433
|
+
if (a > 1u && dim <= a) || !(*acc).stats || dim <= 1u {
|
|
434
|
+
return vdbReadValue(acc, ijk);
|
|
435
|
+
}
|
|
436
|
+
let t = (*acc).gridType;
|
|
437
|
+
let b = (*acc).buf;
|
|
438
|
+
if dim <= 8u {
|
|
439
|
+
let leaf = (*acc).inner.leaf;
|
|
440
|
+
var n = 0u;
|
|
441
|
+
for (var w = 0u; w < 16u; w++) {
|
|
442
|
+
n += countOneBits(vdb_read_uint32(b, vdb_address_offset(leaf.address, VDB_LEAF_OFF_VALUE_MASK + 4u * w)));
|
|
443
|
+
}
|
|
444
|
+
return vdb_leaf_get_ave_float(t, b, leaf) * (f32(n) / 512.0);
|
|
445
|
+
}
|
|
446
|
+
return vdb_lower_get_ave_float(t, b, (*acc).inner.lower);
|
|
447
|
+
}`);
|
|
448
|
+
}
|
|
449
|
+
// K3.7: the level-set zero-crossing finder and normal (./level-set.ts).
|
|
450
|
+
if (o.helpers.includes("levelSet"))
|
|
451
|
+
out.push(...levelSetWgsl());
|
|
452
|
+
return out;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* API layers in profile order. A profile's API is every layer up to and
|
|
456
|
+
* including its own (`majorant`, rank 3, is deferred past 0.1, D22).
|
|
457
|
+
*/
|
|
458
|
+
export const API_LAYERS = [readLayer, sampleLayer, marchLayer];
|
|
459
|
+
/** The public API text for the profile at `profileRank` (0 = read, 1 = sample, 2 = march), then the requested helpers. */
|
|
460
|
+
export function apiWgsl(profileRank, o) {
|
|
461
|
+
return [...API_LAYERS.slice(0, profileRank + 1).map((layer) => layer(o, profileRank)), ...helperFunctions(o)].join("\n");
|
|
462
|
+
}
|
|
463
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/core/wgsl/api.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * The public `vdb*` WGSL API layered over the vendored traversal\n * (docs/dev/design/K1-core.md §3.2). Written in the generated module's final names:\n * vendored declarations appear renamed (`vdb_*`, `VDB_*`), and the generator\n * pulls in exactly the vendored declarations this text references.\n *\n * Every pool read goes through `vdb_load`, the module's one buffer access,\n * which the generator emits for the chosen binding mode.\n *\n * Layers stack: `sample` includes `read`, `march` includes `sample`\n * (`majorant` is deferred past 0.1, D22). Each layer is a function of the\n * normalized options and the profile rank.\n *\n * Conventions every layer keeps:\n * - A grid id is usable when it is below `vdbGridCount()` and its record is\n * live. Every per-grid function checks that first: a dead or out-of-range\n * id never reads a zeroed record or image bytes as a record.\n * - Voxel centres sit at integer index coordinates (the vendored trilinear and\n * NanoVDB `SampleFromVoxels`); HDDA cells are floor-based, so voxel `i`\n * occupies `[i, i + 1)` for ray clipping and traversal.\n */\n\nimport type { VDBGridTypeName } from \"../types.js\";\nimport { levelSetWgsl } from \"./level-set.js\";\nimport type { VDBModuleHelper } from \"./types.js\";\n\n/** Options the API layer depends on (normalized by the generator). */\nexport interface ApiOptions {\n readonly types: readonly VDBGridTypeName[];\n readonly isActive: boolean;\n readonly sampler: \"trilinear\" | \"nearest\";\n readonly outside: \"background\" | \"zero\";\n /** Opt-in helpers, canonical order; the generator has checked each one's profile. */\n readonly helpers: readonly VDBModuleHelper[];\n}\n\n/** Vendored grid-type constant names (after the rename) per compiled type. */\nexport const GRID_TYPE_CONSTANT: Readonly<Record<VDBGridTypeName, string>> = {\n float: \"VDB_GRID_TYPE_FLOAT\",\n fp4: \"VDB_GRID_TYPE_FP4\",\n fp8: \"VDB_GRID_TYPE_FP8\",\n fp16: \"VDB_GRID_TYPE_FP16\",\n fpn: \"VDB_GRID_TYPE_FPN\",\n};\n\n/** Whether the accessor carries the index bbox (only `sample`+ with `outside: 'zero'`). */\nfunction carriesBBox(profileRank: number, o: ApiOptions): boolean {\n return profileRank >= 1 && o.outside === \"zero\";\n}\n\n/** Whether the accessor carries the stats flag and `valueMax` (`march`+). */\nfunction carriesStats(profileRank: number): boolean {\n return profileRank >= 2;\n}\n\nfunction readLayer(o: ApiOptions, profileRank: number): string {\n const bbox = carriesBBox(profileRank, o);\n const stats = carriesStats(profileRank);\n const typeOk = o.types.map((t) => `t == ${GRID_TYPE_CONSTANT[t]}`).join(\" || \");\n const extraFields = (bbox ? \"\\n lo: vec3i,\\n hi: vec3i,\" : \"\") + (stats ? \"\\n stats: bool,\\n vmax: f32,\" : \"\");\n const extraInit =\n (bbox ? \"\\n a.lo = vdbIndexMin(g);\\n a.hi = vdbIndexMax(g);\" : \"\") +\n (stats\n ? \"\\n a.stats = (vdb_rec(g, VDB_REC_FLAGS) & VDB_REC_FLAG_HAS_STATS) != 0u;\\n a.vmax = bitcast<f32>(vdb_rec(g, VDB_REC_VALUE_MAX));\"\n : \"\");\n const parts = [\n `struct VdbAccessor {\n buf: vdb_buf_t,\n gridType: u32,\n ok: bool,\n inner: vdb_readaccessor_t,${extraFields}\n}`,\n `fn vdb_rec(g: u32, w: u32) -> u32 {\n return vdb_load(VDB_POOL_TABLE_WORD + g * VDB_POOL_RECORD_WORDS + w);\n}`,\n `fn vdb_type_ok(t: u32) -> bool {\n return ${typeOk};\n}`,\n `fn vdbGridCount() -> u32 {\n return vdb_load(VDB_HEADER_GRID_COUNT);\n}`,\n `fn vdb_live(g: u32) -> bool {\n return g < vdbGridCount() && (vdb_rec(g, VDB_REC_FLAGS) & VDB_REC_FLAG_LIVE) != 0u;\n}`,\n `fn vdbGridType(g: u32) -> u32 {\n if !vdb_live(g) {\n return 0u;\n }\n return vdb_rec(g, VDB_REC_GRID_TYPE);\n}`,\n `fn vdbIndexMin(g: u32) -> vec3i {\n if !vdb_live(g) {\n return vec3i(0);\n }\n return bitcast<vec3i>(vec3u(vdb_rec(g, VDB_REC_INDEX_BBOX_MIN), vdb_rec(g, VDB_REC_INDEX_BBOX_MIN + 1u), vdb_rec(g, VDB_REC_INDEX_BBOX_MIN + 2u)));\n}`,\n `fn vdbIndexMax(g: u32) -> vec3i {\n if !vdb_live(g) {\n return vec3i(-1);\n }\n return bitcast<vec3i>(vec3u(vdb_rec(g, VDB_REC_INDEX_BBOX_MAX), vdb_rec(g, VDB_REC_INDEX_BBOX_MAX + 1u), vdb_rec(g, VDB_REC_INDEX_BBOX_MAX + 2u)));\n}`,\n `fn vdbAccessorInit(g: u32) -> VdbAccessor {\n var a: VdbAccessor;\n a.gridType = vdbGridType(g);\n a.ok = vdb_type_ok(a.gridType);\n var root = vdb_root_handle_t(0u);\n if a.ok {\n a.buf = vdb_make_buffer(vdb_rec(g, VDB_REC_IMAGE_OFFSET), vdb_rec(g, VDB_REC_IMAGE_BYTES) >> 2u);\n root = vdb_tree_get_root(a.buf, vdb_grid_get_tree(vdb_grid_handle_t(0u)));${extraInit}\n }\n var inner: vdb_readaccessor_t;\n vdb_readaccessor_init(&inner, root);\n a.inner = inner;\n return a;\n}`,\n `fn vdbReadValue(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> f32 {\n if !(*acc).ok {\n return 0.0;\n }\n var inner = (*acc).inner;\n let v = vdb_readaccessor_get_value_float((*acc).gridType, (*acc).buf, &inner, ijk);\n (*acc).inner = inner;\n return v;\n}`,\n ];\n if (o.isActive) {\n parts.push(`fn vdbIsActive(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> bool {\n if !(*acc).ok {\n return false;\n }\n var inner = (*acc).inner;\n let v = vdb_readaccessor_is_active((*acc).gridType, (*acc).buf, &inner, ijk);\n (*acc).inner = inner;\n return v;\n}`);\n }\n return parts.join(\"\\n\");\n}\n\n/**\n * `vdbSample` per sampler and `outside` mode.\n *\n * `outside: 'background'` reads the tree everywhere (NanoVDB: outside the\n * tree the background value).\n *\n * `outside: 'zero'` samples the field that equals the tree inside the index\n * bbox `[min, max]` (voxels, inclusive) and 0 outside it, so both samplers\n * see the same box with voxel centres at integers:\n * - trilinear: each of the 8 taps outside `[min, max]` reads 0. A point is\n * 0 unless its base voxel `floor(xyz)` lies in `[min - 1, max]` (some tap\n * inside), i.e. `xyz` in `[min - 1, max + 1)`.\n * - nearest: the voxel `floor(xyz + 0.5)` must lie in `[min, max]`, i.e.\n * `xyz` in `[min - 0.5, max + 0.5)`; else 0.\n * CPU twins: `tools` `vdbSampleTrilinear` / `vdbSampleNearest` with `{ outside: 'zero' }`.\n */\nfunction sampleFunction(o: ApiOptions, profileRank: number): string[] {\n const read = (ijk: string) => `vdb_readaccessor_get_value_float((*acc).gridType, (*acc).buf, &inner, ${ijk})`;\n if (!carriesBBox(profileRank, o)) {\n const lookup =\n o.sampler === \"trilinear\" ? \"vdb_sample_trilinear_typed((*acc).gridType, (*acc).buf, &inner, xyz)\" : read(\"vec3i(floor(xyz + vec3f(0.5)))\");\n return [\n `fn vdbSample(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {\n if !(*acc).ok {\n return 0.0;\n }\n var inner = (*acc).inner;\n let v = ${lookup};\n (*acc).inner = inner;\n return v;\n}`,\n ];\n }\n if (o.sampler === \"nearest\") {\n return [\n `fn vdbSample(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {\n let ijk = vec3i(floor(xyz + vec3f(0.5)));\n if !(*acc).ok || any(ijk < (*acc).lo) || any(ijk > (*acc).hi) {\n return 0.0;\n }\n var inner = (*acc).inner;\n let v = ${read(\"ijk\")};\n (*acc).inner = inner;\n return v;\n}`,\n ];\n }\n // Same tap order and lerp structure as the vendored sample_trilinear_typed.\n return [\n `fn vdb_tap0(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> f32 {\n if any(ijk < (*acc).lo) || any(ijk > (*acc).hi) {\n return 0.0;\n }\n var inner = (*acc).inner;\n let v = ${read(\"ijk\")};\n (*acc).inner = inner;\n return v;\n}`,\n `fn vdbSample(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {\n let b = vec3i(floor(xyz));\n if !(*acc).ok || any(b < (*acc).lo - vec3i(1)) || any(b > (*acc).hi) {\n return 0.0;\n }\n let u = xyz - vec3f(b);\n let x00 = mix(vdb_tap0(acc, b), vdb_tap0(acc, b + vec3i(1, 0, 0)), u.x);\n let x10 = mix(vdb_tap0(acc, b + vec3i(0, 1, 0)), vdb_tap0(acc, b + vec3i(1, 1, 0)), u.x);\n let x01 = mix(vdb_tap0(acc, b + vec3i(0, 0, 1)), vdb_tap0(acc, b + vec3i(1, 0, 1)), u.x);\n let x11 = mix(vdb_tap0(acc, b + vec3i(0, 1, 1)), vdb_tap0(acc, b + vec3i(1, 1, 1)), u.x);\n return mix(mix(x00, x10, u.y), mix(x01, x11, u.y), u.z);\n}`,\n ];\n}\n\nfunction sampleLayer(o: ApiOptions, profileRank: number): string {\n return [\n `fn vdb_row(b: u32) -> vec4f {\n return bitcast<vec4f>(vec4u(vdb_load(b), vdb_load(b + 1u), vdb_load(b + 2u), vdb_load(b + 3u)));\n}`,\n `fn vdb_affine(g: u32, w: u32, p: vec4f) -> vec3f {\n if !vdb_live(g) {\n return vec3f(0.0);\n }\n let b = VDB_POOL_TABLE_WORD + g * VDB_POOL_RECORD_WORDS + w;\n return vec3f(dot(vdb_row(b), p), dot(vdb_row(b + 4u), p), dot(vdb_row(b + 8u), p));\n}`,\n `fn vdbWorldToIndex(g: u32, p: vec3f) -> vec3f {\n return vdb_affine(g, VDB_REC_WORLD_TO_INDEX, vec4f(p, 1.0));\n}`,\n `fn vdbWorldToIndexDir(g: u32, d: vec3f) -> vec3f {\n return vdb_affine(g, VDB_REC_WORLD_TO_INDEX, vec4f(d, 0.0));\n}`,\n `fn vdbIndexToWorld(g: u32, p: vec3f) -> vec3f {\n return vdb_affine(g, VDB_REC_INDEX_TO_WORLD, vec4f(p, 1.0));\n}`,\n `fn vdbIndexToWorldDir(g: u32, d: vec3f) -> vec3f {\n return vdb_affine(g, VDB_REC_INDEX_TO_WORLD, vec4f(d, 0.0));\n}`,\n ...sampleFunction(o, profileRank),\n `fn vdbRayClip(g: u32, o: vec3f, d: vec3f, t: ptr<function, vec2f>) -> bool {\n if !vdb_live(g) {\n return false;\n }\n var t0 = (*t).x;\n var t1 = (*t).y;\n let hit = vdb_hdda_ray_clip(vec3f(vdbIndexMin(g)), vec3f(vdbIndexMax(g) + vec3i(1)), o, &t0, d, &t1);\n *t = vec2f(t0, t1);\n return hit && t0 <= t1;\n}`,\n ].join(\"\\n\");\n}\n\n/**\n * `march` (design note §3.2): the vendored HDDA, the accessor's node size at a\n * voxel, and node stats.\n *\n * `vdbGetDim(acc, ijk)` is the vendored `readaccessor_get_dim`: 1 inside a\n * leaf, 8 in a lower-node tile, 128 in an upper-node tile, 4096 in a root tile\n * or the background (and 4096 for a grid the accessor can't read, so a walk\n * ends after one cell instead of stalling at dim 0).\n *\n * `vdbNodeMax(acc, ijk, dim)` bounds the aligned cell of size `dim` holding\n * `ijk`. With `a = vdbGetDim(acc, ijk)`:\n * - `a > 1` and `dim <= a`: the cell lies in one tile; returns its value\n * (exact, active or not).\n * - otherwise the max statistic of the smallest node spanning the cell: the\n * leaf for `dim <= 8`, lower for `<= 128`, upper for `<= 4096`, else root.\n * NanoVDB stats cover ACTIVE values only: the result bounds the active\n * voxels and active tiles of that node, not inactive values, and not a\n * trilinear sample, whose taps reach one voxel into the neighbours.\n * - without stats (record flag b1 clear) the stats branches return the\n * record's `valueMax`: the caller's bound from `pool.add`, else +Infinity\n * (the pool convention for \"no bound\"). Test `vdbHasStats(g)` rather than\n * relying on infinity arithmetic.\n * The node handles come from the accessor cache that `vdbGetDim` just filled\n * along `ijk`'s path (leaf, lower and upper are all valid whenever the level\n * below them is, see the vendored `readaccessor_iscached*`).\n */\nfunction marchLayer(): string {\n return [\n `alias VdbHdda = vdb_hdda_t;`,\n `fn vdbHddaInit(h: ptr<function, VdbHdda>, o: vec3f, tmin: f32, d: vec3f, tmax: f32, dim: u32) {\n vdb_hdda_init(h, o, tmin, d, tmax, i32(dim));\n}`,\n `fn vdbHddaUpdate(h: ptr<function, VdbHdda>, o: vec3f, d: vec3f, dim: u32) -> bool {\n return vdb_hdda_update(h, o, d, i32(dim));\n}`,\n `fn vdbHddaStep(h: ptr<function, VdbHdda>) -> bool {\n return vdb_hdda_step(h);\n}`,\n `fn vdbGetDim(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> u32 {\n if !(*acc).ok {\n return 4096u;\n }\n var inner = (*acc).inner;\n let v = vdb_readaccessor_get_dim((*acc).gridType, (*acc).buf, &inner, ijk);\n (*acc).inner = inner;\n return v;\n}`,\n `fn vdbHasStats(g: u32) -> bool {\n return vdb_live(g) && (vdb_rec(g, VDB_REC_FLAGS) & VDB_REC_FLAG_HAS_STATS) != 0u;\n}`,\n `fn vdbValueMax(g: u32) -> f32 {\n if !vdb_live(g) {\n return 0.0;\n }\n return bitcast<f32>(vdb_rec(g, VDB_REC_VALUE_MAX));\n}`,\n `fn vdbNodeMax(acc: ptr<function, VdbAccessor>, ijk: vec3i, dim: u32) -> f32 {\n if !(*acc).ok {\n return 0.0;\n }\n let a = vdbGetDim(acc, ijk);\n if a > 1u && dim <= a {\n return vdbReadValue(acc, ijk);\n }\n if !(*acc).stats {\n return (*acc).vmax;\n }\n let t = (*acc).gridType;\n let b = (*acc).buf;\n if dim <= 8u {\n return vdb_leaf_get_max_float(t, b, (*acc).inner.leaf);\n }\n if dim <= 128u {\n return vdb_lower_get_max_float(t, b, (*acc).inner.lower);\n }\n if dim <= 4096u {\n return vdb_upper_get_max_float(t, b, (*acc).inner.upper);\n }\n return vdb_root_get_max_float(t, b, (*acc).inner.root);\n}`,\n ].join(\"\\n\");\n}\n\n/**\n * Opt-in helpers (K1.7a, the `helpers` option). Each is emitted only when\n * asked for, so modules without helpers keep their bytes (the size snapshot).\n *\n * `vdbCellBoundTrilinear(acc, ijk, dim)`: the max of `vdbNodeMax` over the\n * 2x2x2 block of aligned `dim`-cells whose min corner is the cell holding\n * `ijk` (that cell and its +x/+y/+z neighbours). A trilinear sample at `p`\n * reads voxels `floor(p) + {0,1}^3`, so when `floor(p)` lies in the cell every\n * tap lies in the block and the result bounds the sample, with `vdbNodeMax`'s\n * caveat: stats bound ACTIVE values, so inactive leaf voxels must be <= their\n * leaf's max (true of fog volumes). With `outside: 'zero'` and a negative\n * field, also take max(result, 0). This is the skip test a march needs; the\n * cell's own `vdbNodeMax` is not one (CLAUDE.md Traps). CPU twin: `tools`\n * `cellBoundTrilinear`.\n *\n * `vdbHddaCellEnd(h)`: the ray `t` where the HDDA's current cell ends,\n * `min(next.x, next.y, next.z, tmax)` of the vendored state, so a host\n * needn't name `VdbHdda`'s vendored fields. CPU twin: `tools` `hddaCellEnd`.\n *\n * `vdbNodeAverage(acc, ijk, dim)` (K3.2): the box mean of the aligned\n * `dim`-cell holding `ijk`, from node statistics instead of voxels (the\n * sparse volume source's `'node-average'` LOD). A cell inside one tile (or the\n * background) is that tile's value, exactly. Otherwise, for `dim <= 8`, the\n * leaf's average times its active fraction (`countOneBits` of the value mask\n * / 512): the exact mean when the leaf's inactive voxels are 0 (fog); for\n * `dim <= 128`, the lower node's average, which is the mean of its ACTIVE\n * voxels (NanoVDB stores no active count per lower node), so it overstates a\n * partly empty lower node; larger cells read the lower node too (`dim` is\n * meant to be 8 or 128; no upper level, to keep the module small). Without stats it is the value at `ijk` (no\n * prefilter). CPU twin: `tools` `nodeAverage`.\n *\n * `vdbRayClipSupport(g, o, d, t)`: `vdbRayClip` against the box where\n * `vdbSample` can read the grid's voxels: `[min - 1, max + 1]` for trilinear\n * (the taps of a point in `[min - 1, min)` reach voxel `min`) and\n * `[min - 0.5, max + 0.5]` for nearest. `vdbRayClip`'s box, `[min, max + 1]`,\n * is the voxel-cell box the HDDA walks; it cuts the min-side half voxel of the\n * trilinear support. CPU twin: `tools` `rayClipSupport`.\n */\nfunction helperFunctions(o: ApiOptions): string[] {\n const out: string[] = [];\n if (o.helpers.includes(\"rayClipSupport\")) {\n const pad = o.sampler === \"nearest\" ? \"0.5\" : \"1.0\";\n out.push(`fn vdbRayClipSupport(g: u32, o: vec3f, d: vec3f, t: ptr<function, vec2f>) -> bool {\n if !vdb_live(g) {\n return false;\n }\n var t0 = (*t).x;\n var t1 = (*t).y;\n let hit = vdb_hdda_ray_clip(vec3f(vdbIndexMin(g)) - vec3f(${pad}), vec3f(vdbIndexMax(g)) + vec3f(${pad}), o, &t0, d, &t1);\n *t = vec2f(t0, t1);\n return hit && t0 <= t1;\n}`);\n }\n if (o.helpers.includes(\"cellBoundTrilinear\")) {\n out.push(`fn vdbCellBoundTrilinear(acc: ptr<function, VdbAccessor>, ijk: vec3i, dim: u32) -> f32 {\n var m = vdbNodeMax(acc, ijk, dim);\n for (var k = 1u; k < 8u; k++) {\n let c = vec3i(vec3u(k & 1u, (k >> 1u) & 1u, (k >> 2u) & 1u)) * i32(dim);\n m = max(m, vdbNodeMax(acc, ijk + c, dim));\n }\n return m;\n}`);\n }\n if (o.helpers.includes(\"hddaCellEnd\")) {\n out.push(`fn vdbHddaCellEnd(h: ptr<function, VdbHdda>) -> f32 {\n return min(min((*h).next.x, (*h).next.y), min((*h).next.z, (*h).tmax));\n}`);\n }\n if (o.helpers.includes(\"fastTrilinear\")) {\n // Only trilinear has 8 taps to share (the generator rejects the helper with 'nearest').\n const inside = carriesBBox(1, o) ? \" || any(b < (*acc).lo) || any(b >= (*acc).hi)\" : \"\";\n // Uniform per-tap work (no per-lane choice between a leaf read and a descent: lanes of a SIMD group that\n // disagree would run both). All 8 taps lie in the base voxel's lower node (128-block) unless the base is\n // on its +x/+y/+z face; each tap is then one lower-node child lookup (the same words for taps in the same\n // leaf), never a tree walk. The vendored taps instead thrash the accessor's one-leaf cache when the cell\n // straddles leaves (x-fastest tap order alternates them).\n // A tap: one lower-node child lookup (the caching variant the accessor already uses, on a scratch cache).\n // vdbSampleFast: the lower node holding the base is the accessor's cached one, else a descent (which caches\n // it); at level 2+ the base's 128-block, which holds all 8 taps, is one tile (or the background): one value.\n // c0 holds taps 0-3 (z = 0), c1 taps 4-7 (z = 1), x fastest: the vendored c000, c100, c010, c110, c001, ...\n // No comments inside the WGSL: generated modules carry only the banner.\n out.push(`fn vdb_lower_tap(t: u32, buf: vdb_buf_t, node: vdb_lower_handle_t, b: vec3i, k: u32) -> f32 {\n let ijk = b + vec3i(vec3u(k & 1u, (k >> 1u) & 1u, k >> 2u));\n var s: vdb_readaccessor_t;\n let al = vdb_lower_get_value_address_and_level_and_cache(t, buf, node, ijk, &s);\n return vdb_read_float_typed(t, buf, al.address, ijk, al.level);\n}`);\n const taps = (from: number) => [0, 1, 2, 3].map((k) => `vdb_lower_tap(t, buf, n, b, ${from + k}u)`).join(\", \");\n out.push(`fn vdbSampleFast(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {\n let b = vec3i(floor(xyz));\n if !(*acc).ok || any((b & vec3i(127)) == vec3i(127))${inside} {\n return vdbSample(acc, xyz);\n }\n let t = (*acc).gridType;\n let buf = (*acc).buf;\n var inner = (*acc).inner;\n var lower = vdb_readaccessor_iscached1(&inner, vdb_readaccessor_computedirty(&inner, b));\n var v = 0.0;\n if !lower {\n let al = vdb_readaccessor_get_value_address_and_level(t, buf, &inner, b);\n lower = al.level <= 1u;\n v = vdb_read_float_typed(t, buf, al.address, b, al.level);\n }\n (*acc).inner = inner;\n var c0 = vec4f(v);\n var c1 = vec4f(v);\n if lower {\n let n = inner.lower;\n c0 = vec4f(${taps(0)});\n c1 = vec4f(${taps(4)});\n }\n let u = xyz - vec3f(b);\n return mix(mix(mix(c0.x, c0.y, u.x), mix(c0.z, c0.w, u.x), u.y), mix(mix(c1.x, c1.y, u.x), mix(c1.z, c1.w, u.x), u.y), u.z);\n}`);\n }\n if (o.helpers.includes(\"nodeAverage\")) {\n out.push(`fn vdbNodeAverage(acc: ptr<function, VdbAccessor>, ijk: vec3i, dim: u32) -> f32 {\n if !(*acc).ok {\n return 0.0;\n }\n let a = vdbGetDim(acc, ijk);\n if (a > 1u && dim <= a) || !(*acc).stats || dim <= 1u {\n return vdbReadValue(acc, ijk);\n }\n let t = (*acc).gridType;\n let b = (*acc).buf;\n if dim <= 8u {\n let leaf = (*acc).inner.leaf;\n var n = 0u;\n for (var w = 0u; w < 16u; w++) {\n n += countOneBits(vdb_read_uint32(b, vdb_address_offset(leaf.address, VDB_LEAF_OFF_VALUE_MASK + 4u * w)));\n }\n return vdb_leaf_get_ave_float(t, b, leaf) * (f32(n) / 512.0);\n }\n return vdb_lower_get_ave_float(t, b, (*acc).inner.lower);\n}`);\n }\n // K3.7: the level-set zero-crossing finder and normal (./level-set.ts).\n if (o.helpers.includes(\"levelSet\")) out.push(...levelSetWgsl());\n return out;\n}\n\n/**\n * API layers in profile order. A profile's API is every layer up to and\n * including its own (`majorant`, rank 3, is deferred past 0.1, D22).\n */\nexport const API_LAYERS: readonly ((o: ApiOptions, profileRank: number) => string)[] = [readLayer, sampleLayer, marchLayer];\n\n/** The public API text for the profile at `profileRank` (0 = read, 1 = sample, 2 = march), then the requested helpers. */\nexport function apiWgsl(profileRank: number, o: ApiOptions): string {\n return [...API_LAYERS.slice(0, profileRank + 1).map((layer) => layer(o, profileRank)), ...helperFunctions(o)].join(\"\\n\");\n}\n"]}
|