Bullet: load / save collisionshape

I am trying to prefix the cycle of all triangles and add them to btTriangleMesh. (Only loading should be fast, speed savings can be ignored.)

So what is the fastest way to load collision data from a file. How about these two:

  • Saving the Vertex array (bt3Vector) and index (DWORD) and loading only resize btTriangleMesh and set the data right away.

  • Using serializeSingleShape () to save and load something like ReadBulletSample (or run a new btDynamicsWorld, read the file with BulletWorldImporter, get a collision object and clear btDynamicsWorld var)

If there are any other methods, let me know. The geometry of the model has these two buffers:

Vertex = vector<float[3]> Index = vector<DWORD> 
+4
source share
2 answers

I used bullet serialization code. I believe that it is already optimized and sees no reason why you should invent it.

bt_col - bullet collision object

  int maxSerializeBufferSize = 1024*1024*5; btDefaultSerializer* serializer = new btDefaultSerializer(maxSerializeBufferSize); serializer->startSerialization(); bt_col->serializeSingleShape(serializer); serializer->finishSerialization(); FILE* file = fopen(filename, "wb"); fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1, file); fclose(file); delete serializer; 
+4
source

If I were you, I would do the following:

  • If the collision file is really large, read it in blocks until you get what you want.
  • Use a memory pool to save blocks to avoid heap fragmentation during update / deletion.
  • Then do the actual collision tests.

If you are trying to save data, you can save it as a structure.

 struct Triangle { float vertices[9]; // 3x3 int index; }; 

If the structures do not have the same size, it will be a little more complicated.

 struct Triangle { int prevOffset; // Offset to the beginning of the previous struct in bytes .. ie. 20 bytes int nextOffset; // Offset at the beginning of the next struct std::vector<float[3]> Vertices; int index; }; 

Reading:

 int offset = 0; char* m_Data; // Pointer to the contents of the file Triangle *getTriangle(){ Triangle* tri = (Triangle*)( m_Data+offset ); offset = tri->Next; return tri; } 

You write structures as bytes while maintaining offsets.

  // Writing the pool tri->next = ( (int)tri-(int)m_Data )+tri->Vertices.size()*4+16; // For a 32bit system // +12 for the ints (next/prev/id) // *4 for the floats 

Exactly how memory pools bind their chunck headers. Using pointers to the previous and next elements so you can iterate in both directions .

+2
source

All Articles