Skip to content

Commit 5ac338c

Browse files
committed
modify mpr threshold
1 parent 6622ef7 commit 5ac338c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

genesis/engine/solvers/rigid/mpr_decomp.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ def __init__(self, rigid_solver):
1616
self._B = rigid_solver._B
1717
self._para_level = rigid_solver._para_level
1818

19+
if gs.ti_float == ti.f32:
20+
self.CCD_EPS = 1e-6
21+
else:
22+
self.CCD_EPS = 1e-10
23+
1924
self.support_field = SupportField(rigid_solver)
2025
self.init_support()
2126

@@ -150,7 +155,6 @@ def mpr_portal_dir(self, i_ga, i_gb, i_b):
150155
def mpr_portal_encapsules_origin(self, direction, i_ga, i_gb, i_b):
151156
dot = direction.dot(self.simplex_support[i_ga, i_gb, 1, i_b].v)
152157

153-
CCD_EPS = 1e-5
154158
return dot > 0.0
155159
# return dot > 0 or ti.abs(dot) < CCD_EPS
156160

@@ -418,7 +422,6 @@ def mpr_expand_portal(self, v, v1, v2, i_ga, i_gb, i_b):
418422

419423
@ti.func
420424
def mpr_discover_portal(self, i_ga, i_gb, i_b):
421-
CCD_EPS = 1e-5
422425
ret = 0
423426
self.simplex_size[i_ga, i_gb, i_b] = 0
424427

@@ -436,8 +439,8 @@ def mpr_discover_portal(self, i_ga, i_gb, i_b):
436439
self.simplex_support[i_ga, i_gb, 0, i_b].v = center_a - center_b
437440
self.simplex_size[i_ga, i_gb, i_b] = 1
438441

439-
if self.simplex_support[i_ga, i_gb, 0, i_b].v.norm() < CCD_EPS:
440-
self.simplex_support[i_ga, i_gb, 0, i_b].v += gs.ti_vec3([10.0 * CCD_EPS, 0.0, 0.0])
442+
if self.simplex_support[i_ga, i_gb, 0, i_b].v.norm() < self.CCD_EPS:
443+
self.simplex_support[i_ga, i_gb, 0, i_b].v += gs.ti_vec3([10.0 * self.CCD_EPS, 0.0, 0.0])
441444

442445
direction = (self.simplex_support[i_ga, i_gb, 0, i_b].v * -1).normalized()
443446

@@ -451,13 +454,13 @@ def mpr_discover_portal(self, i_ga, i_gb, i_b):
451454
dot = v.dot(direction)
452455

453456
# if dot < 0 or ti.abs(dot) < CCD_EPS:
454-
if dot < CCD_EPS:
457+
if dot < self.CCD_EPS:
455458
ret = -1
456459
else:
457460
direction = self.simplex_support[i_ga, i_gb, 0, i_b].v.cross(self.simplex_support[i_ga, i_gb, 1, i_b].v)
458-
if direction.norm() < CCD_EPS:
461+
if direction.norm() < self.CCD_EPS:
459462
# if portal.points[1].v == ccd_vec3_origin:
460-
if self.simplex_support[i_ga, i_gb, 1, i_b].v.norm() < CCD_EPS:
463+
if self.simplex_support[i_ga, i_gb, 1, i_b].v.norm() < self.CCD_EPS:
461464
ret = 1
462465
else:
463466
ret = 2
@@ -466,7 +469,7 @@ def mpr_discover_portal(self, i_ga, i_gb, i_b):
466469
v, v1, v2 = self.compute_support(direction, i_ga, i_gb, i_b)
467470
dot = v.dot(direction)
468471
# if dot < 0 or ti.abs(dot) < CCD_EPS:
469-
if dot < CCD_EPS:
472+
if dot < self.CCD_EPS:
470473
ret = -1
471474
else:
472475
self.simplex_support[i_ga, i_gb, 2, i_b].v1 = v1
@@ -488,7 +491,7 @@ def mpr_discover_portal(self, i_ga, i_gb, i_b):
488491
v, v1, v2 = self.compute_support(direction, i_ga, i_gb, i_b)
489492
dot = v.dot(direction)
490493
# if dot < 0 or ti.abs(dot) < CCD_EPS:
491-
if dot < CCD_EPS:
494+
if dot < self.CCD_EPS:
492495
ret = -1
493496
break
494497

@@ -497,7 +500,7 @@ def mpr_discover_portal(self, i_ga, i_gb, i_b):
497500
va = self.simplex_support[i_ga, i_gb, 1, i_b].v.cross(v)
498501
dot = va.dot(self.simplex_support[i_ga, i_gb, 0, i_b].v)
499502
# if dot < 0 or ti.abs(dot) < CCD_EPS:
500-
if dot < -CCD_EPS:
503+
if dot < -self.CCD_EPS:
501504
self.simplex_support[i_ga, i_gb, 2, i_b].v1 = v1
502505
self.simplex_support[i_ga, i_gb, 2, i_b].v2 = v2
503506
self.simplex_support[i_ga, i_gb, 2, i_b].v = v
@@ -507,7 +510,7 @@ def mpr_discover_portal(self, i_ga, i_gb, i_b):
507510
va = v.cross(self.simplex_support[i_ga, i_gb, 2, i_b].v)
508511
dot = va.dot(self.simplex_support[i_ga, i_gb, 0, i_b].v)
509512
# if dot < 0 or ti.abs(dot) < CCD_EPS:
510-
if dot < -CCD_EPS:
513+
if dot < -self.CCD_EPS:
511514
self.simplex_support[i_ga, i_gb, 1, i_b].v1 = v1
512515
self.simplex_support[i_ga, i_gb, 1, i_b].v2 = v2
513516
self.simplex_support[i_ga, i_gb, 1, i_b].v = v

0 commit comments

Comments
 (0)