Skip to content

Commit

Permalink
DAE loading improoved: warning if pycollada not installed and ignore …
Browse files Browse the repository at this point in the history
…broken option (#10)

* print warning that pycollada needs to be installed to load dae meshes.

* loading of broken meshes allowed with a warning printed

Co-authored-by: Vladimir Petrik <[email protected]>
  • Loading branch information
petrikvladimir and petrikvladimir authored Nov 30, 2022
1 parent 96bb02a commit 526a85a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/robomeshcat/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,22 @@ def create_cylinder(cls, radius: float, length: float, pose=None, color: Optiona
def create_mesh(cls, path_to_mesh: Union[str, Path], scale: Union[float, List[float]] = 1., pose=None,
color: Optional[List[float]] = None, texture: Optional[Union[g.ImageTexture, Path]] = None,
opacity: float = 1., name: str = None):
""" Create a object given by mesh geometry loaded by trimes. """
mesh: trimesh.Trimesh = trimesh.load(path_to_mesh, force='mesh')
"""Create a mesh object by loading it from the :param path_to_mesh. Loading is performed by 'trimesh' library
internally."""
try:
mesh: trimesh.Trimesh = trimesh.load(path_to_mesh, force='mesh')
except ValueError as e:
if str(e) == 'File type: dae not supported':
print('To load DAE meshes you need to install pycollada package via '
'`conda install -c conda-forge pycollada`'
' or `pip install pycollada`')
raise
except Exception as e:
print(f'Loading of a mesh failed with message: \'{e}\'. '
f'Trying to load with with \'ignore_broken\' but consider to fix the mesh located here:'
f' \'{path_to_mesh}\'.')
mesh: trimesh.Trimesh = trimesh.load(path_to_mesh, force='mesh', ignore_broken=True)

mesh.apply_scale(scale)
try:
exp_obj = trimesh.exchange.obj.export_obj(mesh)
Expand Down

0 comments on commit 526a85a

Please sign in to comment.