|
| 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() |
0 commit comments