11from __future__ import annotations
22
33import dataclasses
4- import itertools
54from collections .abc import Sequence
65
76from jaxsim import logging
@@ -26,9 +25,7 @@ class ModelDescription(KinematicGraph):
2625
2726 fixed_base : bool = True
2827
29- collision_shapes : tuple = dataclasses .field (
30- default_factory = list , repr = False
31- )
28+ collision_shapes : tuple = dataclasses .field (default_factory = list , repr = False )
3229
3330 @staticmethod
3431 def build_model_from (
@@ -101,31 +98,33 @@ def build_model_from(
10198 logging .info (msg .format (parent_link_of_shape ))
10299 continue
103100
104- # Create a new collision shape
105- # new_collision_shape = CollisionShape(collidable_points=())
106- # final_collisions.append(new_collision_shape)
107-
108- # # If the frame was found, update the collidable points' pose and add them
109- # # to the new collision shape.
110- # for cp in collision_shape.collidable_points:
111- # # Find the link that is part of the (reduced) model in which the
112- # # collision shape's parent was lumped into
113- # real_parent_link_name = kinematic_graph.frames_dict[
114- # parent_link_of_shape.name
115- # ].parent_name
116-
117- # # Change the link associated to the collidable point, updating their
118- # # relative pose
119- # moved_cp = cp.change_link(
120- # new_link=kinematic_graph.links_dict[real_parent_link_name],
121- # new_H_old=fk.relative_transform(
122- # relative_to=real_parent_link_name,
123- # name=cp.parent_link.name,
124- # ),
125- # )
126-
127- # # Store the updated collision.
128- # new_collision_shape.collidable_points += (moved_cp,)
101+ # Find the link that is part of the (reduced) model in which the
102+ # collision shape's parent was lumped into.
103+ real_parent_link_name = kinematic_graph .frames_dict [
104+ parent_link_of_shape
105+ ].parent_name
106+
107+ # Get the transform from the real parent link to the removed link
108+ # that still exists as a frame.
109+ parent_H_frame = fk .relative_transform (
110+ relative_to = real_parent_link_name ,
111+ name = parent_link_of_shape ,
112+ )
113+
114+ # Transform the collision shape's pose to the new parent link frame.
115+ # The collision shape was defined w.r.t. the removed link (now a frame).
116+ # Now we need to express it w.r.t. the link that absorbed the removed link.
117+ # Compose the transforms: parent_H_shape = parent_H_frame @ frame_H_shape
118+ parent_H_shape = parent_H_frame @ collision_shape .transform
119+
120+ # Create a new collision shape with updated pose and parent link
121+ new_collision_shape = dataclasses .replace (
122+ collision_shape ,
123+ transform = parent_H_shape ,
124+ parent_link = real_parent_link_name ,
125+ )
126+
127+ final_collisions .append (new_collision_shape )
129128
130129 # Build the model
131130 model = ModelDescription (
0 commit comments