pycollada

0.9.3 · active · verified Sat Apr 11

pycollada is a Python library for reading, writing, and creating COLLADA (COLLAborative Design Activity) documents, an interchange file format for interactive 3D applications. It allows users to load a COLLADA file and interact with it as a Python object, supporting creation from scratch and in-place editing. The current version is 0.9.3, released on January 24, 2026, with a fairly active release cadence addressing compatibility and performance improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple COLLADA document containing a single red triangle and then save it. It also shows how to load an existing COLLADA file and access its basic properties. Requires numpy to be installed.

import os
from collada import Collada, material, geometry, source
import numpy as np

# 1. Create a new COLLADA document
mesh = Collada()

# 2. Define geometry: a simple triangle
# Vertices
verts = np.array([
    0.0, 0.0, 0.0,
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0
])
normals = np.array([
    0.0, 0.0, 1.0,
    0.0, 0.0, 1.0,
    0.0, 0.0, 1.0
])

vert_src = source.FloatSource('my_verts-positions', verts, ('X', 'Y', 'Z'))
norm_src = source.FloatSource('my_normals-normals', normals, ('X', 'Y', 'Z'))

# Indices for a single triangle
triangles = np.array([0, 0, 1, 1, 2, 2]) # vertex index, normal index, ...

geom = geometry.Geometry(mesh, 'geometry0', 'my_triangle_geometry',
                       [geometry.Triangles(vert_src, norm_src, triangles, 'material0')])

mesh.geometries.append(geom)

# 3. Create a material
effect = material.Effect('effect0', [], 'phong', diffuse=(1, 0, 0, 1))
mat = material.Material('material0', 'red_material', effect)
mesh.materials.append(mat)
mesh.effects.append(effect)

# 4. Save the COLLADA document
output_file = 'my_first_collada.dae'
mesh.write(output_file)
print(f"Created '{output_file}'")

# 5. Load an existing COLLADA document (or the one we just created)
# For demonstration, we'll try to load the file we just saved.
if os.path.exists(output_file):
    loaded_mesh = Collada(output_file)
    print(f"Loaded '{output_file}' with {len(loaded_mesh.geometries)} geometries.")
    # Example: Accessing a geometry
    if loaded_mesh.geometries:
        print(f"First geometry ID: {loaded_mesh.geometries[0].id}")
else:
    print(f"Could not load '{output_file}'. Make sure the file exists.")

view raw JSON →