That's a bit annoying. Before you responded I started looking into adding the names myself. Pretty much just de-serializing nameless shapes, and doing some very hacky checks since I know the unique parameters each shape has and re-serializing them with names I have provided. But this doesn't seem to work. Specifically I'm trying to serialize compound shapes.
When I pull them out of the original .bullet file provided by blender they are fine, just without names. I give them names and then use them(all in the same run of my application), and their behavior is fine. Before the application ends I re-serialize the shapes with their names. When I check the file in file inspector all the data inside appears to be correct, with the exception of the names...they still don't appear to have been set. If I attempt to de-serialize the newly generated .bullet file in another run of my application, it seems to only de-serialize the children of the compound shape, but not the compound shapes themselves. So I have ~20 box shapes, ~10 cylinder shapes, and 0 compound shapes in the importer, instead of the intended 2 compound shapes.
Here is the relevant code I am using:
Deserializing:
Code: Select all
btBulletWorldImporter Importer;
Ogre::DataStreamPtr Stream = Ogre::ResourceGroupManager::getSingleton().openResource(FileName,Group);
char* buffer = new char[Stream->size()];
Stream->read((void*)buffer, Stream->size());
if(!Importer.loadFileFromMemory(buffer, Stream->size()))
{
[throw exception]
}
delete[] buffer;
for( Whole X = 0 ; X < Importer.getNumCollisionShapes() ; ++X )
{
btCollisionShape* Shape = Importer.getCollisionShapeByIndex(X);
const char* MaybeAName = Importer.getNameForPointer((void*)Shape);
String Name;
if(MaybeAName)
{
Name = String(MaybeAName);
CollisionShapeManager::iterator it = CollisionShapes.find(Name);
if(it != CollisionShapes.end())
{
CollisionShape* NewShape = WrapShape(Name,Shape);
CollisionShapes[Name] = NewShape;
}
}else{
static Whole NameCount = 0;
Name = String("Unnamed")+=ToString(NameCount++);
CollisionShape* NewShape = WrapShape(Name,Shape);
UnnamedShapes.insert(NewShape);
}
}
Serializing:
Code: Select all
btDefaultSerializer* BulletSerializer = new btDefaultSerializer(1024*1024*5);
BulletSerializer->startSerialization();
for( std::map<String,CollisionShape*>::iterator it = CollisionShapes.begin() ; it != CollisionShapes.end() ; it++ )
{
CollisionShape* Shape = (*it).second;
BulletSerializer->registerNameForPointer((void*)Shape->GetBulletShape(),(*it).first.c_str());
int len = Shape->GetBulletShape()->calculateSerializeBufferSize();
btChunk* chunk = BulletSerializer->allocate(len,1);
const char* structType = Shape->GetBulletShape()->serialize(chunk->m_oldPtr, BulletSerializer);
BulletSerializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,Shape->GetBulletShape());
}
BulletSerializer->finishSerialization();
FILE* f2 = fopen(FileName.c_str(),"wb");
fwrite(BulletSerializer->getBufferPointer(),BulletSerializer->getCurrentBufferSize(),1,f2);
fclose(f2);
And I have attached the two bullet files generated.
Edit: Apparently .bullet extensions aren't allowed.
