def load_geometry(self, *resource_loaders, **kwargs): """Load external geometry resources, such as meshes. Args: resource_loaders: List of objects that implement the resource loading interface (:class:`compas.robots.AbstractMeshLoader`) and can retrieve external geometry. force: True if it should force reloading even if the geometry has been loaded already, otherwise False. """ force = kwargs.get('force', False) loaders = list(resource_loaders) loaders.insert(0, DefaultMeshLoader()) for link in self.links: for element in itertools.chain(link.collision, link.visual): shape = element.geometry.shape needs_reload = force or not shape.geometry if 'filename' in dir(shape) and needs_reload: for loader in loaders: if loader.can_load_mesh(shape.filename): shape.geometry = loader.load_mesh(shape.filename) break if not shape.geometry: raise Exception( 'Unable to load geometry for {}'.format( shape.filename))
def load_geometry(self, *resource_loaders, **kwargs): """Load external geometry resources, such as meshes. Parameters ---------- resource_loaders : :class:`compas.robots.AbstractMeshLoader` List of objects that implement the resource loading interface (:class:`compas.robots.AbstractMeshLoader`) and can retrieve external geometry. force : bool True if it should force reloading even if the geometry has been loaded already, otherwise False. Examples -------- >>> robot = RobotModel.ur5() >>> robot.load_geometry(LocalPackageMeshLoader(compas.DATA, 'ur_description')) >>> print(robot) Robot name=ur5, Links=11, Joints=10 (6 configurable) """ force = kwargs.get('force', False) loaders = list(resource_loaders) loaders.insert(0, DefaultMeshLoader()) for link in self.links: for element in itertools.chain(link.collision, link.visual): shape = element.geometry.shape needs_reload = force or not shape.meshes if 'filename' in dir(shape) and needs_reload: for loader in loaders: if loader.can_load_mesh(shape.filename): # NOTE: this part is annoying, but we keep it for backwards compatibility's sake. # Externally defined loaders (eg. COMPAS_FAB File Server loader) # might not be updated yet on the user's system, so we fallback # to the deprecated load_mesh method in that case. # However, to add to the confusion, some loaders were actually returning # meshes regardless of the misnaming. We handle that in _get_item_meshes # so, we don't force load_mesh into a list, otherwise it will turn into a # list of lists in those cases. # All of this ugly fallback should be removed in 2.0 if hasattr(loader, 'load_meshes'): shape.meshes = loader.load_meshes( shape.filename) else: shape.meshes = loader.load_mesh(shape.filename) break if not shape.meshes: raise Exception('Unable to load meshes for {}'.format( shape.filename))
def load_geometry(self, *resource_loaders, **kwargs): """Load external geometry resources, such as meshes. Parameters ---------- resource_loaders: :class:`compas.robots.AbstractMeshLoader` List of objects that implement the resource loading interface (:class:`compas.robots.AbstractMeshLoader`) and can retrieve external geometry. force: boolean True if it should force reloading even if the geometry has been loaded already, otherwise False. Examples -------- >>> loader = GithubPackageMeshLoader('ros-industrial/abb', 'abb_irb6600_support', 'kinetic-devel') >>> urdf = loader.load_urdf('irb6640.urdf') >>> model = RobotModel.from_urdf_file(urdf) >>> model.load_geometry(loader) """ force = kwargs.get('force', False) loaders = list(resource_loaders) loaders.insert(0, DefaultMeshLoader()) for link in self.links: for element in itertools.chain(link.collision, link.visual): shape = element.geometry.shape needs_reload = force or not shape.geometry if 'filename' in dir(shape) and needs_reload: for loader in loaders: if loader.can_load_mesh(shape.filename): shape.geometry = loader.load_mesh(shape.filename) break if not shape.geometry: raise Exception( 'Unable to load geometry for {}'.format( shape.filename))