xatlas-python

0.0.11 · active · verified Wed Apr 15

xatlas-python provides Python bindings for xatlas, a C++ library for generating UV atlases. It allows users to create texture atlases for 3D meshes, optimizing texture space and improving rendering performance. The current version is 0.0.11, and releases occur semi-regularly as new features are added or bugs fixed, typically every few months, reflecting active development.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an `Atlas`, add a mesh defined by NumPy arrays for vertices and indices, generate the UV atlas, and then access the resulting meshes with their generated UV coordinates. Input data types (`np.float32` for vertices, `np.uint32` for indices) are crucial.

import xatlas
import numpy as np

# Create an atlas instance
atlas = xatlas.Atlas()

# Define a simple mesh (e.g., a quad)
vertices = np.array([
    [0.0, 0.0, 0.0],
    [1.0, 0.0, 0.0],
    [0.0, 1.0, 0.0],
    [1.0, 1.0, 0.0],
], dtype=np.float32)

indices = np.array([
    [0, 1, 2],
    [2, 1, 3],
], dtype=np.uint32)

# Add the mesh to the atlas
atlas.add_mesh(vertices, indices)

# Generate the UV atlas
atlas.generate()

# Access the generated meshes and their UVs
print(f"Generated {len(atlas.meshes)} mesh(es).")
for i, mesh in enumerate(atlas.meshes):
    print(f"\nMesh {i}:")
    print(f"  Vertices shape: {mesh.vertices.shape} (position data)")
    print(f"  Indices shape: {mesh.indices.shape} (triangle connectivity)")
    print(f"  UVs shape: {mesh.uvs.shape} (texture coordinates)")
    # Example: print first few UVs
    if mesh.uvs.size > 0:
        print(f"  First 3 UVs:\n{mesh.uvs[:3]}")

view raw JSON →