Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* Moved private methods `_get_file_format` and `_mesh_import` to `compas_robots.resources` and made them public (`get_file_format` and `mesh_import`).

### Removed


Expand Down
4 changes: 4 additions & 0 deletions src/compas_robots/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from __future__ import absolute_import

from .mesh_importer import get_file_format
from .mesh_importer import mesh_import
from .basic import AbstractMeshLoader
from .basic import DefaultMeshLoader
from .basic import LocalPackageMeshLoader
from .github import GithubPackageMeshLoader

__all__ = [
"get_file_format",
"mesh_import",
"AbstractMeshLoader",
"DefaultMeshLoader",
"LocalPackageMeshLoader",
Expand Down
38 changes: 5 additions & 33 deletions src/compas_robots/resources/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
except ImportError:
from urlparse import urlparse

from compas.datastructures import Mesh

SUPPORTED_FORMATS = ("obj", "stl", "ply")
from .mesh_importer import mesh_import
from .mesh_importer import get_file_format


class AbstractMeshLoader(object):
Expand Down Expand Up @@ -94,7 +93,7 @@ def can_load_mesh(self, url):
return True

# Only OBJ loader supports remote files atm
is_obj = _get_file_format(url) == "obj"
is_obj = get_file_format(url) == "obj"
return scheme in ("http", "https") and is_obj

def load_meshes(self, url, precision=None):
Expand All @@ -115,7 +114,7 @@ def load_meshes(self, url, precision=None):
List of meshes.
"""
url = self._get_mesh_url(url)
return _mesh_import(url, url, precision)
return mesh_import(url, url, precision)

def _get_mesh_url(self, url):
"""Concatenates basepath directory to URL only if defined in the keyword arguments.
Expand All @@ -141,14 +140,6 @@ def _get_mesh_url(self, url):
return url


def _get_file_format(url):
# This could be much more elaborate
# with an actual header check
# and/or remote content-type check
file_extension = url.split(".")[-1].lower()
return file_extension


class LocalPackageMeshLoader(AbstractMeshLoader):
"""Loads suport package resources stored locally.

Expand Down Expand Up @@ -240,27 +231,8 @@ def load_meshes(self, url, precision=None):
List of meshes.
"""
local_file = self._get_local_path(url)
return _mesh_import(url, local_file, precision)
return mesh_import(url, local_file, precision)

def _get_local_path(self, url):
_prefix, path = url.split(self.schema_prefix)
return self.build_path(*path.split("/"))


def _mesh_import(name, file, precision=None):
"""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(name)

if file_extension not in SUPPORTED_FORMATS:
raise NotImplementedError("Mesh type not supported: {}".format(file_extension))

if file_extension == "obj":
return [Mesh.from_obj(file, precision)]
elif file_extension == "stl":
return [Mesh.from_stl(file, precision)]
elif file_extension == "ply":
return [Mesh.from_ply(file, precision)]

raise Exception
4 changes: 2 additions & 2 deletions src/compas_robots/resources/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from urllib2 import urlopen

from .basic import AbstractMeshLoader
from .basic import _mesh_import
from .mesh_importer import mesh_import


class GithubPackageMeshLoader(AbstractMeshLoader):
Expand Down Expand Up @@ -112,4 +112,4 @@ def load_meshes(self, url, precision=None):
_prefix, path = url.split(self.schema_prefix)
url = self.build_url(path)

return _mesh_import(url, url, precision)
return mesh_import(url, url, precision)
30 changes: 30 additions & 0 deletions src/compas_robots/resources/mesh_importer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from compas.datastructures import Mesh

SUPPORTED_FORMATS = ("obj", "stl", "ply")


def get_file_format(url):
# This could be much more elaborate
# with an actual header check
# and/or remote content-type check
file_extension = url.split(".")[-1].lower()
return file_extension


def mesh_import(name, file, precision=None):
"""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(name)

if file_extension not in SUPPORTED_FORMATS:
raise NotImplementedError("Mesh type not supported: {}".format(file_extension))

if file_extension == "obj":
return [Mesh.from_obj(file, precision)]
elif file_extension == "stl":
return [Mesh.from_stl(file, precision)]
elif file_extension == "ply":
return [Mesh.from_ply(file, precision)]

raise Exception