Skip to content

Commit 81e91e6

Browse files
Kashu7100duburcqaYilingQiao
authored
[FEATURE] Add support of 'contype'/'conaffinity' for primitive and mesh entities. (#1438)
Co-authored-by: Alexis DUBURCQ <alexis.duburcq@gmail.com> Co-authored-by: YilingQiao <49262224+YilingQiao@users.noreply.github.com>
1 parent ec40996 commit 81e91e6

File tree

5 files changed

+390
-100
lines changed

5 files changed

+390
-100
lines changed

examples/collision/contype.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"""
2+
NOTE: contype and conaffinity are 32-bit integer bitmasks used for contact filtering of contact pairs.
3+
When the contype of one geom and the conaffinity of the other geom share a common bit set to 1, two geoms can collide.
4+
Plane: contype=0xFFFF, conaffinity=0xFFFF (1111 1111 1111 1111)
5+
Red Cube: contype=1, conaffinity=1 (0001) -> collide with Plane and Blue Cube
6+
Green Cube: contype=2, conaffinity=2 (0010) -> collide with Plane and Blue Cube
7+
Blue Cube: contype=3, conaffinity=3 (0011) -> collide with Plane, Red Cube, and Green Cube
8+
Dragon: contype=4, conaffinity=4 (0100) -> collide with Plane only
9+
"""
10+
11+
import argparse
12+
13+
import genesis as gs
14+
15+
16+
def main():
17+
parser = argparse.ArgumentParser()
18+
parser.add_argument("-v", "--vis", action="store_true", default=False)
19+
args = parser.parse_args()
20+
21+
gs.init()
22+
23+
scene = gs.Scene(
24+
viewer_options=gs.options.ViewerOptions(
25+
camera_pos=(0.0, -2, 1.5),
26+
camera_lookat=(0.0, 0.0, 0.5),
27+
camera_fov=40,
28+
max_FPS=200,
29+
),
30+
show_viewer=args.vis,
31+
)
32+
33+
scene.add_entity(gs.morphs.Plane())
34+
35+
scene.add_entity(
36+
gs.morphs.Box(
37+
pos=(0.025, 0, 0.5),
38+
quat=(0, 0, 0, 1),
39+
size=(0.1, 0.1, 0.1),
40+
contype=1,
41+
conaffinity=1,
42+
),
43+
surface=gs.surfaces.Default(
44+
color=(1.0, 0.0, 0.0, 1.0),
45+
),
46+
)
47+
scene.add_entity(
48+
gs.morphs.Box(
49+
pos=(-0.025, 0, 1.0),
50+
quat=(0, 0, 0, 1),
51+
size=(0.1, 0.1, 0.1),
52+
contype=2,
53+
conaffinity=2,
54+
),
55+
surface=gs.surfaces.Default(
56+
color=(0.0, 1.0, 0.0, 1.0),
57+
),
58+
)
59+
scene.add_entity(
60+
gs.morphs.Box(
61+
pos=(0.0, 0, 1.5),
62+
quat=(0, 0, 0, 1),
63+
size=(0.1, 0.1, 0.1),
64+
contype=3,
65+
conaffinity=3,
66+
),
67+
surface=gs.surfaces.Default(
68+
color=(0.0, 0.0, 1.0, 1.0),
69+
),
70+
)
71+
scene.add_entity(
72+
morph=gs.morphs.Mesh(
73+
file="meshes/dragon/dragon.obj",
74+
scale=0.004,
75+
euler=(0, 0, 90),
76+
pos=(-0.1, 0.0, 1.0),
77+
contype=4,
78+
conaffinity=4,
79+
),
80+
)
81+
82+
scene.build()
83+
84+
for i in range(1000):
85+
scene.step()
86+
87+
88+
if __name__ == "__main__":
89+
main()

genesis/engine/entities/rigid_entity/rigid_entity.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from genesis.utils import mjcf as mju
1818
from genesis.utils import terrain as tu
1919
from genesis.utils import urdf as uu
20-
from genesis.utils.misc import tensor_to_array, ti_field_to_torch, ALLOCATE_TENSOR_WARNING
20+
from genesis.utils.misc import ALLOCATE_TENSOR_WARNING, tensor_to_array, ti_field_to_torch
2121
from genesis.utils.path_planing import RRT, RRTConnect
2222

2323
from ..base_entity import Entity
@@ -169,8 +169,8 @@ def _load_primitive(self, morph, surface):
169169
if morph.collision:
170170
g_infos.append(
171171
dict(
172-
contype=1,
173-
conaffinity=1,
172+
contype=morph.contype,
173+
conaffinity=morph.conaffinity,
174174
mesh=gs.Mesh.from_trimesh(cmesh, surface=gs.surfaces.Collision()),
175175
type=geom_type,
176176
data=geom_data,
@@ -240,8 +240,8 @@ def _load_mesh(self, morph, surface):
240240
for mesh in meshes:
241241
g_infos.append(
242242
dict(
243-
contype=1,
244-
conaffinity=1,
243+
contype=morph.contype,
244+
conaffinity=morph.conaffinity,
245245
mesh=mesh,
246246
type=gs.GEOM_TYPE.MESH,
247247
sol_params=gu.default_solver_params(),

genesis/engine/solvers/rigid/collider_decomp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def _compute_collision_pair_validity(self):
197197
continue
198198

199199
# contype and conaffinity
200-
if links_entity_idx[i_la] == links_entity_idx[i_lb] and not (
200+
if not (
201201
(geoms_contype[i_ga] & geoms_conaffinity[i_gb]) or (geoms_contype[i_gb] & geoms_conaffinity[i_ga])
202202
):
203203
continue

0 commit comments

Comments
 (0)