[SOLVED] btGImpactMeshShape scrambled...

Post Reply
LastBlow
Posts: 9
Joined: Mon Jul 11, 2016 10:36 am
Location: SAN DIEGO

[SOLVED] btGImpactMeshShape scrambled...

Post by LastBlow » Sat Nov 11, 2017 10:39 pm

Hi!

It seems that Bullet Physics defines the vertices and triangles in a btTriangleIndexVertexArray in a way different from the way they are defined in Blender, so the mesh appears scrambled. For illustration, here below 3 cubes rendered as a btBoxShape and a cube rendered as a btGImpactMeshShape based on a btTriangleIndexVertexArray. The .obj cube mesh is exported from Blender and the same for all 4 cubes.

Thus the question, how to export a concave mesh from Blender, so its vertices and triangles can be loaded in Bullet Physics as a btTriangleIndexVertexArray to create a btGImpactMeshShape without the mesh being scrambled, any... silver bullet to do that???

Thanks! ;-)
Blender cube.jpg
Blender cube.jpg (636.08 KiB) Viewed 874 times
Last edited by LastBlow on Mon Nov 13, 2017 3:13 pm, edited 9 times in total.

LastBlow
Posts: 9
Joined: Mon Jul 11, 2016 10:36 am
Location: SAN DIEGO

Re: btGImpactMeshShape scrambled...

Post by LastBlow » Sun Nov 12, 2017 1:47 am

Alright, just figured it out, so it can help others... Blender names its indices starting at 1 while Bullet Physics starts at 0.

As an example, here below how the vertices and indices for a btTriangleIndexVertexArray should look like for a cube mesh
exported from Blender to render properly in Bullet Physics as a btGImpactMeshShape.

Plus a low-poly rendition of the Standford Bunny who just happened to hop by... ;-)

PS. Related post at stackoverflow: https://stackoverflow.com/questions/242 ... 7#47243137

Code: Select all

const int NUMBER_VERTICES = 8;
const int NUMBER_TRIANGLES = 12;


static btScalar cubeVertices[3 * NUMBER_VERTICES] = {
   1.000000, -1.000000, -1.000000,
   1.000000, -1.000000, 1.000000,
   -1.000000, -1.000000, 1.000000,
   -1.000000, -1.000000, -1.000000,
   1.000000, 1.000000, -0.999999,
   0.999999, 1.000000, 1.000001,
   -1.000000, 1.000000, 1.000000,
   -1.000000, 1.000000, -1.000000
};

static int cubeIndices[NUMBER_TRIANGLES][3] = {
   { 1, 3, 0 },
   { 7, 5, 4 },
   { 4, 1, 0 },
   { 5, 2, 1 },
   { 2, 7, 3 },
   { 0, 7, 4 },
   { 1, 2, 3 },
   { 7, 6, 5 },
   { 4, 5, 1 },
   { 5, 6, 2 },
   { 2, 6, 7 },
   { 0, 3, 7 }
};
Attachments
the newest family addition.jpg
the newest family addition.jpg (380.05 KiB) Viewed 840 times

Post Reply