btTriangleMesh from imported .pod model.

29 views
Skip to first unread message

jayanth s

unread,
Jul 8, 2013, 3:09:29 AM7/8/13
to isg...@googlegroups.com
Okay, I found this thread, where bullet physics bodies are created along the vertices of a model exported from blender using POD importer. But they use btConvexHullShape to create the rigid body, which may not work in my case because my requirement has irregular complex models.

So I was trying to create a btTriangleMesh along the vertices of my model, so that I can create a btBvhTriangleMeshShape to create my rigid body.

So for starters I exported a cube (default blender cube, placed at origin) to understand how the vertices are stored in the Isgl3dMeshNode structure. This is my code

        Isgl3dPODImporter * podImporter = [Isgl3dPODImporter podImporterWithFile:@"simpleCube.pod"];
    NSLog(@"number of meshes : %d", podImporter.numberOfMeshes);
    [podImporter buildSceneObjects];
    [podImporter addMeshesToScene:self.scene];
       
    Isgl3dMeshNode * ground     =   [podImporter meshNodeWithName:@"Cube"];
    btCollisionShape *groundShape   =   [self getCollisionShapeForNode:ground];


and my getCollisionShapeForNode method is

- (btCollisionShape*) getCollisionShapeForNode: (Isgl3dMeshNode*)node{
    int numVertices = node.mesh.numberOfVertices;
    NSLog(@"no of vertices : %d", numVertices);
    NSLog(@"no of indices : %d", node.mesh.numberOfElements);
    unsigned char * indices =   node.mesh.indices;
   
    btCollisionShape* collisionShape = nil;
    btTriangleMesh* triangleMesh        =   new btTriangleMesh();
    for (int i = 0; i < node.mesh.numberOfElements; i+=3) {
        NSLog(@"%d %d %d", indices[i],
indices[i+1], indices[i+2]);
    }
}


And the NSLog statement prints..

number of meshes : 1
no of vertices : 24
no of indices : 36

and indices printed as

 20   0    21
 0    22   0
 20   0    22
 0    23   0
 16   0    17
 0    18   0
 16   0    18
 0    19   0
 12   0    13
 0    14   0
 12   0    14
 0    15   0


I am not sure I understand how this indices (and the vertices it points to) constitute 12 triangles (two in each phase) in the cube. I expect indices to be something like this (given below)

20   21    22 //phase 6          
20   22    23           
16   17    18 //phase 5          
16   18    19           
12   13    14 //phase 4         
12   14    15           
8    9     10 //phase 3          
8    10    11           
4    5     6  //phase 2          
4    6     7            
0    1     2  //phase 1          
0    2     3



Probably I am missing something obvious. But I am stuck on this for sometime. How we can use indices to constitute a triangle mesh, so that I can create a physics body along the lines of that.

An additional question, Has anyone has an example code that creates triangle mesh to create physics rigid body.
Reply all
Reply to author
Forward
0 new messages