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

feat: meshrt in biomod #40

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion examples/biorbd/models/double_pendulum.bioMod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ segment Seg2
parent Seg1
rotations x
rtinmatrix 0
rt 0 0 0 xyz 0 0 -1
rt -0.1 0 0 xyz 0 0 -1
ranges
-pi/2 pi/2
mass 1
Expand All @@ -42,6 +42,7 @@ segment Seg2
0.0000 -0.0032 0.0090
com -0.0005 0.0688 -0.9542
meshfile mesh/pendulum.STL
meshrt 0.1 0 0 xyz 0 0 0
endsegment

// Marker 3
Expand Down
11 changes: 11 additions & 0 deletions pyorerun/biorbd_components/model_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,14 @@ def meshlines(self) -> list[np.ndarray]:
meshes += [np.array([segment_mesh.point(i).to_array() for i in range(segment_mesh.nbVertex())])]

return meshes

def mesh_homogenous_matrices_in_global(self, q: np.ndarray, segment_index: int) -> np.ndarray:
"""
Returns a list of homogeneous matrices of the mesh in the global reference frame
"""
mesh_rt = (
super(BiorbdModel, self).segments[segment_index].segment.characteristics().mesh().getRotation().to_array()
)
# mesh_rt = self.segments[segment_index].segment.characteristics().mesh().getRotation().to_array()
segment_rt = self.segment_homogeneous_matrices_in_global(q, segment_index=segment_index)
return segment_rt @ mesh_rt
6 changes: 5 additions & 1 deletion pyorerun/biorbd_components/model_updapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ def create_segments_updater(self):
)

if segment.has_mesh:
mesh = TransformableMeshUpdater.from_file(segment_name, segment.mesh_path, transform_callable)
mesh_transform_callable = partial(
self.model.mesh_homogenous_matrices_in_global,
segment_index=segment.id,
)
mesh = TransformableMeshUpdater.from_file(segment_name, segment.mesh_path, mesh_transform_callable)
mesh.set_transparency(self.model.options.transparent_mesh)
mesh.set_color(self.model.options.mesh_color)

Expand Down
Loading