-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for meshes to primitive builders #33
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
27ad953
Added trimesh to depencencies
8acc9cd
Implemented MeshBuilder class, plus its inertia and geometry overrides
16e652c
Implemented 2 tests on meshbuilder
f10a04c
Run isort on meshbuilder tests
91f2332
Updated conda dependencies on github actions with trimesh
38a1a5c
Updated scale type hinting to numpy NDArray
7113789
Updated test on meshbuilder to use tempfile rather than creating file…
22b9816
Forced mesh type to be .stl on mesh load
1fbf07f
Added docstring to meshbuilder and reformatted affected files
d1d73f6
Added tempfile inside context for other meshbuilder test
07789d3
Added tempfile inside context for other meshbuilder test
e00ee38
Added extra type checks and extension parsig on mesh path
f4bffde
Removed leftover comments
fdc1fec
Added type checks on mesh file type
17d5028
Reverted extension extraction to usage of pathlib
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import os | ||
| import pathlib | ||
| import tempfile | ||
|
|
||
| import numpy as np | ||
| import trimesh | ||
|
|
||
| from rod.builder.primitives import MeshBuilder | ||
|
|
||
|
|
||
| def test_builder_creation(): | ||
| mesh = trimesh.creation.box([1, 1, 1]) | ||
|
|
||
| # Temporary write to file because rod Mesh works with uri | ||
| with tempfile.NamedTemporaryFile(suffix=".stl") as fp: | ||
| mesh.export(fp.name, file_type="stl") | ||
|
|
||
| builder = MeshBuilder( | ||
| name="test_mesh", | ||
| mesh_path=fp.name, | ||
| mass=1.0, | ||
| scale=np.array([1.0, 1.0, 1.0]), | ||
| ) | ||
| assert ( | ||
| builder.mesh.vertices.shape == mesh.vertices.shape | ||
| ), f"{builder.mesh.vertices.shape} != {mesh.vertices.shape}" | ||
| assert ( | ||
| builder.mesh.faces.shape == mesh.faces.shape | ||
| ), f"{builder.mesh.faces.shape} != {mesh.faces.shape}" | ||
| assert ( | ||
| builder.mesh.moment_inertia.all() == mesh.moment_inertia.all() | ||
| ), f"{builder.mesh.moment_inertia} != {mesh.moment_inertia}" | ||
| assert builder.mesh.volume == mesh.volume, f"{builder.mesh.volume} != {mesh.volume}" | ||
|
|
||
|
|
||
| def test_builder_creation_custom_mesh(): | ||
| # Create a custom mesh | ||
| vertices = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]]) | ||
| faces = np.array([[0, 1, 2], [0, 2, 3]]) | ||
| mesh = trimesh.Trimesh(vertices=vertices, faces=faces) | ||
|
|
||
| # Temporary write to file because rod Mesh works with uri | ||
| with tempfile.NamedTemporaryFile(suffix=".stl") as fp: | ||
| mesh.export(fp.name, file_type="stl") | ||
|
|
||
| builder = MeshBuilder( | ||
| name="test_mesh", | ||
| mesh_path=fp.name, | ||
| mass=1.0, | ||
| scale=np.array([1.0, 1.0, 1.0]), | ||
| ) | ||
| assert ( | ||
| builder.mesh.vertices.shape == mesh.vertices.shape | ||
| ), f"{builder.mesh.vertices.shape} != {mesh.vertices.shape}" | ||
| assert ( | ||
| builder.mesh.faces.shape == mesh.faces.shape | ||
| ), f"{builder.mesh.faces.shape} != {mesh.faces.shape}" | ||
| assert ( | ||
| builder.mesh.moment_inertia.all() == mesh.moment_inertia.all() | ||
| ), f"{builder.mesh.moment_inertia} != {mesh.moment_inertia}" | ||
| assert builder.mesh.volume == mesh.volume, f"{builder.mesh.volume} != {mesh.volume}" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.