From ac0fea96df7da3fc08e51d95f23c4c85327fd164 Mon Sep 17 00:00:00 2001 From: Eric Vin Date: Fri, 12 Jan 2024 20:42:51 -0800 Subject: [PATCH] Removed redundant mesh loading code. --- src/scenic/core/regions.py | 8 +++----- src/scenic/core/shapes.py | 8 +++----- src/scenic/core/utils.py | 38 -------------------------------------- tests/core/test_utils.py | 10 ++-------- 4 files changed, 8 insertions(+), 56 deletions(-) diff --git a/src/scenic/core/regions.py b/src/scenic/core/regions.py index c3954543e..d758e386f 100644 --- a/src/scenic/core/regions.py +++ b/src/scenic/core/regions.py @@ -56,7 +56,7 @@ ) from scenic.core.lazy_eval import isLazy, valueInContext from scenic.core.type_support import toOrientation, toScalar, toVector -from scenic.core.utils import cached, cached_method, cached_property, loadMesh, unifyMesh +from scenic.core.utils import cached, cached_method, cached_property, unifyMesh from scenic.core.vectors import ( Orientation, OrientedVector, @@ -848,9 +848,7 @@ def __init__( self.orientation = orientation @classmethod - def fromFile( - cls, path, filetype=None, compressed=None, binary=False, unify=True, **kwargs - ): + def fromFile(cls, path, unify=True, **kwargs): """Load a mesh region from a file, attempting to infer filetype and compression. For example: "foo.obj.bz2" is assumed to be a compressed .obj file. @@ -867,7 +865,7 @@ def fromFile( unify (bool): Whether or not to attempt to unify this mesh. kwargs: Additional arguments to the MeshRegion initializer. """ - mesh = loadMesh(path, filetype, compressed, binary) + mesh = trimesh.load(path, force="mesh") if unify and issubclass(cls, MeshVolumeRegion): mesh = unifyMesh(mesh, verbose=True) diff --git a/src/scenic/core/shapes.py b/src/scenic/core/shapes.py index 8b01f36d1..2a57c1f37 100644 --- a/src/scenic/core/shapes.py +++ b/src/scenic/core/shapes.py @@ -11,7 +11,7 @@ ) from scenic.core.type_support import toOrientation -from scenic.core.utils import cached_property, loadMesh, unifyMesh +from scenic.core.utils import cached_property, unifyMesh from scenic.core.vectors import Orientation ################################################################################################### @@ -122,9 +122,7 @@ def __init__(self, mesh, dimensions=None, scale=1, initial_rotation=None): super().__init__(dimensions, scale) @classmethod - def fromFile( - cls, path, filetype=None, compressed=None, binary=False, unify=True, **kwargs - ): + def fromFile(cls, path, unify=True, **kwargs): """Load a mesh shape from a file, attempting to infer filetype and compression. For example: "foo.obj.bz2" is assumed to be a compressed .obj file. @@ -141,7 +139,7 @@ def fromFile( unify (bool): Whether or not to attempt to unify this mesh. kwargs: Additional arguments to the MeshShape initializer. """ - mesh = loadMesh(path, filetype, compressed, binary) + mesh = trimesh.load(path, force="mesh") if not mesh.is_volume: raise ValueError( "A MeshShape cannot be defined with a mesh that does not have a well defined volume." diff --git a/src/scenic/core/utils.py b/src/scenic/core/utils.py index ce5333471..4549afdad 100644 --- a/src/scenic/core/utils.py +++ b/src/scenic/core/utils.py @@ -124,44 +124,6 @@ def alarm(seconds, handler=None, noNesting=False): signal.signal(signal.SIGALRM, signal.SIG_DFL) -def loadMesh(path, filetype, compressed, binary): - working_path = path - - if binary: - mode = "rb" - else: - mode = "r" - - # Check if file is compressed - if compressed is None: - root, ext = os.path.splitext(working_path) - - if ext == ".bz2": - compressed = True - working_path = root - else: - compressed = False - - # Check mesh filetype - if filetype is None: - root, ext = os.path.splitext(working_path) - - if ext == "": - raise ValueError("Mesh filetype not provided, but could not be extracted") - - filetype = ext - - if compressed: - open_function = bz2.open - else: - open_function = open - - with open_function(path, mode) as mesh_file: - mesh = trimesh.load(mesh_file, file_type=filetype, force="mesh") - - return mesh - - def unifyMesh(mesh, verbose=False): """Attempt to merge mesh bodies, raising a `ValueError` if something fails. diff --git a/tests/core/test_utils.py b/tests/core/test_utils.py index de2f8e6a7..370dc29b8 100644 --- a/tests/core/test_utils.py +++ b/tests/core/test_utils.py @@ -4,18 +4,12 @@ import pytest import trimesh -from scenic.core.utils import loadMesh, repairMesh, unifyMesh +from scenic.core.utils import repairMesh, unifyMesh @pytest.mark.slow def test_mesh_repair(getAssetPath): - plane_mesh = loadMesh( - path=getAssetPath("meshes/classic_plane.obj.bz2"), - filetype="obj", - compressed=True, - binary=False, - ) - + plane_mesh = trimesh.load(getAssetPath("meshes/classic_plane.obj.bz2"), force="mesh") # Test simple fix inverted_mesh = plane_mesh.copy() inverted_mesh.invert()