Skip to content

Commit

Permalink
extension.lower()
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Nov 21, 2024
1 parent 3019b16 commit 1d07a45
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions trimesh/path/exchange/load.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,63 @@

from ... import util
from ...exchange.ply import load_ply
from ..path import Path
from ..typed import Optional
from . import misc
from .dxf import _dxf_loaders
from .svg_io import svg_to_path


def load_path(file_obj, file_type=None, **kwargs):
def load_path(file_obj, file_type: Optional[str] = None, **kwargs):
"""
Load a file to a Path file_object.
Parameters
-----------
file_obj : One of the following:
file_obj
Accepts many types:
- Path, Path2D, or Path3D file_objects
- open file file_object (dxf or svg)
- file name (dxf or svg)
- shapely.geometry.Polygon
- shapely.geometry.MultiLineString
- dict with kwargs for Path constructor
- (n,2,(2|3)) float, line segments
file_type : str
- `(n, 2, (2|3)) float` line segments
file_type
Type of file is required if file
file_object passed.
object is passed.
Returns
---------
path : Path, Path2D, Path3D file_object
Data as a native trimesh Path file_object
Data as a native trimesh Path file_object
"""
# avoid a circular import
from ...exchange.load import load_kwargs

if isinstance(file_type, str):
# get the file type from the extension
file_type = util.split_extension(file_type)
# we accept full file names here so make sure we
file_type = util.split_extension(file_type).lower()

# record how long we took
tic = util.now()


if isinstance(file_obj, Path):
# we have been passed a Path file_object so
# do nothing and return the passed file_object
# we have been passed a file object that is already a loaded
# trimesh.path.Path object so do nothing and return
return file_obj
elif util.is_file(file_obj):
# for open file file_objects use loaders
if file_type == "ply":
# we cannot register this exporter to path_loaders since this is already reserved by TriMesh in ply format in trimesh.load()
# we cannot register this exporter to path_loaders
# since this is already reserved for 3D values in `trimesh.load`
kwargs.update(load_ply(file_obj, file_type=file_type))
else:
kwargs.update(path_loaders[file_type](file_obj, file_type=file_type))
elif isinstance(file_obj, str):
# strings passed are evaluated as file file_objects
with open(file_obj, "rb") as f:
# get the file type from the extension
file_type = util.split_extension(file_obj)
file_type = util.split_extension(file_obj).lower()
if file_type == "ply":
# we cannot register this exporter to path_loaders since this is already reserved by TriMesh in ply format in trimesh.load()
kwargs.update(load_ply(f, file_type=file_type))
Expand Down

0 comments on commit 1d07a45

Please sign in to comment.