Skip to content

Collada DAE support #19109

@RussTedrake

Description

@RussTedrake

Original title: Provide tools to help convert Collada DAE to Wavefront OBJ

Related to #2941, #14436, and #18844.

Request: We now have stl2obj. I think we should provide something similar for dae. Or at least publish our recommended workflow.

This is most relevant for visual geometries, because the primary difficulties were in preserving the colors/textures during conversion. Meshcat actually supports DAE directly. But Drake's simulated cameras do not support dae, and currently perform badly (#19055) when the visual geometry is specified as a dae asset.

I'll document here my experience in converting this file, which was more challenging than it should have been.

Approach 1: Meshlab.

Result: Meshlab failed to load the colors; unsuprisingly the exported obj was missing the colors, too.

Approach 2: Assimp.

Usage: assimp export daefile objfile
Result: Drake doesn't like that the exported obj file has multiple objects

RuntimeError: The OBJ file contains multiple objects; only OBJs with a single object are supported: File name: '/home/russt/QR/assets/movo_description_drake/meshes/manipulation/robotiq/visual/robotiq_85_base_link.obj'

Approach 3: Trimesh

Usage: I wrote this simple script:

import pathlib
from trimesh import load_mesh
from trimesh.exchange.obj import export_obj

for mesh_file in pathlib.Path('.').glob('*.dae'):
    mesh = load_mesh(mesh_file)
    obj, data = export_obj(
                mesh, return_texture=True, mtl_name=mesh_file.with_suffix('.mtl'))
    obj_file = mesh_file.with_suffix('.obj')
    with open(obj_file, "w") as f:
        f.write(obj)
    # save the MTL and images                                
    for k, v in data.items():
        with open(k, 'wb') as f:
            f.write(v)

Result: Drake doesn't like that the exported obj file has multiple objects

RuntimeError: The OBJ file contains multiple objects; only OBJs with a single object are supported: File name: '/home/russt/QR/assets/movo_description_drake/meshes/manipulation/robotiq/visual/robotiq_85_base_link.obj'

Approach 4: Blender

Usage: I wrote this simple script:

# Run with e.g.
# blender --background --python convert_dae_to_obj.py -- kinova_robotiq_coupler.dae ../collision/kinova_robotiq_coupler.obj

import bpy
import sys

argv = sys.argv
argv = argv[argv.index("--") + 1 :]  # get all args after "--"

dae_in = argv[0]
obj_out = argv[1]

bpy.ops.object.delete()
bpy.ops.wm.collada_import(filepath=dae_in)
bpy.ops.export_scene.obj(filepath=obj_out, axis_forward="Y", axis_up="Z")

Result: That worked! The only drawback is that the generated asset is now infected with GPL.

Metadata

Metadata

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions