DracoPy - Draco Mesh Compression Wrapper

2.0.0 · active · verified Fri Apr 17

DracoPy is a Python wrapper for Google's Draco Mesh Compression Library, enabling efficient encoding and decoding of 3D mesh data. It supports common formats like OBJ and PLY (via in-memory mesh objects). The current version is 2.0.0, with releases occurring infrequently, often coinciding with upstream Draco library updates or significant API overhauls.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple 3D mesh using NumPy arrays, encode it into Draco compressed bytes, and then decode it back into a `DracoMesh` object. It highlights the use of NumPy for mesh data, which is standard in version 2.0.0 and above.

import dracopy
import numpy as np

# 1. Create a dummy mesh (a simple triangle)
# Vertices and faces must be NumPy arrays in DracoPy 2.0.0+
vertices = np.array([
    [0.0, 0.0, 0.0],
    [1.0, 0.0, 0.0],
    [0.0, 1.0, 0.0]
], dtype=np.float32)

faces = np.array([
    [0, 1, 2]
], dtype=np.int32)

# Create a DracoMesh object
mesh_to_encode = dracopy.DracoMesh(vertices=vertices, faces=faces)

# 2. Encode the mesh to Draco bytes
print("Encoding mesh...")
draco_bytes = dracopy.encode(mesh_to_encode, compression_level=7)
print(f"Encoded bytes length: {len(draco_bytes)}")

# 3. Decode the Draco bytes back to a DracoMesh
print("Decoding mesh...")
decoded_mesh = dracopy.decode(draco_bytes)

# 4. Access decoded data (still NumPy arrays)
print(f"Decoded vertices shape: {decoded_mesh.vertices.shape}")
print(f"Decoded faces shape: {decoded_mesh.faces.shape}")

# Optional: Verify data equality
assert np.array_equal(vertices, decoded_mesh.vertices)
assert np.array_equal(faces, decoded_mesh.faces)
print("Encoding and decoding successful!")

view raw JSON →