Skip to content

Commit f874abf

Browse files
Libero0809Kashu7100
authored andcommitted
[FEATURE] Enhance SAP coupler for coupling between Rigid body and Fem object. (Genesis-Embodied-AI#1458)
1 parent 7c40e18 commit f874abf

File tree

9 files changed

+1783
-558
lines changed

9 files changed

+1783
-558
lines changed

genesis/engine/bvh.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ def _kernel_radix_sort_morton_codes_one_round(self, i: int):
281281

282282
# Reorder morton codes
283283
for i_b, i_a in ti.ndrange(self.n_batches, self.n_aabbs):
284-
code = (self.morton_codes[i_b, i_a][1 - (i // 4)] >> ((i % 4) * 8)) & 0xFF
285-
idx = ti.i32(self.offset[i_b, i_a] + self.prefix_sum[i_b, ti.i32(code)])
284+
code = ti.i32((self.morton_codes[i_b, i_a][1 - (i // 4)] >> ((i % 4) * 8)) & 0xFF)
285+
idx = ti.i32(self.offset[i_b, i_a] + self.prefix_sum[i_b, code])
286286
self.tmp_morton_codes[i_b, idx] = self.morton_codes[i_b, i_a]
287287

288288
# Swap the temporary and original morton codes
@@ -445,14 +445,15 @@ def _kernel_compute_bounds_one_layer(self) -> ti.i32:
445445

446446
return is_done
447447

448-
@ti.kernel
448+
@ti.func
449449
def query(self, aabbs: ti.template()):
450450
"""
451451
Query the BVH for intersections with the given AABBs.
452452
453453
The results are stored in the query_result field.
454454
"""
455455
self.query_result_count[None] = 0
456+
overflow = False
456457

457458
n_querys = aabbs.shape[1]
458459
for i_b, i_q in ti.ndrange(self.n_batches, n_querys):
@@ -474,6 +475,8 @@ def query(self, aabbs: ti.template()):
474475
idx = ti.atomic_add(self.query_result_count[None], 1)
475476
if idx < self.max_n_query_results:
476477
self.query_result[idx] = gs.ti_ivec3(i_b, i_a, i_q) # Store the AABB index
478+
else:
479+
overflow = True
477480
else:
478481
# Push children onto the stack
479482
if node.right != -1:
@@ -483,6 +486,8 @@ def query(self, aabbs: ti.template()):
483486
query_stack[stack_depth] = node.left
484487
stack_depth += 1
485488

489+
return overflow
490+
486491

487492
@ti.data_oriented
488493
class FEMSurfaceTetLBVH(LBVH):
@@ -503,10 +508,13 @@ def filter(self, i_a, i_q):
503508
504509
This is used to avoid self-collisions in FEM surface tets.
505510
506-
i_a: index of the found AABB
507-
i_q: index of the query AABB
511+
Parameters
512+
----------
513+
i_a:
514+
index of the found AABB
515+
i_q:
516+
index of the query AABB
508517
"""
509-
510518
result = i_a >= i_q
511519
i_av = self.fem_solver.elements_i[self.fem_solver.surface_elements[i_a]].el2v
512520
i_qv = self.fem_solver.elements_i[self.fem_solver.surface_elements[i_q]].el2v

0 commit comments

Comments
 (0)