libigl Python Bindings

2.6.2 · active · verified Thu Apr 16

libigl provides Python bindings for the C++ libigl library, a powerful and simple geometry processing toolkit. It offers a wide range of functionalities, including discrete differential geometry operators, finite-element matrices, and mesh topology data structures. The current version is 2.6.2, and the library is actively developed with frequent releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple mesh, save it to a file using `igl.write_triangle_mesh`, and then load it back using `igl.read_triangle_mesh`. It uses NumPy arrays for vertex coordinates and face connectivity. For interactive visualization, additional libraries like `meshplot` (not included here) are often used.

import igl
import numpy as np
import os

# Create a simple mesh (triangle on the XY plane)
V = np.array([
    [0.0, 0.0, 0.0],
    [1.0, 0.0, 0.0],
    [0.0, 1.0, 0.0]
], dtype=np.float64)
F = np.array([
    [0, 1, 2]
], dtype=np.int32)

# Define a path for saving/loading
output_dir = os.environ.get('LIBIGL_OUTPUT_DIR', '.')
output_mesh_path = os.path.join(output_dir, 'example_triangle.obj')

# Save the mesh
success = igl.write_triangle_mesh(output_mesh_path, V, F)
print(f"Mesh saved successfully: {success} to {output_mesh_path}")

# Load the mesh back
V_loaded, F_loaded = igl.read_triangle_mesh(output_mesh_path)
print(f"Loaded Vertices shape: {V_loaded.shape}, Faces shape: {F_loaded.shape}")

# Example: Calculate edge lengths (requires a function like igl.edge_lengths)
# This is illustrative; actual function name might vary and require more imports.
# If igl.edge_lengths existed, it might look like:
# L = igl.edge_lengths(V, F)
# print(f"Edge lengths: {L}")

# Cleanup (optional)
# os.remove(output_mesh_path)

view raw JSON →