MuJoCo custom object mesh flickering through table surface in gym environment

I’m working with the FetchReach-v1 gym environment and decided to swap out the default block with a custom wrench mesh. The simulation runs fine but I’m getting this annoying issue where my wrench keeps bouncing up and down through the table surface every couple of frames.

Basically the wrench will be sitting on the table normally, then suddenly drop halfway through the surface, then pop back up again. It’s like it can’t decide where it wants to be.

I modified the reach.xml file and replaced the original object definition with this:

<body name="target_obj" pos="0.0 0.0 0.0">
    <joint name="target_obj:joint" type="free" damping="0.02"></joint>
    <geom size="0.03 0.03 0.03" mesh="wrench_model" condim="3" name="target_obj" material="obj_material" class="objects" mass="1.5"></geom>
    <site name="target_obj" pos="0 0 0" size="0.025 0.025 0.025" rgba="0 1 0 1" type="sphere"></site>
</body>

I tried adjusting the position values and geometry settings but nothing seems to help. When I switch back to type="box" instead of using the mesh, everything works perfectly. Anyone know what might be causing this mesh collision issue?

Had this exact issue importing custom meshes from Blender. MuJoCo’s physics solver freaks out with complex mesh topology during contact resolution. Add contype="1" and conaffinity="1" to your geom definition - it explicitly sets collision layer properties and usually fixes it. Also try lowering the joint damping value. Sounds backwards, but higher damping actually makes the solver more unstable with complex meshes. Check your timestep too - if it’s too large, the integrator can’t handle rapid contact changes. I had to drop mine from 0.002 to 0.001 for detailed meshes. Last thing - make sure your wrench mesh is properly triangulated. No degenerate faces or super thin geometry that’ll mess with collision detection.

Sounds like a penetration depth problem with your mesh. Add margin="0.001" to the geom tag - it creates a buffer around the mesh surface to stop interpenetration. Also check your wrench mesh for double faces or flipped normals. That’s what usually makes objects bounce through surfaces like crazy.

I’ve encountered this exact mesh instability issue with non-convex objects in MuJoCo. Your wrench mesh might be too detailed for the contact solver, which struggles to handle complex surfaces reliably. To resolve this, try creating a simplified collision proxy using type="convex" instead of your raw mesh. Keep your detailed wrench for visuals, but use a basic convex hull for physics purposes. Set up two separate geom elements: one for the visual with full detail and one for collision only with simple geometry. Make sure to set your visual geom to contype="0" to prevent interference with physics. Additionally, use basic box or capsule primitives that approximate your wrench shape for the collision geom. This dual setup should eliminate the flickering while maintaining visual fidelity. Lastly, verify your mesh export to ensure there aren’t overlapping vertices or internal geometry, as those will consistently confuse the collision system.

This flickering happens because your custom mesh isn’t making good contact with the table surface. I’ve hit the same issue importing CAD models into MuJoCo. Usually it’s because the mesh has too many contact points or weird surface normals that mess up the constraint solver. Add solimp="0.9 0.95 0.001" and solref="0.02 1" to your geom definition - these control contact impedance and reference values to stabilize mesh interactions. Also bump up the nconmax value in your worldbody settings if you haven’t. Complex meshes need more contact constraints to settle down. Check if your wrench mesh has proper vertex normals too. MuJoCo uses these for contact detection, and bad normals will cause exactly the jittery behavior you’re seeing. Most 3D software can recalculate vertex normals automatically.

The flickering usually comes from bad collision mesh properties or scaling issues. I’ve hit this same problem with custom meshes in MuJoCo - it’s almost always misaligned vertices or collision hulls that are too complex for stable contact detection. First, check if your wrench mesh has clean collision geometry. MuJoCo likes convex hulls, so if your wrench has detailed features or concave parts, the physics engine can’t compute stable contacts. You’ll probably need a separate simplified collision mesh from your visual one. Scale mismatch is another common culprit. Even with size parameters in the geom tag, MuJoCo might still use the original mesh dimensions. Try explicit scaling in your mesh definition or double-check that your wrench is properly sized before importing. Also worth checking the mass distribution - if the mesh center of mass doesn’t line up with the geometry center, you’ll get weird settling behavior on the table.