Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for meshes to primitive builders #33

Merged
merged 15 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 3 additions & 5 deletions src/rod/builder/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def __post_init__(self) -> None:
"""

if isinstance(self.mesh_path, str):
extension = pathlib.PurePath(self.mesh_path).suffix
extension = self.mesh_path.split(".")[-1]
elif isinstance(self.mesh_path, pathlib.Path):
extension = self.mesh_path.suffix
extension = str(self.mesh_path).split(".")[-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last curiosity, any specific reason to go back to string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just not working without a suffix keyword for NamedTempFile. I can easily revert back.

else:
raise TypeError(
f"Expected str or pathlib.Path for mesh_path, got {type(self.mesh_path)}"
Expand All @@ -88,11 +88,9 @@ def __post_init__(self) -> None:
self.mesh: trimesh.base.Trimesh = trimesh.load(
str(self.mesh_path),
force="mesh",
file_type=extension.lstrip("."),
file_type=extension,
)

if not isinstance(self.scale, NDArray):
raise TypeError(f"Expected numpy.ndarray for scale, got {type(self.scale)}")
assert self.scale.shape == (
3,
), f"Scale must be a 3D vector, got {self.scale.shape}"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_meshbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_builder_creation():
mesh = trimesh.creation.box([1, 1, 1])

# Temporary write to file because rod Mesh works with uri
with tempfile.NamedTemporaryFile() as fp:
with tempfile.NamedTemporaryFile(suffix=".stl") as fp:
mesh.export(fp.name, file_type="stl")

builder = MeshBuilder(
Expand Down Expand Up @@ -40,7 +40,7 @@ def test_builder_creation_custom_mesh():
mesh = trimesh.Trimesh(vertices=vertices, faces=faces)

# Temporary write to file because rod Mesh works with uri
with tempfile.NamedTemporaryFile() as fp:
with tempfile.NamedTemporaryFile(suffix=".stl") as fp:
mesh.export(fp.name, file_type="stl")

builder = MeshBuilder(
Expand Down
Loading