How to manually create convex collision mesh for concave meshes instead of vhacd?

Post Reply
bluefish_
Posts: 8
Joined: Sun Jan 23, 2022 11:24 am

How to manually create convex collision mesh for concave meshes instead of vhacd?

Post by bluefish_ »

Hello! I'm using pybullet to simulate a scene with a few objects chaining together under gravity and the hook object is passing through the box opening:
Screen Shot 2022-01-23 at 3.30.27 AM.png
Screen Shot 2022-01-23 at 3.30.27 AM.png (358.32 KiB) Viewed 4192 times
Screen Shot 2022-01-23 at 3.29.22 AM.png
Screen Shot 2022-01-23 at 3.29.22 AM.png (97.68 KiB) Viewed 4192 times
Screen Shot 2022-01-23 at 3.29.25 AM.png
Screen Shot 2022-01-23 at 3.29.25 AM.png (95.7 KiB) Viewed 4192 times
I'm using vhacd to generate a convex decomposition of the original box mesh because the original shape is concave (using code

Code: Select all

p.vhacd(self.part_obj_path, obj_acd_path, "log.txt", pca=True, mode=1)
). Somehow vhacd is not working super well for this concave mesh and I tried to create a mesh file with "o convex_#" of different components but it still didn't seem to help. I'm wondering in this case is it because the collision mesh is not correct or because of some other factors?

Below is the rough structure of my code; please let me know if there's anything in my code that might be contributing to this; thanks very much!

Code: Select all

    
    p.connect(p.GUI)
    p.setAdditionalSearchPath(pybullet_data.getDataPath())
    # disable rendering
    p.configureDebugVisualizer(p.COV_ENABLE_RENDERING, 0)
    p.configureDebugVisualizer(p.COV_ENABLE_GUI, 0)
    p.configureDebugVisualizer(p.COV_ENABLE_TINY_RENDERER, 0)
    p.setGravity(0,0,-9.8)

    for id, part in list_of_parts():
        part_mesh = get_part_mesh()
        mesh_color = part_mesh.get_color()
        rgba = list(mesh_color) + [1]
        quarternion = p.getQuaternionFromEuler(part.frame.radians_rot())
        visualShapeId = p.createVisualShape(shapeType=p.GEOM_MESH,
                            fileName=part.collision_obj_path,
                            rgbaColor=rgba,
                            visualFramePosition=part.frame.pos,
                            visualFrameOrientation=quarternion)
        collisionShapeId = p.createCollisionShape(shapeType=p.GEOM_MESH,
                            fileName=part.collision_obj_path,
                            collisionFramePosition=part.frame.pos,
                            collisionFrameOrientation=quarternion)
        bodyId = p.createMultiBody(baseMass=part.mass,
            baseCollisionShapeIndex=collisionShapeId,
            baseVisualShapeIndex=visualShapeId,
            useMaximalCoordinates=True)
        p.changeDynamics(bodyId,-1,activationState=p.ACTIVATION_STATE_ENABLE_SLEEPING,linearDamping=0.5, angularDamping=0.5)

    startPos = [0,0,0]
    p.resetDebugVisualizerCamera(cameraDistance=800, cameraYaw=60, cameraPitch=-60, cameraTargetPosition=startPos)
    p.configureDebugVisualizer(p.COV_ENABLE_RENDERING, 1)
    p.setRealTimeSimulation(1)
    
    while True:
    	p.stepSimulation()
 
Post Reply