Reading and using a .bullet file

sum1nil
Posts: 3
Joined: Sat Jun 05, 2010 5:36 pm

Reading and using a .bullet file

Post by sum1nil »

Hi,

I am using the rendering engine Lightfeather. Using the tileload event in their large terrain, I am attempting to create a physics model of that tile (and all tiles). I then want to add it to a btTriangleIndexVertexArray using a btIndexedMesh. Here is the rather sloppy code so far:

Code: Select all

     btIndexedMesh iMesh = btIndexedMesh();
     res::CMesh* tileMesh = event.getMesh();; // Is the mesh of only the single tile?
     res::CVertexBuffer* vertices = tileMesh->getVertexBuffer(); //05702c70
     lf::u32 start = vertices->getStartVertex();
     res::CIndexBuffer* indices = tileMesh->getIndexBuffer();
     lf::u32 numIndex = indices->getIndexCount(); 
     lf::u32 numVertex  =  vertices->getVertexCount();
     iMesh.m_triangleIndexBase = (unsigned char*)indices->getPointer();
     iMesh.m_vertexBase = (unsigned char*)vertices->getPointer(res::EVCT_POSITION, start);
     iMesh.m_triangleIndexStride = 0*sizeof(int); // what should this value be?
     iMesh.m_vertexStride = vertices->getVertexStride(); // is a value of 0 correct?
     iMesh.m_numVertices = numVertex;
     iMesh.m_numTriangles = tileMesh->getPolygonCount(); // Is this the same as number of triangles?
     lf::u32 entrySize = vertices->getEntrySize();
     
     triArray->addIndexedMesh(iMesh);
The size of a complete vertex entry for vertices is 28.

After feeding in the triArray to make a btBvhTriangleMeshShape, the btBvhTriangleMeshShape serialization into "myTerrain.bullet" appears to go ok, however, not so much when trying to reload it.

While reloading the btBvhTriangleMeshShape, bullet gives the vertex stride 16 and the index stride 12 but I get an access violation.

Does this seem right? I would appreciate any help. Thank you.

Note: Lightfeather's buffers are non-interleaved which, I believe makes the index and vertex stride equal to zero.
However with the index stride and vertex stride at 0 (in Bullet's processAllTriangles) I noticed that the triangle being made reads only from the vertex base which never advances forward; resulting in all the triangles vertex's having the same values as the vertex base.....I have thousands of triangles all with vertexs whose only values are those at vertexbase. Will post more code later. Thanks.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Reading and using a .bullet file

Post by Erwin Coumans »

There seems to be 2 issues:

1) serialization issue
2) setting up the striding etc.

It will be best to setup the simulation in step (2) working first and make sure everything runs fine. After that, we can look into making the serialization work.

Can you be more precise about the interleaved mesh format? Bullet requires an index array and a vertex array. If there is no index array, you need to create one. Passing a zero striding value doesn't make much sense.

Does the simulation run fine (without using serialization)?
Thanks,
Erwin
sum1nil
Posts: 3
Joined: Sat Jun 05, 2010 5:36 pm

Re: Reading and using a .bullet file

Post by sum1nil »

Thanks for your response. :D
The program has 2 'sides'. One is just the normal rendering of a large terrain done by lightfeather. The other is to build from the tile meshes passed to the tileLoad event a physics model. I was then going to draw lines using a btTriangleBuffer. All of this is just to see if the rendered terrain and the physics model gels. There are no actual direct calls to opengl in this first program; I wanted to write the physics model to disk and have the ability to load it.
---------------

The vertex format of vertices is (Position, Normal, a Color represented by an int):
6 * sizeof(float) + sizeof(int) = 28 (EntrySize is also 28 - bulletWorldLoader automatically calculated a stride for the vertex of 16 (EntrySize - Position size).

The index stride is confusing to me obviously, from the header:
/*!
* The CIndexBuffer class holds an indexbuffer
* Indexbuffers hold the indexes which, combined with a Vertexbuffer represent the geometry of a model
* The indexbuffer is nothing more than a list of positions of vertexes within a vertexbuffer
*/
Not knowing enough to know better, I'd think the index stride corresponding to a vertex buffer would simply be 1.

In Bullet this is the code that throws errors:

Code: Select all

						 unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
						 graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
						 triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());  //Access Violation!!!
						 graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
Questions:
Do I need to do something extra before passing the btTriangleIndexedMesh into the btTriangleMeshShape.

mmmm... starting to ramble...
Please bear with me; very new to graphics programming...etc

The Serialize calls can be skipped. The above access violation happens while trying to fill a btTriangleBuffer using btTriangleMeshShape->processAllTriangles function.

Thanks.