google-deepmind / mujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.
https://mujoco.org
Apache License 2.0
8.25k stars 823 forks source link

Non-convex mesh collision detection does not work as expected #2192

Closed JewelryForge closed 3 weeks ago

JewelryForge commented 3 weeks ago

Intro

Hi!

I am a graduate student and I use MuJoCo for my research on legged locomotion.

I'm trying to use mesh to generate various terrains. I use simulate to test the following model file, with a mesh and multiple free boxes to test collision detections. It's expected that all boxes will finally stop on the surface of the terrain. However, all boxes seem to stop on the bounding box of the mesh. I have checked MuJoCo's documents and found that it supports non-convex mesh for collision detection. So, the simulation result seems to be wrong.

I have tried to set nativeccd to true or set convexhull to false. All options produce the same results.

My setup

MuJoCo 3.2.4

What's happening? What did you expect?

https://github.com/user-attachments/assets/585e4db8-ae8d-473b-b22c-cad37a641cf1

Steps for reproduction

Simulate the following model file.

Minimal model for reproduction

<mujoco model="test_mesh">
  <compiler angle="radian" autolimits="true"/>
  <asset>
    <material name="white" rgba="1 1 1 1"/>
    <mesh name="terrain" vertex="
        -4 -2.5  0
        -4  2.5  0
        -2 -2.5  0
        -2  2.5  0
        -2 -2.5 -1
        -2  2.5 -1
        -1 -2.5 -1
        -1  2.5 -1
        -1 -2.5  0
        -1  2.5  0
         1 -2.5  0
         1  2.5  0
         1 -2.5 -1
         1  2.5 -1
         2 -2.5 -1
         2  2.5 -1
         2 -2.5  0
         2  2.5  0
         4 -2.5  0
         4  2.5  0
         4 -2.5 -1
         4  2.5 -1
    " face="
         0  2  1
         1  2  3
         2  4  3
         3  4  5
         4  6  5
         5  6  7
         6  8  7
         7  8  9
         8 10  9
         9 10 11
        10 12 11
        11 12 13
        12 14 13
        13 14 15
    "/>
  </asset>

  <worldbody>
    <body name="terrain" pos="0 0 0">
      <geom type="mesh" mesh="terrain" material="white"/>
    </body>
    <body pos="4.5 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="4 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="3.5 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="3 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="2.5 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="2 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="1.5 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="1 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="0.5 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="0. 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="-0.5 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="-1 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="-1.5 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="-2 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="-2.5 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="-3. 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="-3.5 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="-4 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
    <body pos="-4.5 0 0.5">
      <freejoint/>
      <geom type="box" size="0.1 0.1 0.1"/>
    </body>
  </worldbody>
</mujoco>

Code required for reproduction

No response

Confirmations

JewelryForge commented 3 weeks ago

Okay, I need to convert the non-convex object to multiple convex objects for collision detection.