From 526a85af8a2743b190a9a1bb8c55925f48eb9af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Petr=C3=ADk?= Date: Wed, 30 Nov 2022 15:00:03 +0100 Subject: [PATCH] DAE loading improoved: warning if pycollada not installed and ignore 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 --- src/robomeshcat/object.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/robomeshcat/object.py b/src/robomeshcat/object.py index 30cd44e..db26822 100644 --- a/src/robomeshcat/object.py +++ b/src/robomeshcat/object.py @@ -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)