Create collision shape manually with API

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
pasta99
Posts: 3
Joined: Mon Mar 08, 2021 6:04 am

Create collision shape manually with API

Post by pasta99 »

I want to use the b3RobotSimulatorClientAPI similar to the Pybullet API in C++ code. In the pybullet examples it is possible to create meshes by hand like so: https://github.com/bulletphysics/bullet ... ateMesh.py . Unfortunately there is no vertices and indices option in the b3RobotSimulatorCreateCollisionShapeArgs. Is there a way to create a mesh like in the example with the C++ API? Am I missing something?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Create collision shape manually with API

Post by Erwin Coumans »

The C++ bindings (b3RobotSimulatorClientAPI ) is limited and would need to be expanded. PyBullet uses the C-API, and so does b3RobotSimulatorClientAPI . You can just add the args you need, and look at pybullet.c how the methods are called.
pasta99
Posts: 3
Joined: Mon Mar 08, 2021 6:04 am

Re: Create collision shape manually with API

Post by pasta99 »

Thanks for the reply.
I added a btAlignedObjectArray for the vertices and indices to the args. In the API I added following code:

Code: Select all

if (shapeType == GEOM_MESH && args.m_numVertices)
        {
                int numVertices = args.m_numVertices;
                int numIndices = args.m_numIndices;

                double* vertices = &args.m_vertices[0];
                int* indices = &args.m_indices[0];
                double meshScale[3];
                scalarToDouble3(args.m_meshScale, meshScale);
                if (numIndices)
                {
                        shapeIndex = b3CreateCollisionShapeAddConcaveMesh(sm, command, meshScale, vertices, numVertices, indices, numIndices);
                }
                else
                {
                        shapeIndex = b3CreateCollisionShapeAddConvexMesh(sm, command, meshScale, vertices, numVertices);
                }
        }
Unfortunately if I call the function I get the message "b3Printf: Request createCollisionShape failed".

Do you have an idea why this might be happening?
Post Reply