def load_meshes(self, url): """Load meshes from the given URL in the ROS file server. A single mesh url can contain multiple meshes depending on the format. Parameters ---------- url : str Mesh URL Returns ------- list[:class:`compas.datastructures.Mesh`] List of meshes. """ use_local_file = False file_extension = _get_file_format(url) if self.local_cache_enabled: local_filename = self._local_mesh_filename(url) use_local_file = _cache_file_exists(local_filename) else: _, local_filename = tempfile.mkstemp(suffix='.' + file_extension, prefix='ros_fileserver_') if not use_local_file: service = roslibpy.Service(self.ros, '/file_server/get_file', 'file_server/GetBinaryFile') request = roslibpy.ServiceRequest(dict(name=url)) response = service.call(request, timeout=TIMEOUT) file_content = binascii.a2b_base64(response.data['value']) # Just look away, we're about to do something nasty! # namespaces are handled differently between the CLI and CPython # XML parsers, so, we just get rid of it for DAE files if file_extension == 'dae': file_content = file_content.replace(b'xmlns="http://www.collada.org/2005/11/COLLADASchema"', b'') file_content = file_content.replace(b'xmlns="https://www.collada.org/2005/11/COLLADASchema"', b'') # compas.files does not support file-like objects so we need to # save the file to disk always. If local caching is enabled, # we store it in the cache folder, otherwise, as a temp file. _write_file(local_filename, file_content, 'wb') else: # Nothing to do here, the file will be read by the mesh importer LOGGER.debug('Loading mesh file %s from local cache dir', local_filename) return _fileserver_mesh_import(url, local_filename, self.precision)
def _mesh_import(url, filename): """Internal function to load meshes using the correct loader. Name and file might be the same but not always, e.g. temp files.""" file_extension = _get_file_format(url) if file_extension not in SUPPORTED_FORMATS: raise NotImplementedError( 'Mesh type not supported: {}'.format(file_extension)) print(filename) if file_extension == "dae": # no dae support yet #mesh = Mesh.from_dae(filename) obj_filename = filename.replace(".dae", ".obj") if os.path.isfile(obj_filename): mesh = Mesh.from_obj(obj_filename) # former DAE files have yaxis and zaxis swapped # TODO: already fix in conversion to obj frame = Frame([0,0,0], [1,0,0], [0,0,1]) T = Transformation.from_frame(frame) mesh_transform(mesh, T) return mesh else: raise FileNotFoundError("Please convert '%s' into an OBJ file, \ since DAE is currently not supported \ yet." % filename) if file_extension == 'obj': return Mesh.from_obj(filename) elif file_extension == 'stl': return Mesh.from_stl(filename) elif file_extension == 'ply': return Mesh.from_ply(filename) raise Exception