Skip to main content

Lightweight OpenVDB and NanoVDB I/O (cross-validated against libopenvdb 13 / libnanovdb 32), mesh-to-SDF, dense/sparse grid ops, CPU autograd, Gaussian-splat rasterizer (forward+backward)

Project description

tinyvdb

Lightweight Python bindings for TinyVDB — a lightweight C/C++ library for OpenVDB and NanoVDB file I/O, mesh-to-SDF conversion, and grid operations. No OpenVDB dependency required.

Built with the Python C Stable API (abi3) for broad compatibility: one wheel per platform works across Python 3.11+.

Installation

pip install tinyvdb

Pre-built wheels are available for:

Platform Architectures
Linux x86_64, aarch64
macOS x86_64, arm64
Windows AMD64

Quick start

Read a VDB file

import tinyvdb

with tinyvdb.open("smoke.vdb") as f:
    print(f.grid_count, "grids")
    print(f.header)

    f.read_grids()
    grid = f.grid(0)
    print(grid.name, grid.type_name)
    print(grid.transform)
    print(grid.metadata)

    # Access tree structure
    tree = grid.tree
    node = tree.node(0)
    print(node.type, node.origin)

Read a NanoVDB file

import tinyvdb

with tinyvdb.NanoVDBFile("sphere.nvdb") as f:
    print(f.grid_count, "grids")
    for i in range(f.grid_count):
        print(f"  Grid {i}: {f.grid_name(i)}")
        print(f"  Type: {f.grid_type(i)}")
        print(f"  Class: {f.grid_class(i)}")
        print(f"  Voxel size: {f.voxel_size(i)}")
        print(f"  BBox: {f.bbox(i)}")
        print(f"  World BBox: {f.world_bbox(i)}")
        print(f"  Node counts: {f.node_counts(i)}")
        print(f"  Active voxels: {f.active_voxel_count(i)}")

NanoVDB utilities

import tinyvdb

# Node sizes
leaf_size = tinyvdb.leaf_node_size()          # Default: Float
lower_size = tinyvdb.lower_node_size()         # Default: Float
upper_size = tinyvdb.upper_node_size()         # Default: Float

# Value sizes
float_size = tinyvdb.value_size()              # 4 bytes
vec3f_size = tinyvdb.value_size(tinyvdb.GRID_TYPE_VEC3F)  # 12 bytes
double_size = tinyvdb.value_size(tinyvdb.GRID_TYPE_DOUBLE) # 8 bytes

# Grid type names
name = tinyvdb.grid_type_name(tinyvdb.GRID_TYPE_FLOAT)  # "Float"

Load from bytes / save round-trip

data = open("input.vdb", "rb").read()
f = tinyvdb.from_bytes(data)
f.read_grids()

# Serialize back
output = f.to_bytes(compression=tinyvdb.COMPRESS_ZIP, level=5)
open("output.vdb", "wb").write(output)
f.close()

Mesh to SDF and back

import struct
import tinyvdb

# Vertices as flat float32 buffer, faces as flat uint32 buffer
vertices = struct.pack("9f", 0,0,0, 1,0,0, 0,1,0)
faces = struct.pack("3I", 0, 1, 2)

# Convert mesh to signed distance field
sdf = tinyvdb.mesh_to_sdf(vertices, faces, voxel_size=0.05, band_width=3.0)
print(sdf.shape)  # (nx, ny, nz)

# Extract mesh via marching cubes
mesh = tinyvdb.sdf_to_mesh(sdf, isovalue=0.0)
print(mesh.num_vertices, mesh.num_faces)

CSG operations

union = tinyvdb.csg_union(sdf_a, sdf_b)
intersection = tinyvdb.csg_intersection(sdf_a, sdf_b)
difference = tinyvdb.csg_difference(sdf_a, sdf_b)

Morphology and filtering

dilated = tinyvdb.dilate(sdf, iterations=2)
eroded = tinyvdb.erode(sdf, iterations=1)
smoothed = tinyvdb.gaussian_filter(sdf, width=1, iterations=3)

Measurement

area = tinyvdb.surface_area(sdf)
vol = tinyvdb.volume(sdf)

Ray casting

hit = tinyvdb.ray_cast_sdf(sdf,
                            origin=(0, 0, -5),
                            direction=(0, 0, 1),
                            max_t=100.0)
if hit:
    print(hit["t"], hit["position"], hit["normal"])

Differential operators

grad = tinyvdb.gradient(sdf)          # -> DenseVecGrid
div  = tinyvdb.divergence(grad)       # -> DenseGrid
lap  = tinyvdb.laplacian(sdf)         # -> DenseGrid
c    = tinyvdb.curl(vec_field)        # -> DenseVecGrid

Advection and Poisson solver

advected = tinyvdb.advect(field, velocity, dt=0.01)
solution, iterations = tinyvdb.solve_poisson(rhs, max_iters=500, tolerance=1e-6)

Particles and fracture

# Rasterize particles into SDF
sdf = tinyvdb.particles_to_sdf(positions, radii,
                                voxel_size=0.05, band_width=3.0)

# Fill volume interior with spheres
result = tinyvdb.volume_to_spheres(sdf, min_radius=0.01, max_spheres=500)

# Fracture volume with cutter SDFs
pieces = tinyvdb.fracture(volume, [cutter1, cutter2])

Manifold repair

mesh = tinyvdb.make_manifold(vertices, faces,
                              resolution=50, isovalue=0.55)

numpy interop

DenseGrid supports the buffer protocol, so zero-copy access works with numpy:

import numpy as np

grid = tinyvdb.mesh_to_sdf(verts, faces, 0.1, 3.0)
arr = np.frombuffer(grid, dtype=np.float32).reshape(grid.shape)

API reference

Types

Type Description
VDBFile VDB file handle (context manager)
VDBGrid Grid accessor (name, type, transform, metadata, tree)
VDBTree Tree structure with node access
VDBNode Tree node (root, internal, or leaf)
DenseGrid 3D scalar grid with buffer protocol
DenseVecGrid 3D vector field (3-component) with buffer protocol
TriangleMesh Triangle mesh (vertices + faces as bytes)
VDBError Exception type (subclass of RuntimeError)

Constants

Compression

Constant Value Description
COMPRESS_NONE 0 No compression
COMPRESS_ZIP 1 ZIP (zlib/miniz)
COMPRESS_ACTIVE_MASK 2 Compress node masks
COMPRESS_BLOSC 4 BLOSC (LZ4)
SIGN_FLOOD_FILL 0 Exterior flood fill sign method
SIGN_SWEEP 1 Directional sweep sign method

NanoVDB Codecs

Constant Value Description
CODEC_NONE 0 No compression
CODEC_ZIP 1 ZIP compression
CODEC_BLOSC 2 BLOSC compression

NanoVDB Grid Types

Constant Value Description
GRID_TYPE_FLOAT 1 32-bit float
GRID_TYPE_DOUBLE 2 64-bit double
GRID_TYPE_INT32 4 32-bit integer
GRID_TYPE_INT64 5 64-bit integer
GRID_TYPE_VEC3F 6 3D float vector
GRID_TYPE_VEC3D 7 3D double vector

NanoVDB Grid Classes

Constant Value Description
GRID_CLASS_LEVEL_SET 1 Level set
GRID_CLASS_FOG_VOLUME 2 Fog volume
GRID_CLASS_POINT_DATA 6 Point data

Supported VDB versions

Reads and writes OpenVDB files version 220 through 225 (OpenVDB 3.x to 10.x+).

License

Apache License 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinyvdb-0.9.0.tar.gz (25.7 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tinyvdb-0.9.0-cp311-abi3-win_amd64.whl (293.7 kB view details)

Uploaded CPython 3.11+Windows x86-64

tinyvdb-0.9.0-cp311-abi3-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ x86-64

tinyvdb-0.9.0-cp311-abi3-musllinux_1_2_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ ARM64

tinyvdb-0.9.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (754.3 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

tinyvdb-0.9.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (698.5 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

tinyvdb-0.9.0-cp311-abi3-macosx_11_0_arm64.whl (537.8 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

tinyvdb-0.9.0-cp311-abi3-macosx_10_9_x86_64.whl (631.6 kB view details)

Uploaded CPython 3.11+macOS 10.9+ x86-64

File details

Details for the file tinyvdb-0.9.0.tar.gz.

File metadata

  • Download URL: tinyvdb-0.9.0.tar.gz
  • Upload date:
  • Size: 25.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tinyvdb-0.9.0.tar.gz
Algorithm Hash digest
SHA256 2754eb1cefb6b8cb07cc017a0ab4b114b50807ed4f2358475340a37c9ec49ba2
MD5 0ab081ef3cb03836fd440332f837a978
BLAKE2b-256 eaa60baec683da6d00557c1256553ffe8ca3d3a240c6b4249a66bd70ae30db1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.9.0.tar.gz:

Publisher: wheels.yml on syoyo/tinyvdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tinyvdb-0.9.0-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: tinyvdb-0.9.0-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 293.7 kB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tinyvdb-0.9.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 21ef3ca1b887fa39d7808dee5a916e2844e811b6cbf662f9c60d2012e26a3674
MD5 6f35f0f8dc14330f4d8635303f2ea50e
BLAKE2b-256 b4506d01e7fc98d936103feed232ddaa8402e71ac12feba7f5059a6ecec9c3f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.9.0-cp311-abi3-win_amd64.whl:

Publisher: wheels.yml on syoyo/tinyvdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tinyvdb-0.9.0-cp311-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tinyvdb-0.9.0-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 964dfa4e94807d9a1234c928c0096a35ccb67c8c444c236b258a4d2ac8a37c21
MD5 e0276c213e4b3fe5e5ec3ffc3cd76409
BLAKE2b-256 2af38efd46550911f38ae6ccc4d5ca763c1450b062a29e193aa760b1d465981d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.9.0-cp311-abi3-musllinux_1_2_x86_64.whl:

Publisher: wheels.yml on syoyo/tinyvdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tinyvdb-0.9.0-cp311-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tinyvdb-0.9.0-cp311-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 ed196d5edf46815c2adab2bc0c5fa65a0f3804d0c35b8ce239b98ff52d46da2c
MD5 c3b3f9afcb7154a2e2219b566b864f2f
BLAKE2b-256 3ec9c0d1353d09bd17a5254c2fd4997f90786a971c871f204381b2586117a800

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.9.0-cp311-abi3-musllinux_1_2_aarch64.whl:

Publisher: wheels.yml on syoyo/tinyvdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tinyvdb-0.9.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tinyvdb-0.9.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2b3b4c5543ee119ed5b0671c23e493c8b9a25332ca650aac53cf50f8ca342346
MD5 c38446b47933780cb2ffe88311a70ed2
BLAKE2b-256 cbab7b6d7d9dbf55d1e481b3c0b7032d25b0e8455b17bfb04e0c21ceb46568e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.9.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on syoyo/tinyvdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tinyvdb-0.9.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tinyvdb-0.9.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f49799494be6504fdf914cd4026458a8df2391c750592b53a74394937742ea1c
MD5 1a6d34bff2924411c4eedf655a625dc7
BLAKE2b-256 c8565411dc467fa611222c0c6ff2810babecb8816b04cb22fa1d8afd3e39a116

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.9.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: wheels.yml on syoyo/tinyvdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tinyvdb-0.9.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tinyvdb-0.9.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 38d3537bf51b99ce0c083b1002962b27a4d1807d24bce44971e388f4d862dbeb
MD5 fc5b9a5a5a1f8e31ebdc656810e676cc
BLAKE2b-256 7cca4338698299659debbe0fdc8bc1693c408a4ac27166fd48ebc3a113a568cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.9.0-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on syoyo/tinyvdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tinyvdb-0.9.0-cp311-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tinyvdb-0.9.0-cp311-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ac21c5449d6b327023cbee98c2618dccd8f2ded1949bdc9b145d25d125cb689c
MD5 5ee08bc9241149bed8a4fc1388c42d94
BLAKE2b-256 3b9760d07c1d6063631ba220742c6baf02d9dbad634fce2f78f13cf2780c29cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.9.0-cp311-abi3-macosx_10_9_x86_64.whl:

Publisher: wheels.yml on syoyo/tinyvdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page