Skip to content

Commit

Permalink
Removed redundant mesh loading code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Vin committed Jan 13, 2024
1 parent ed1aa72 commit ac0fea9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 56 deletions.
8 changes: 3 additions & 5 deletions src/scenic/core/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions src/scenic/core/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

###################################################################################################
Expand Down Expand Up @@ -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.
Expand All @@ -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."
Expand Down
38 changes: 0 additions & 38 deletions src/scenic/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 2 additions & 8 deletions tests/core/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ac0fea9

Please sign in to comment.