Page 1 of 1

Create collision shape manually with API

Posted: Mon Mar 08, 2021 6:27 am
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?

Re: Create collision shape manually with API

Posted: Tue Mar 09, 2021 2:32 am
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.

Re: Create collision shape manually with API

Posted: Wed Mar 10, 2021 9:34 am
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?