[docs]classGithubPackageMeshLoader(AbstractMeshLoader):"""Loads resources stored in Github. Attributes ---------- repository : str Repository name including organization, e.g. ``ros-industrial/abb``. support_package : str Name of the support package containing URDF, Meshes and additional assets, e.g. 'abb_irb4400_support' branch : str Branch name, defaults to ``master``. """HOST='https://raw.githubusercontent.com'def__init__(self,repository,support_package,branch='master'):super(GithubPackageMeshLoader,self).__init__()self.repository=repositoryself.support_package=support_packageself.branch=branchself.schema_prefix='package://'+self.support_package+'/'
[docs]defbuild_url(self,file):"""Returns the corresponding url of the file. Parameters ---------- file : str File name. Following convention, the file should reside inside a ``urdf`` folder. Returns ------- str The file's url. """return'{}/{}/{}/{}/{}'.format(GithubPackageMeshLoader.HOST,self.repository,self.branch,self.support_package,file)
[docs]defload_urdf(self,file):"""Load a URDF file from a Github support package repository. Parameters ---------- file : str File name. Following convention, the file should reside inside a ``urdf`` folder. """url=self.build_url('urdf/{}'.format(file))returnurlopen(url)
[docs]defcan_load_mesh(self,url):"""Determine whether this loader can load a given mesh URL. Parameters ---------- url : str Mesh URL. Returns ------- bool ``True`` if the URL uses the ``package://` scheme and the package name matches the specified in the constructor, otherwise ``False``. """returnurl.startswith(self.schema_prefix)
[docs]defload_mesh(self,url):"""Loads a mesh from a Github repository URL. Parameters ---------- url : str Mesh location Returns ------- :class:`Mesh` Instance of a mesh. """_prefix,path=url.split(self.schema_prefix)url=self.build_url(path)# TODO: As soon as compas.files adds support# for file-like objects, we could skip# storing a temp file for these urlstempfile,_=urlretrieve(url)return_mesh_import(url,tempfile)