@@ -613,12 +613,12 @@ def _func_contact_mpr_terrain(self, i_ga, i_gb, i_b):
613613 r_max = ti .min (self ._solver .terrain_rc [0 ] - 1 , r_max )
614614 c_max = ti .min (self ._solver .terrain_rc [1 ] - 1 , c_max )
615615
616- cnt = 0
616+ n_con = 0
617617 for r in range (r_min , r_max ):
618618 nvert = 0
619619 for c in range (c_min , c_max + 1 ):
620620 for i in range (2 ):
621- if cnt < self ._n_contacts_per_pair :
621+ if n_con < ti . static ( self ._n_contacts_per_pair ) :
622622 nvert = nvert + 1
623623 self .add_prism_vert (
624624 sh * (r + i ) + self ._solver .terrain_xyz_maxmin [3 ],
@@ -651,17 +651,17 @@ def _func_contact_mpr_terrain(self, i_ga, i_gb, i_b):
651651 contact_pos = contact_pos + gb_pos
652652
653653 valid = True
654- i_col = self .n_contacts [i_b ]
655- for j in range (cnt ):
654+ i_c = self .n_contacts [i_b ]
655+ for j in range (n_con ):
656656 if (
657- contact_pos - self .contact_data [i_col - j - 1 , i_b ].pos
657+ contact_pos - self .contact_data [i_c - j - 1 , i_b ].pos
658658 ).norm () < tolerance :
659659 valid = False
660660 break
661661
662662 if valid :
663663 self ._func_add_contact (i_ga , i_gb , normal , contact_pos , penetration , i_b )
664- cnt = cnt + 1
664+ n_con = n_con + 1
665665
666666 self ._solver .geoms_state [i_ga , i_b ].pos , self ._solver .geoms_state [i_ga , i_b ].quat = ga_pos , ga_quat
667667 self ._solver .geoms_state [i_gb , i_b ].pos , self ._solver .geoms_state [i_gb , i_b ].quat = gb_pos , gb_quat
@@ -787,12 +787,13 @@ def _func_broad_phase(self):
787787 self .contact_cache [i_ga , i_gb , i_b ].normal .fill (0.0 )
788788 continue
789789
790- if self .n_broad_pairs [i_b ] == self ._max_collision_pairs :
790+ i_p = self .n_broad_pairs [i_b ]
791+ if i_p == self ._max_collision_pairs :
791792 # print(self._warn_msg_max_collision_pairs)
792793 break
793- self .broad_collision_pairs [self . n_broad_pairs [ i_b ] , i_b ][0 ] = i_ga
794- self .broad_collision_pairs [self . n_broad_pairs [ i_b ] , i_b ][1 ] = i_gb
795- self .n_broad_pairs [i_b ] = self . n_broad_pairs [ i_b ] + 1
794+ self .broad_collision_pairs [i_p , i_b ][0 ] = i_ga
795+ self .broad_collision_pairs [i_p , i_b ][1 ] = i_gb
796+ self .n_broad_pairs [i_b ] += 1
796797
797798 self .active_buffer [n_active , i_b ] = self .sort_buffer [i , i_b ].i_g
798799 n_active = n_active + 1
@@ -1058,9 +1059,9 @@ def _func_narrow_phase_nonconvex_vs_nonterrain(self):
10581059
10591060 # Discard contact point is repeated
10601061 repeated = False
1061- for i_con in range (n_con ):
1062+ for i_c in range (n_con ):
10621063 if not repeated :
1063- idx_prev = self .n_contacts [i_b ] - 1 - i_con
1064+ idx_prev = self .n_contacts [i_b ] - 1 - i_c
10641065 prev_contact = self .contact_data [idx_prev , i_b ].pos
10651066 if (contact_pos - prev_contact ).norm () < tolerance :
10661067 repeated = True
@@ -1106,7 +1107,7 @@ def _func_plane_box_contact(self, i_ga, i_gb, i_b):
11061107 contact_pos_0 = contact_pos
11071108 tolerance = self ._func_compute_tolerance (i_ga , i_gb , i_b )
11081109 for i_v in range (gb_info .vert_start , gb_info .vert_end ):
1109- if n_con < self ._n_contacts_per_pair :
1110+ if n_con < ti . static ( self ._n_contacts_per_pair ) :
11101111 pos_corner = gu .ti_transform_by_trans_quat (
11111112 self ._solver .verts_info [i_v ].init_pos , gb_state .pos , gb_state .quat
11121113 )
@@ -1119,10 +1120,8 @@ def _func_plane_box_contact(self, i_ga, i_gb, i_b):
11191120
11201121 @ti .func
11211122 def _func_add_contact (self , i_ga , i_gb , normal , contact_pos , penetration , i_b ):
1122- # print(f"Adding contact {i_ga} {i_gb}, normal:", normal, "contact_pos:", contact_pos, "penetration:", penetration)
1123- i_col = self .n_contacts [i_b ]
1124-
1125- if i_col == self ._max_contact_pairs :
1123+ i_c = self .n_contacts [i_b ]
1124+ if i_c == self ._max_contact_pairs :
11261125 # FIXME: 'ti.static_print' cannot be used as it will be printed systematically, completely ignoring guard
11271126 # condition, while 'print' is slowing down the kernel even if every called in practice...
11281127 # print(self._warn_msg_max_collision_pairs)
@@ -1135,17 +1134,17 @@ def _func_add_contact(self, i_ga, i_gb, normal, contact_pos, penetration, i_b):
11351134 friction_b = gb_info .friction * self ._solver .geoms_state [i_gb , i_b ].friction_ratio
11361135
11371136 # b to a
1138- self .contact_data [i_col , i_b ].geom_a = i_ga
1139- self .contact_data [i_col , i_b ].geom_b = i_gb
1140- self .contact_data [i_col , i_b ].normal = normal
1141- self .contact_data [i_col , i_b ].pos = contact_pos
1142- self .contact_data [i_col , i_b ].penetration = penetration
1143- self .contact_data [i_col , i_b ].friction = ti .max (ti .max (friction_a , friction_b ), 1e-2 )
1144- self .contact_data [i_col , i_b ].sol_params = 0.5 * (ga_info .sol_params + gb_info .sol_params )
1145- self .contact_data [i_col , i_b ].link_a = ga_info .link_idx
1146- self .contact_data [i_col , i_b ].link_b = gb_info .link_idx
1147-
1148- self .n_contacts [i_b ] = i_col + 1
1137+ self .contact_data [i_c , i_b ].geom_a = i_ga
1138+ self .contact_data [i_c , i_b ].geom_b = i_gb
1139+ self .contact_data [i_c , i_b ].normal = normal
1140+ self .contact_data [i_c , i_b ].pos = contact_pos
1141+ self .contact_data [i_c , i_b ].penetration = penetration
1142+ self .contact_data [i_c , i_b ].friction = ti .max (ti .max (friction_a , friction_b ), 1e-2 )
1143+ self .contact_data [i_c , i_b ].sol_params = 0.5 * (ga_info .sol_params + gb_info .sol_params )
1144+ self .contact_data [i_c , i_b ].link_a = ga_info .link_idx
1145+ self .contact_data [i_c , i_b ].link_b = gb_info .link_idx
1146+
1147+ self .n_contacts [i_b ] = i_c + 1
11491148
11501149 @ti .func
11511150 def _func_compute_tolerance (self , i_ga , i_gb , i_b ):
@@ -1325,7 +1324,7 @@ def _func_convex_convex_contact(self, i_ga, i_gb, i_b):
13251324 # add the discovered contact points and stop multi-contact search.
13261325 for i_c in range (n_contacts ):
13271326 # Ignore contact points if the number of contacts exceeds the limit.
1328- if i_c < self ._n_contacts_per_pair :
1327+ if i_c < ti . static ( self ._n_contacts_per_pair ) :
13291328 contact_pos = self ._gjk .contact_pos [i_b , i_c ]
13301329 normal = self ._gjk .normal [i_b , i_c ]
13311330 self ._func_add_contact (i_ga , i_gb , normal , contact_pos , penetration , i_b )
@@ -1453,9 +1452,9 @@ def _func_convex_convex_contact(self, i_ga, i_gb, i_b):
14531452
14541453 # Discard contact point is repeated
14551454 repeated = False
1456- for i_con in range (n_con ):
1455+ for i_c in range (n_con ):
14571456 if not repeated :
1458- idx_prev = self .n_contacts [i_b ] - 1 - i_con
1457+ idx_prev = self .n_contacts [i_b ] - 1 - i_c
14591458 prev_contact = self .contact_data [idx_prev , i_b ].pos
14601459 if (contact_pos - prev_contact ).norm () < tolerance :
14611460 repeated = True
0 commit comments