66import genesis as gs
77from genesis .options .solvers import LegacyCouplerOptions
88from genesis .repr_base import RBC
9+ import genesis .utils .sdf_decomp as sdf_decomp
910
1011if TYPE_CHECKING :
1112 from genesis .engine .simulator import Simulator
@@ -118,13 +119,28 @@ def _func_collide_with_rigid(self, f, pos_world, vel, mass, i_b):
118119
119120 @ti .func
120121 def _func_collide_with_rigid_geom (self , pos_world , vel , mass , geom_idx , batch_idx ):
121- signed_dist = self .rigid_solver .sdf .sdf_world (pos_world , geom_idx , batch_idx )
122+ signed_dist = sdf_decomp .sdf_func_world (
123+ geoms_state = self .rigid_solver .geoms_state ,
124+ geoms_info = self .rigid_solver .geoms_info ,
125+ sdf_info = self .rigid_solver .sdf ._sdf_info ,
126+ pos_world = pos_world ,
127+ geom_idx = geom_idx ,
128+ batch_idx = batch_idx ,
129+ )
122130
123131 # bigger coup_softness implies that the coupling influence extends further away from the object.
124132 influence = ti .min (ti .exp (- signed_dist / max (1e-10 , self .rigid_solver .geoms_info .coup_softness [geom_idx ])), 1 )
125133
126134 if influence > 0.1 :
127- normal_rigid = self .rigid_solver .sdf .sdf_normal_world (pos_world , geom_idx , batch_idx )
135+ normal_rigid = sdf_decomp .sdf_func_normal_world (
136+ geoms_state = self .rigid_solver .geoms_state ,
137+ geoms_info = self .rigid_solver .geoms_info ,
138+ collider_static_config = self .rigid_solver .collider ._collider_static_config ,
139+ sdf_info = self .rigid_solver .sdf ._sdf_info ,
140+ pos_world = pos_world ,
141+ geom_idx = geom_idx ,
142+ batch_idx = batch_idx ,
143+ )
128144 vel = self ._func_collide_in_rigid_geom (pos_world , vel , mass , normal_rigid , influence , geom_idx , batch_idx )
129145
130146 return vel
@@ -134,8 +150,23 @@ def _func_collide_with_rigid_geom_robust(self, pos_world, vel, mass, normal_prev
134150 """
135151 Similar to _func_collide_with_rigid_geom, but additionally handles potential side flip due to penetration.
136152 """
137- signed_dist = self .rigid_solver .sdf .sdf_world (pos_world , geom_idx , batch_idx )
138- normal_rigid = self .rigid_solver .sdf .sdf_normal_world (pos_world , geom_idx , batch_idx )
153+ signed_dist = sdf_decomp .sdf_func_world (
154+ geoms_state = self .rigid_solver .geoms_state ,
155+ geoms_info = self .rigid_solver .geoms_info ,
156+ sdf_info = self .rigid_solver .sdf ._sdf_info ,
157+ pos_world = pos_world ,
158+ geom_idx = geom_idx ,
159+ batch_idx = batch_idx ,
160+ )
161+ normal_rigid = sdf_decomp .sdf_func_normal_world (
162+ geoms_state = self .rigid_solver .geoms_state ,
163+ geoms_info = self .rigid_solver .geoms_info ,
164+ collider_static_config = self .rigid_solver .collider ._collider_static_config ,
165+ sdf_info = self .rigid_solver .sdf ._sdf_info ,
166+ pos_world = pos_world ,
167+ geom_idx = geom_idx ,
168+ batch_idx = batch_idx ,
169+ )
139170
140171 # bigger coup_softness implies that the coupling influence extends further away from the object.
141172 influence = ti .min (ti .exp (- signed_dist / max (1e-10 , self .rigid_solver .geoms_info .coup_softness [geom_idx ])), 1 )
@@ -159,7 +190,10 @@ def _func_collide_in_rigid_geom(self, pos_world, vel, mass, normal_rigid, influe
159190 This function assumes known normal_rigid and influence.
160191 """
161192 vel_rigid = self .rigid_solver ._func_vel_at_point (
162- pos_world , self .rigid_solver .geoms_info .link_idx [geom_idx ], batch_idx
193+ pos_world = pos_world ,
194+ link_idx = self .rigid_solver .geoms_info .link_idx [geom_idx ],
195+ i_b = batch_idx ,
196+ links_state = self .rigid_solver .links_state ,
163197 )
164198
165199 # v w.r.t rigid
@@ -198,7 +232,11 @@ def _func_collide_in_rigid_geom(self, pos_world, vel, mass, normal_rigid, influe
198232 delta_mv = mass * (vel - vel_old )
199233 force = - delta_mv / self .rigid_solver .substep_dt
200234 self .rigid_solver ._func_apply_external_force (
201- pos_world , force , self .rigid_solver .geoms_info .link_idx [geom_idx ], batch_idx
235+ pos_world ,
236+ force ,
237+ self .rigid_solver .geoms_info .link_idx [geom_idx ],
238+ batch_idx ,
239+ self .rigid_solver .links_state ,
202240 )
203241
204242 return vel
@@ -345,8 +383,14 @@ def mpm_surface_to_particle(self, f: ti.i32):
345383 if self .mpm_solver .particles_ng [f , i_p , i_b ].active :
346384 for i_g in range (self .rigid_solver .n_geoms ):
347385 if self .rigid_solver .geoms_info .needs_coup [i_g ]:
348- sdf_normal = self .rigid_solver .sdf .sdf_normal_world (
349- self .mpm_solver .particles [f , i_p , i_b ].pos , i_g , i_b
386+ sdf_normal = sdf_decomp .sdf_func_normal_world (
387+ geoms_state = self .rigid_solver .geoms_state ,
388+ geoms_info = self .rigid_solver .geoms_info ,
389+ collider_static_config = self .rigid_solver .collider ._collider_static_config ,
390+ sdf_info = self .rigid_solver .sdf ._sdf_info ,
391+ pos_world = self .mpm_solver .particles [f , i_p , i_b ].pos ,
392+ geom_idx = i_g ,
393+ batch_idx = i_b ,
350394 )
351395 # we only update the normal if the particle does not the object
352396 if sdf_normal .dot (self .mpm_rigid_normal [i_p , i_g , i_b ]) >= 0 :
@@ -553,11 +597,29 @@ def _func_pbd_collide_with_rigid_geom(self, i, pos_world, vel, mass, normal_prev
553597 Resolves collision when a particle is already in collision with a rigid object.
554598 This function assumes known normal_rigid and influence.
555599 """
556- signed_dist = self .rigid_solver .sdf .sdf_world (pos_world , geom_idx , batch_idx )
600+ signed_dist = sdf_decomp .sdf_func_world (
601+ geoms_state = self .rigid_solver .geoms_state ,
602+ geoms_info = self .rigid_solver .geoms_info ,
603+ sdf_info = self .rigid_solver .sdf ._sdf_info ,
604+ pos_world = pos_world ,
605+ geom_idx = geom_idx ,
606+ batch_idx = batch_idx ,
607+ )
557608 vel_rigid = self .rigid_solver ._func_vel_at_point (
558- pos_world , self .rigid_solver .geoms_info .link_idx [geom_idx ], batch_idx
609+ pos_world = pos_world ,
610+ link_idx = self .rigid_solver .geoms_info .link_idx [geom_idx ],
611+ i_b = batch_idx ,
612+ links_state = self .rigid_solver .links_state ,
613+ )
614+ normal_rigid = sdf_decomp .sdf_func_normal_world (
615+ geoms_state = self .rigid_solver .geoms_state ,
616+ geoms_info = self .rigid_solver .geoms_info ,
617+ collider_static_config = self .rigid_solver .collider ._collider_static_config ,
618+ sdf_info = self .rigid_solver .sdf ._sdf_info ,
619+ pos_world = pos_world ,
620+ geom_idx = geom_idx ,
621+ batch_idx = batch_idx ,
559622 )
560- normal_rigid = self .rigid_solver .sdf .sdf_normal_world (pos_world , geom_idx , batch_idx )
561623 new_pos = pos_world
562624 if signed_dist < self .pbd_solver .particle_size / 2 : # skip non-penetration particles
563625
@@ -583,7 +645,11 @@ def _func_pbd_collide_with_rigid_geom(self, i, pos_world, vel, mass, normal_prev
583645 force = (- delta_mv / self .rigid_solver ._substep_dt ) * (1 - energy_loss )
584646
585647 self .rigid_solver ._func_apply_external_force (
586- pos_world , force , self .rigid_solver .geoms_info .link_idx [geom_idx ], batch_idx
648+ pos_world ,
649+ force ,
650+ self .rigid_solver .geoms_info .link_idx [geom_idx ],
651+ batch_idx ,
652+ self .rigid_solver .links_state ,
587653 )
588654
589655 return new_pos , vel , normal_rigid
0 commit comments