@@ -86,7 +86,7 @@ def sdf(self, f, pos_world, i_b):
8686 def sdf_ (self , pos_voxels ):
8787 # sdf value from voxels coordinate
8888 base = ti .floor (pos_voxels , gs .ti_int )
89- signed_dist = ti . cast (0.0 , gs . ti_float )
89+ signed_dist = gs . ti_float (0.0 )
9090 if (base >= self .sdf_res - 1 ).any () or (base < 0 ).any ():
9191 signed_dist = 1.0
9292 else :
@@ -117,7 +117,7 @@ def normal(self, f, pos_world, i_b):
117117 @ti .func
118118 def normal_ (self , pos_voxels ):
119119 # since we are in voxels frame, delta can be a relatively big value
120- delta = ti . cast (1e-2 , gs . ti_float )
120+ delta = gs . ti_float (1e-2 )
121121 normal_vec = ti .Vector ([0 , 0 , 0 ], dt = gs .ti_float )
122122
123123 for i in ti .static (range (3 )):
@@ -146,15 +146,15 @@ def collide(self, f, pos_world, vel_mat, i_b):
146146 signed_dist = self .sdf (f , pos_world , i_b )
147147 # bigger coup_softness implies that the coupling influence extends further away from the object.
148148 influence = ti .min (ti .exp (- signed_dist / max (gs .EPS , self .material .coup_softness )), 1 )
149- if signed_dist <= 0 or influence > 0.1 :
149+ if signed_dist <= 0.0 or influence > 0.1 :
150150 vel_collider = self .vel_collider (f , pos_world , i_b )
151151
152152 # v w.r.t collider
153153 rel_v = vel_mat - vel_collider
154154 normal_vec = self .normal (f , pos_world , i_b )
155155 normal_component = rel_v .dot (normal_vec )
156156
157- if normal_component < 0 :
157+ if normal_component < 0.0 :
158158 # remove inward velocity
159159 rel_v_t = rel_v - normal_component * normal_vec
160160 rel_v_t_norm = rel_v_t .norm (gs .EPS )
@@ -165,9 +165,10 @@ def collide(self, f, pos_world, vel_mat, i_b):
165165 )
166166
167167 # tangential component after friction
168- flag = ti .cast (normal_component < 0 , gs .ti_float )
169- rel_v_t = rel_v_t_friction * flag + rel_v_t * (1 - flag )
170- vel_mat = vel_collider + rel_v_t * influence + rel_v * (1 - influence )
168+ # FIXME: This formula could be simplified since flag = 1.0 systematically.
169+ flag = ti .cast (normal_component < 0.0 , gs .ti_float )
170+ rel_v_t = rel_v_t_friction * flag + rel_v_t * (1.0 - flag )
171+ vel_mat = vel_collider + rel_v_t * influence + rel_v * (1.0 - influence )
171172
172173 return vel_mat
173174
0 commit comments