cmeel-assimp

6.0.2 · active · verified Thu Apr 16

cmeel-assimp is a Python distribution of the Open-Asset-Importer-Library (Assimp), providing bindings to load and process 3D models from a multitude of file formats. It leverages the cmeel build system to simplify the installation of the underlying C++ library. The current version is 6.0.2, reflecting the latest Assimp releases.

Common errors

Warnings

Install

Imports

Quickstart

Loads a basic Wavefront OBJ file, demonstrates accessing mesh data (vertices and faces), and ensures proper scene release. It includes common post-processing flags for triangulation and normal generation.

import os
from pyassimp import load, postprocess

# Create a dummy model file for demonstration
dummy_model_content = """
# Wavefront .obj file
# A simple triangle

v 0.0 0.0 0.0
v 1.0 0.0 0.0
v 0.0 1.0 0.0

f 1 2 3
"""

model_path = 'dummy_triangle.obj'
with open(model_path, 'w') as f:
    f.write(dummy_model_content)

try:
    # Load a 3D model with basic post-processing
    # Use aiProcess_Triangulate to ensure all faces are triangles
    # Use postprocess.aiProcess_GenNormals to generate smooth normals if not present
    scene = load(model_path, processing=postprocess.aiProcess_Triangulate | postprocess.aiProcess_GenNormals)

    print(f"Successfully loaded model: {model_path}")
    print(f"Number of meshes in scene: {len(scene.meshes)}")
    
    if scene.meshes:
        mesh = scene.meshes[0]
        print(f"First mesh has {len(mesh.vertices)} vertices and {len(mesh.faces)} faces.")
        if mesh.vertices:
            print(f"First vertex: {mesh.vertices[0]}")
        if mesh.faces:
            print(f"First face (indices): {mesh.faces[0]}")
    
    # It's good practice to release the scene explicitly when done
    scene.release()

except Exception as e:
    print(f"Error loading model: {e}")
finally:
    # Clean up the dummy model file
    if os.path.exists(model_path):
        os.remove(model_path)

view raw JSON →