I am into my first 3D game. I am using blender to create my model, using bullet for physics, and Isgl3D game engine.
So far, I am able to
- Create models in blender
- Export it to iPhone using Isgl3D libraries and show them.
- Create physics bodies along the vertices of this models (for simple models like cube and sphere.)
Now I want to create some complex irregular models and create physics rigid bodies along the vertices of that model. From my research, I found btTriangleMesh
and btBvhTriangleMeshShape
which can be used to create complex physics rigid bodies.
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 the above given 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.
Anyone know how indices exported from .POD file differ from normal triangle indices. No way I could make a cube from the indices as it printed right now.
An additional question, Has anyone has an example code that creates triangle mesh to create physics rigid body.