add example to import and export a binary .bullet file
This commit is contained in:
@@ -34,6 +34,14 @@ SET(App_ExampleBrowser_SRCS
|
||||
../Benchmarks/landscapeData.h
|
||||
../Benchmarks/TaruData
|
||||
../Importers/ImportBsp/BspConverter.h
|
||||
../Importers/ImportBullet/SerializeSetup.cpp
|
||||
../Importers/ImportBullet/SerializeSetup.h
|
||||
|
||||
../../Extras/Serialize/BulletWorldImporter/btWorldImporter.cpp
|
||||
../../Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp
|
||||
../../Extras/Serialize/BulletFileLoader/bChunk.cpp ../../Extras/Serialize/BulletFileLoader/bFile.cpp
|
||||
../../Extras/Serialize/BulletFileLoader/bDNA.cpp ../../Extras/Serialize/BulletFileLoader/btBulletFile.cpp
|
||||
|
||||
../Importers/ImportBsp/BspLoader.h
|
||||
../Importers/ImportBsp/ImportBspExample.h
|
||||
../Importers/ImportColladaDemo/btMatrix4x4.h
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "../Constraints/ConstraintDemo.h"
|
||||
#include "../Vehicles/Hinge2Vehicle.h"
|
||||
#include "../Experiments/ImplicitCloth/ImplicitClothExample.h"
|
||||
#include "../Importers/ImportBullet/SerializeSetup.h"
|
||||
|
||||
|
||||
struct ExampleEntry
|
||||
@@ -128,6 +129,8 @@ static ExampleEntry gDefaultExamples[]=
|
||||
|
||||
|
||||
ExampleEntry(0,"Importers"),
|
||||
ExampleEntry(1,"Import .bullet", "Load a binary .bullet file. The serialization mechanism can deal with versioning, differences in endianess, 32 and 64bit, double/single precision. It is easy to save a .bullet file, see the examples/Importers/ImportBullet/SerializeDemo.cpp for a code example how to export a .bullet file.", SerializeBulletCreateFunc),
|
||||
|
||||
ExampleEntry(1,"Wavefront Obj", "Import a Wavefront .obj file", ImportObjCreateFunc, 0),
|
||||
|
||||
ExampleEntry(1,"Quake BSP", "Import a Quake .bsp file", ImportBspCreateFunc, 0),
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
"../CommonInterfaces/*",
|
||||
"../ForkLift/ForkLiftDemo.*",
|
||||
"../Importers/**",
|
||||
"../../Extras/Serialize/BulletWorldImporter/*",
|
||||
"../../Extras/Serialize/BulletFileLoader/*",
|
||||
"../Planar2D/Planar2D.*",
|
||||
"../RenderingExamples/*",
|
||||
"../VoronoiFracture/*",
|
||||
|
||||
95
examples/Importers/ImportBullet/SerializeSetup.cpp
Normal file
95
examples/Importers/ImportBullet/SerializeSetup.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#include "SerializeSetup.h"
|
||||
#include "../Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h"
|
||||
|
||||
|
||||
#include "../CommonInterfaces/CommonRigidBodyBase.h"
|
||||
|
||||
class SerializeSetup : public CommonRigidBodyBase
|
||||
{
|
||||
public:
|
||||
SerializeSetup(struct GUIHelperInterface* helper);
|
||||
virtual ~SerializeSetup();
|
||||
|
||||
virtual void initPhysics();
|
||||
virtual void stepSimulation(float deltaTime);
|
||||
};
|
||||
|
||||
|
||||
SerializeSetup::SerializeSetup(struct GUIHelperInterface* helper)
|
||||
:CommonRigidBodyBase(helper)
|
||||
{
|
||||
|
||||
}
|
||||
SerializeSetup::~SerializeSetup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SerializeSetup::initPhysics()
|
||||
{
|
||||
this->createEmptyDynamicsWorld();
|
||||
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
|
||||
m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints);
|
||||
btBulletWorldImporter* importer = new btBulletWorldImporter(m_dynamicsWorld);
|
||||
const char* someFileName="spider.bullet";
|
||||
|
||||
const char* prefix[]={"./","./data/","../data/","../../data/","../../../data/","../../../../data/"};
|
||||
int numPrefixes = sizeof(prefix)/sizeof(const char*);
|
||||
char relativeFileName[1024];
|
||||
FILE* f=0;
|
||||
bool fileFound = false;
|
||||
int result = 0;
|
||||
|
||||
for (int i=0;!f && i<numPrefixes;i++)
|
||||
{
|
||||
sprintf(relativeFileName,"%s%s",prefix[i],someFileName);
|
||||
f = fopen(relativeFileName,"rb");
|
||||
if (f)
|
||||
{
|
||||
fileFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (f)
|
||||
{
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
importer->loadFile(relativeFileName);
|
||||
|
||||
//for now, guess the up axis from gravity
|
||||
if (m_dynamicsWorld->getGravity()[1] == 0.f)
|
||||
{
|
||||
m_guiHelper->setUpAxis(2);
|
||||
} else
|
||||
{
|
||||
m_guiHelper->setUpAxis(1);
|
||||
}
|
||||
|
||||
|
||||
//example code to export the dynamics world to a .bullet file
|
||||
|
||||
|
||||
btDefaultSerializer* serializer = new btDefaultSerializer();
|
||||
m_dynamicsWorld->serialize(serializer);
|
||||
|
||||
FILE* file = fopen("testFile.bullet","wb");
|
||||
fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1, file);
|
||||
fclose(file);
|
||||
|
||||
|
||||
|
||||
|
||||
m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld);
|
||||
}
|
||||
|
||||
void SerializeSetup::stepSimulation(float deltaTime)
|
||||
{
|
||||
CommonRigidBodyBase::stepSimulation(deltaTime);
|
||||
}
|
||||
|
||||
class CommonExampleInterface* SerializeBulletCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
||||
{
|
||||
return new SerializeSetup(helper);
|
||||
}
|
||||
7
examples/Importers/ImportBullet/SerializeSetup.h
Normal file
7
examples/Importers/ImportBullet/SerializeSetup.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef SERIALIZE_SETUP_H
|
||||
#define SERIALIZE_SETUP_H
|
||||
|
||||
class CommonExampleInterface* SerializeBulletCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||
|
||||
|
||||
#endif //SERIALIZE_SETUP_H
|
||||
Reference in New Issue
Block a user