Skip to main content

Lightweight OpenVDB file I/O, mesh-to-SDF, and grid operations

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.8.2.tar.gz (26.1 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.8.2-cp311-abi3-win_amd64.whl (257.1 kB view details)

Uploaded CPython 3.11+Windows x86-64

tinyvdb-0.8.2-cp311-abi3-musllinux_1_2_x86_64.whl (1.7 MB view details)

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

tinyvdb-0.8.2-cp311-abi3-musllinux_1_2_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ ARM64

tinyvdb-0.8.2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (661.0 kB view details)

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

tinyvdb-0.8.2-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (644.5 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

tinyvdb-0.8.2-cp311-abi3-macosx_11_0_arm64.whl (490.3 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

tinyvdb-0.8.2-cp311-abi3-macosx_10_9_x86_64.whl (581.0 kB view details)

Uploaded CPython 3.11+macOS 10.9+ x86-64

File details

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

File metadata

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

File hashes

Hashes for tinyvdb-0.8.2.tar.gz
Algorithm Hash digest
SHA256 04c3baca49b60f2a9a4047e50c4434879236f1c73b54f42ed806b1e377a9cca7
MD5 f164087a67e0a44045d62134b67e1858
BLAKE2b-256 3403af8946bf7d36b1fcdb1da70c1f169a69bc098909c9aaa3a1f98609ac4970

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.8.2.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.8.2-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: tinyvdb-0.8.2-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 257.1 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.8.2-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 36280d6bfb3c82f528c2fc77962b846011615557da3892d9440200d03157f4d8
MD5 f8114beef8b261a108c5cbf444407aa3
BLAKE2b-256 379853baff4d0000c6e084df7f1e0820c2f4391472a4673e70259bdc071bed6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.8.2-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.8.2-cp311-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tinyvdb-0.8.2-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f26c9302d9b4c782fd23ac437bb70255f187e9136dce393d18ceded79a5d824c
MD5 e9ca161d7be03d6392daa0ef86ef3c9a
BLAKE2b-256 2ca9daebbf55229bf3597e22878af7ac8959409e4d4464a41029fa2efa57c4be

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.8.2-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.8.2-cp311-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tinyvdb-0.8.2-cp311-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 93f5cac28c8edfc5483cdb6df893bfe3a8dc69e95cddb1a8165992823e59f500
MD5 2e1d1596c79052d34c4dca2757b1fdf6
BLAKE2b-256 a22491f320d135d6461616e535fb00decbaf1c7142e4ffda0494e3da111e20c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.8.2-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.8.2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tinyvdb-0.8.2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af470d5a07f2633bc51980de8339f6857e9a8e804f362f281db3b7e01f8800a0
MD5 82ead8807389a1cd703976990305b20c
BLAKE2b-256 8cb7cd6a8d2cc5b899dcbbe5f9fd2b570e5e941bc0ed6425c01eb9b34000ac8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.8.2-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.8.2-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tinyvdb-0.8.2-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 29c1b1cf53064928ca75e0f346c35652320f922146de2933df762653afa6f0df
MD5 9011c770721509ae07ee1c06b3a7fb31
BLAKE2b-256 0ed9542a8b207adb49295f4d631d75d60ed0ac5d458acbae78146897a2601060

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.8.2-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.8.2-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tinyvdb-0.8.2-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cb95b044f219dcea7b3a000f35c548edada79009034811aee84483e5a7c4aca9
MD5 15c9fdbbb450503a152bfe25011d35f6
BLAKE2b-256 3da4a862284ae925cad5b747cec12c91c9785c565ee1d4a9082ea74d8051a5a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.8.2-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.8.2-cp311-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tinyvdb-0.8.2-cp311-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c9c9ef78f6c56bd0d4669e756e4e209b91b069fe5a2a246aed018011ed6a9d2a
MD5 d43af67d54734483db0e8df5fbba3d12
BLAKE2b-256 53789d1cee263968e682ebefc735d1c1784a5f70e894c179ee7df3ba106d2d7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinyvdb-0.8.2-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