More work on serialization and BulletFileLoader

This commit is contained in:
erwin.coumans
2010-01-22 00:15:33 +00:00
parent 50aa82a240
commit 26a056e629
49 changed files with 6714 additions and 160 deletions

View File

@@ -12,26 +12,15 @@ SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
########################################################
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
${BULLET_PHYSICS_SOURCE_DIR}/src
${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
)
SET(SERIALIZE_FILES
bChunk.cpp
bChunk.h
bCommon.h
bDefines.h
bDNA.cpp
bDNA.h
bFile.cpp
bFile.h
btBulletFile.cpp
btBulletFile.h
)
IF (USE_GLUT)
LINK_LIBRARIES(
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
OpenGLSupport BulletDynamics BulletCollision LinearMath BulletFileLoader ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
)
ADD_EXECUTABLE(AppSerializeDemo
@@ -43,7 +32,7 @@ IF (USE_GLUT)
ELSE (USE_GLUT)
LINK_LIBRARIES(
OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
OpenGLSupport BulletDynamics BulletCollision LinearMath BulletFileLoader ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
)
ADD_EXECUTABLE(AppSerializeDemo

View File

@@ -13,6 +13,7 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#define TEST_SERIALIZATION 1
///create 125 (5x5x5) dynamic object
@@ -148,7 +149,9 @@ void SerializeDemo::initPhysics()
//create a few dynamic rigidbodies
// Re-using the same collision is better for memory usage and performance
btCollisionShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1));
btCollisionShape* colShape = new btCapsuleShape(SCALING*1,SCALING*1);
//btCollisionShape* colShape = new btCylinderShape(btVector3(SCALING*1,SCALING*1,SCALING*1));
//btCollisionShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1));
//btCollisionShape* colShape = new btSphereShape(btScalar(1.));
m_collisionShapes.push_back(colShape);
@@ -218,7 +221,7 @@ void SerializeDemo::initPhysics()
bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile("testFile.bullet");
bool ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0;
bool verboseDumpAllTypes = true;
bool verboseDumpAllTypes = false;
if (ok)
bulletFile2->parse(verboseDumpAllTypes);
@@ -228,16 +231,95 @@ void SerializeDemo::initPhysics()
}
int i;
btHashMap<btHashPtr,btCollisionShape*> shapeMap;
for (i=0;i<bulletFile2->m_collisionShapes.size();i++)
{
btCollisionShapeData* shapeData = (btCollisionShapeData*)bulletFile2->m_collisionShapes[i];
printf("bla");
switch (shapeData->m_shapeType)
{
case CYLINDER_SHAPE_PROXYTYPE:
case CAPSULE_SHAPE_PROXYTYPE:
case BOX_SHAPE_PROXYTYPE:
case SPHERE_SHAPE_PROXYTYPE:
{
btConvexInternalShapeData* bsd = (btConvexInternalShapeData*)shapeData;
btVector3 implicitShapeDimensions;
implicitShapeDimensions.deSerialize(bsd->m_implicitShapeDimensions);
btVector3 margin(bsd->m_collisionMargin,bsd->m_collisionMargin,bsd->m_collisionMargin);
btCollisionShape* shape = 0;
switch (shapeData->m_shapeType)
{
case BOX_SHAPE_PROXYTYPE:
{
shape = new btBoxShape(implicitShapeDimensions+margin);
break;
}
case SPHERE_SHAPE_PROXYTYPE:
{
shape = new btSphereShape(implicitShapeDimensions.getX());
break;
}
case CAPSULE_SHAPE_PROXYTYPE:
{
shape = new btCapsuleShape(implicitShapeDimensions.getX(),implicitShapeDimensions.getY());
break;
}
case CYLINDER_SHAPE_PROXYTYPE:
{
shape = new btCylinderShape(implicitShapeDimensions+margin);
break;
}
default:
{
printf("error: cannot create shape type (%d)\n",shapeData->m_shapeType);
}
}
if (shape)
{
shape->setMargin(bsd->m_collisionMargin);
btVector3 localScaling;
localScaling.deSerialize(bsd->m_localScaling);
shape->setLocalScaling(localScaling);
m_collisionShapes.push_back(shape);
shapeMap.insert(shapeData,shape);
}
break;
}
default:
{
printf("unsupported shape type (%d)\n",shapeData->m_shapeType);
}
}
}
for (i=0;i<bulletFile2->m_rigidBodies.size();i++)
{
btRigidBodyData* colObjData = (btRigidBodyData*)bulletFile2->m_rigidBodies[i];
printf("bla");
btScalar mass = colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f;
btVector3 localInertia;
localInertia.setZero();
btCollisionShape** shapePtr = shapeMap.find(colObjData->m_collisionObjectData.m_collisionShape);
if (shapePtr && *shapePtr)
{
btTransform startTransform;
startTransform.deSerialize(colObjData->m_collisionObjectData.m_worldTransform);
btCollisionShape* shape = (btCollisionShape*)*shapePtr;
if (mass)
{
shape->calculateLocalInertia(mass,localInertia);
}
btRigidBody* body = localCreateRigidBody(mass,startTransform,shape);
} else
{
printf("error: no shape found\n");
}
}
for (i=0;i<bulletFile2->m_collisionObjects.size();i++)

View File

@@ -117,7 +117,7 @@ void btBulletFile::parseData()
m_collisionObjects.push_back((bStructHandle*) id);
}
if (dataChunk.code == BT_BOXSHAPE_CODE)
if (dataChunk.code == BT_SHAPE_CODE)
{
m_collisionShapes.push_back((bStructHandle*) id);
}

View File

@@ -24,6 +24,8 @@ subject to the following restrictions:
#define BT_COLLISIONOBJECT_CODE MAKE_ID('C','O','B','J')
#define BT_RIGIDBODY_CODE MAKE_ID('R','B','D','Y')
#define BT_BOXSHAPE_CODE MAKE_ID('B','O','X','S')
#define BT_SHAPE_CODE MAKE_ID('S','H','A','P')
namespace bParse {

View File

@@ -1 +1 @@
SUBDIRS( glui ConvexDecomposition BulletColladaConverter LibXML COLLADA_DOM GIMPACTUtils )
SUBDIRS( glui ConvexDecomposition BulletColladaConverter LibXML COLLADA_DOM GIMPACTUtils Serialize)

View File

@@ -0,0 +1,7 @@
INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/src
${BULLET_PHYSICS_SOURCE_DIR}/src
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BlenderSerialize
)
ADD_LIBRARY(BlenderSerialize dna249.cpp dna249-64bit.cpp bBlenderFile.cpp bBlenderFile.h bMain.cpp bMain.h )

View File

@@ -0,0 +1,224 @@
/*
bParse
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "bBlenderFile.h"
#include "bMain.h"
#include "bDefines.h"
#include "bDNA.h"
#include <stdio.h>
#include <string.h>
// 32 && 64 bit versions
extern unsigned char DNAstr[];
extern int DNAlen;
extern unsigned char DNAstr64[];
extern int DNAlen64;
using namespace bParse;
bBlenderFile::bBlenderFile(const char* fileName)
:bFile(fileName, "BLENDER")
{
mMain= new bMain(this, fileName, mVersion);
}
bBlenderFile::bBlenderFile(char *memoryBuffer, int len)
:bFile(memoryBuffer,len, "BLENDER"),
mMain(0)
{
mMain= new bMain(this, "memoryBuf", mVersion);
}
bBlenderFile::~bBlenderFile()
{
delete mMain;
}
bMain* bBlenderFile::getMain()
{
return mMain;
}
// ----------------------------------------------------- //
void bBlenderFile::parseData()
{
printf ("Building datablocks\n");
printf ("Chunk size = %d\n",CHUNK_HEADER_LEN);
printf ("File chunk size = %d\n", ChunkUtils::getOffset(mFlags));
const bool swap = (mFlags&FD_ENDIAN_SWAP)!=0;
char *dataPtr = mFileBuffer+mDataStart;
bChunkInd dataChunk;
dataChunk.code = 0;
//dataPtr += ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags);
int seek = ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags);
//dataPtr += ChunkUtils::getOffset(mFlags);
char *dataPtrHead = 0;
while (dataChunk.code != DNA1)
{
// one behind
if (dataChunk.code == SDNA) break;
//if (dataChunk.code == DNA1) break;
// same as (BHEAD+DATA dependancy)
dataPtrHead = dataPtr+ChunkUtils::getOffset(mFlags);
char *id = readStruct(dataPtrHead, dataChunk);
// lookup maps
if (id)
{
mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)id);
m_chunks.push_back(dataChunk);
// block it
bListBasePtr *listID = mMain->getListBasePtr(dataChunk.code);
if (listID)
listID->push_back((bStructHandle*)id);
}
if (dataChunk.code == GLOB)
{
m_glob = (bStructHandle*) id;
}
// next please!
dataPtr += seek;
seek = ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags);
if (seek < 0)
break;
}
}
void bBlenderFile::addDataBlock(char* dataBlock)
{
mMain->addDatablock(dataBlock);
}
// 32 && 64 bit versions
extern unsigned char DNAstr[];
extern int DNAlen;
//unsigned char DNAstr[]={0};
//int DNAlen=0;
extern unsigned char DNAstr64[];
extern int DNAlen64;
void bBlenderFile::writeDNA(FILE* fp)
{
bChunkInd dataChunk;
dataChunk.code = DNA1;
dataChunk.dna_nr = 0;
dataChunk.nr = 1;
if (VOID_IS_8)
{
dataChunk.len = DNAlen64;
dataChunk.oldPtr = DNAstr64;
fwrite(&dataChunk,sizeof(bChunkInd),1,fp);
fwrite(DNAstr64, DNAlen64,1,fp);
}
else
{
dataChunk.len = DNAlen;
dataChunk.oldPtr = DNAstr;
fwrite(&dataChunk,sizeof(bChunkInd),1,fp);
fwrite(DNAstr, DNAlen,1,fp);
}
}
void bBlenderFile::parse(bool verboseDumpAllTypes)
{
if (VOID_IS_8)
{
parseInternal(verboseDumpAllTypes,(char*)DNAstr64,DNAlen64);
}
else
{
parseInternal(verboseDumpAllTypes,(char*)DNAstr,DNAlen);
}
}
// experimental
int bBlenderFile::write(const char* fileName, bool fixupPointers)
{
FILE *fp = fopen(fileName, "wb");
if (fp)
{
char header[SIZEOFBLENDERHEADER] ;
memcpy(header, m_headerString, 7);
int endian= 1;
endian= ((char*)&endian)[0];
if (endian)
{
header[7] = '_';
} else
{
header[7] = '-';
}
if (VOID_IS_8)
{
header[8]='V';
} else
{
header[8]='v';
}
header[9] = '2';
header[10] = '4';
header[11] = '9';
fwrite(header,SIZEOFBLENDERHEADER,1,fp);
writeChunks(fp, fixupPointers);
writeDNA(fp);
fclose(fp);
} else
{
printf("Error: cannot open file %s for writing\n",fileName);
return 0;
}
return 1;
}

View File

@@ -0,0 +1,63 @@
/*
bParse
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef B_BLENDER_FILE_H
#define B_BLENDER_FILE_H
#include "bFile.h"
namespace bParse {
// ----------------------------------------------------- //
class bBlenderFile : public bFile
{
protected:
bMain* mMain;
bStructHandle* m_glob;
public:
bBlenderFile(const char* fileName);
bBlenderFile(char *memoryBuffer, int len);
virtual ~bBlenderFile();
bMain* getMain();
virtual void addDataBlock(char* dataBlock);
bStructHandle* getFileGlobal()
{
return m_glob;
}
// experimental
virtual int write(const char* fileName, bool fixupPointers = false);
virtual void parse(bool verboseDumpAllTypes);
virtual void parseData();
virtual void writeDNA(FILE* fp);
};
};
#endif //B_BLENDER_FILE_H

View File

@@ -0,0 +1,392 @@
/*
bParse
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "bMain.h"
#include "bBlenderFile.h"
#include "bDefines.h"
#include "bChunk.h"
#include "bDNA.h"
using namespace bParse;
// ----------------------------------------------------- //
bMain::bMain(bBlenderFile *filePtr, const char *baseName, int fileVersion)
: mFP(filePtr),
mVersion(fileVersion),
mName(baseName)
{
mData.insert(ID_SCE,bListBasePtr());
mData.insert(ID_LI,bListBasePtr());
mData.insert(ID_OB,bListBasePtr());
mData.insert(ID_ME,bListBasePtr());
mData.insert(ID_CU,bListBasePtr());
mData.insert(ID_MB,bListBasePtr());
mData.insert(ID_MA,bListBasePtr());
mData.insert(ID_TE,bListBasePtr());
mData.insert(ID_IM,bListBasePtr());
mData.insert(ID_WV,bListBasePtr());
mData.insert(ID_LT,bListBasePtr());
mData.insert(ID_LA,bListBasePtr());
mData.insert(ID_CA,bListBasePtr());
mData.insert(ID_IP,bListBasePtr());
mData.insert(ID_KE,bListBasePtr());
mData.insert(ID_WO,bListBasePtr());
mData.insert(ID_SCR,bListBasePtr());
mData.insert(ID_VF,bListBasePtr());
mData.insert(ID_TXT,bListBasePtr());
mData.insert(ID_SO,bListBasePtr());
mData.insert(ID_GR,bListBasePtr());
mData.insert(ID_AR,bListBasePtr());
mData.insert(ID_AC,bListBasePtr());
mData.insert(ID_NT,bListBasePtr());
mData.insert(ID_BR,bListBasePtr());
mData.insert(ID_SCRIPT, bListBasePtr());
}
// ----------------------------------------------------- //
bMain::~bMain()
{
// allocated data blocks!
int sz = mPool.size();
for (int i=0;i<sz;i++)
{
delete [] mPool[i];
}
}
// ----------------------------------------------------- //
int bMain::getVersion()
{
return mVersion;
}
// ----------------------------------------------------- //
const char *bMain::getName()
{
return mName;
}
// ----------------------------------------------------- //
void bMain::addDatablock(void *allocated)
{
assert(allocated);
mPool.push_back((bStructHandle*)allocated);
}
// ------------------------------------------------------------//
void bMain::linkList(void *listBasePtr)
{
struct ListBase // local Blender::ListBase
{
void *first;
void *last;
};
struct Link // local Blender::Link
{
void *next;
void *prev;
};
ListBase *base = (ListBase*)listBasePtr;
if (!base || !base->first)
return;
base->first = mFP->findLibPointer(base->first);
if (!base->first)
{
base->last = 0;
return;
}
void *prev = 0;
Link *l = (Link*)base->first;
while (l)
{
l->next = mFP->findLibPointer(l->next);
l->prev = l->next;
prev = l->next;
l = (Link*)l->next;
}
}
// ------------------------------------------------------------//
bListBasePtr* bMain::getListBasePtr(int listBaseCode)
{
bListBasePtr *ptr = _findCode(listBaseCode);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::_findCode(int code)
{
bListBasePtr* lbPtr = mData.find(code);
return lbPtr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getScene()
{
bListBasePtr *ptr = _findCode(ID_SCE);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getLibrary()
{
bListBasePtr *ptr = _findCode(ID_LI);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getObject()
{
bListBasePtr *ptr = _findCode(ID_OB);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getMesh()
{
bListBasePtr *ptr = _findCode(ID_ME);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getCurve()
{
bListBasePtr *ptr = _findCode(ID_CU);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getMball()
{
bListBasePtr *ptr = _findCode(ID_MB);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getMat()
{
bListBasePtr *ptr = _findCode(ID_MA);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getTex()
{
bListBasePtr *ptr = _findCode(ID_TE);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getImage()
{
bListBasePtr *ptr = _findCode(ID_IM);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getWave()
{
bListBasePtr *ptr = _findCode(ID_WV);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getLatt()
{
bListBasePtr *ptr = _findCode(ID_LT);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getLamp()
{
bListBasePtr *ptr = _findCode(ID_LA);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getCamera()
{
bListBasePtr *ptr = _findCode(ID_CA);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getIpo()
{
bListBasePtr *ptr = _findCode(ID_IP);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getKey()
{
bListBasePtr *ptr = _findCode(ID_KE);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getWorld()
{
bListBasePtr *ptr = _findCode(ID_WO);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getScreen()
{
bListBasePtr *ptr = _findCode(ID_SCR);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getScript()
{
bListBasePtr *ptr = _findCode(ID_SCRIPT);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getVfont()
{
bListBasePtr *ptr = _findCode(ID_VF);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getText()
{
bListBasePtr *ptr = _findCode(ID_TXT);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getSound()
{
bListBasePtr *ptr = _findCode(ID_SO);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getGroup()
{
bListBasePtr *ptr = _findCode(ID_GR);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getArmature()
{
bListBasePtr *ptr = _findCode(ID_AR);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getAction()
{
bListBasePtr *ptr = _findCode(ID_AC);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getNodetree()
{
bListBasePtr *ptr = _findCode(ID_NT);
if (!ptr)
return 0;
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getBrush()
{
bListBasePtr *ptr = _findCode(ID_BR);
if (!ptr)
return 0;
return ptr;
}
//eof

View File

@@ -0,0 +1,110 @@
/*
bParse
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef __BMAIN_H__
#define __BMAIN_H__
#include "bCommon.h"
#include "bChunk.h"
#include "LinearMath/btHashMap.h"
namespace bParse
{
class bDNA;
class bBlenderFile;
};
namespace bParse {
// ----------------------------------------------------- //
typedef btHashMap<btHashInt,bListBasePtr> bMainDataMap;
// ----------------------------------------------------- //
class bMain
{
//private:
public:
bBlenderFile* mFP;
bListBasePtr mPool;
int mVersion;
const char* mName;
bMainDataMap mData;
bListBasePtr *_findCode(int code);
public:
bMain(bBlenderFile *filePtr, const char *baseName, int fileVersion);
~bMain();
int getVersion();
const char *getName();
bListBasePtr *getListBasePtr(int listBaseCode);
bListBasePtr *getScene();
bListBasePtr *getLibrary();
bListBasePtr *getObject();
bListBasePtr *getMesh();
bListBasePtr *getCurve();
bListBasePtr *getMball();
bListBasePtr *getMat();
bListBasePtr *getTex();
bListBasePtr *getImage();
bListBasePtr *getWave();
bListBasePtr *getLatt();
bListBasePtr *getLamp();
bListBasePtr *getCamera();
bListBasePtr *getIpo();
bListBasePtr *getKey();
bListBasePtr *getWorld();
bListBasePtr *getScreen();
bListBasePtr *getScript();
bListBasePtr *getVfont();
bListBasePtr *getText();
bListBasePtr *getSound();
bListBasePtr *getGroup();
bListBasePtr *getArmature();
bListBasePtr *getAction();
bListBasePtr *getNodetree();
bListBasePtr *getBrush();
// tracking allocated memory
void addDatablock(void *allocated);
// --
void linkList(void *listBasePtr);
};
}
#endif//__BMAIN_H__

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src
)
ADD_LIBRARY(
BulletFileLoader
bChunk.cpp
bChunk.h
bCommon.h
bDefines.h
bDNA.cpp
bDNA.h
bFile.cpp
bFile.h
btBulletFile.cpp
btBulletFile.h
)

View File

@@ -0,0 +1,32 @@
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
#ifndef __BULLET_H__
#define __BULLET_H__
#include "bullet_PointerArray.h"
#include "bullet_btPhysicsSystem.h"
#include "bullet_ListBase.h"
#include "bullet_btVector3Data.h"
#include "bullet_btMatrix3x3Data.h"
#include "bullet_btTransformData.h"
#include "bullet_btCollisionShapeData.h"
#include "bullet_btConvexInternalShapeData.h"
#include "bullet_btCollisionObjectData.h"
#include "bullet_btRigidBodyData.h"
#endif//__BULLET_H__

View File

@@ -0,0 +1,40 @@
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
#ifndef __BULLETCOMMON_H__
#define __BULLETCOMMON_H__
// put an empty struct in the case
typedef struct bInvalidHandle {
int unused;
}bInvalidHandle;
namespace Bullet {
class PointerArray;
class btPhysicsSystem;
class ListBase;
class btVector3Data;
class btMatrix3x3Data;
class btTransformData;
class btCollisionShapeData;
class btConvexInternalShapeData;
class btCollisionObjectData;
class btRigidBodyData;
}
#endif//__BULLETCOMMON_H__

View File

@@ -0,0 +1,40 @@
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
#ifndef __BULLET_LISTBASE__H__
#define __BULLET_LISTBASE__H__
// -------------------------------------------------- //
#include "bullet_Common.h"
namespace Bullet {
// ---------------------------------------------- //
class ListBase
{
public:
void *first;
void *last;
};
}
#endif//__BULLET_LISTBASE__H__

View File

@@ -0,0 +1,41 @@
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
#ifndef __BULLET_POINTERARRAY__H__
#define __BULLET_POINTERARRAY__H__
// -------------------------------------------------- //
#include "bullet_Common.h"
namespace Bullet {
// ---------------------------------------------- //
class PointerArray
{
public:
int m_size;
int m_capacity;
void *m_data;
};
}
#endif//__BULLET_POINTERARRAY__H__

View File

@@ -0,0 +1,63 @@
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
#ifndef __BULLET_BTCOLLISIONOBJECTDATA__H__
#define __BULLET_BTCOLLISIONOBJECTDATA__H__
// -------------------------------------------------- //
#include "bullet_Common.h"
#include "bullet_btTransformData.h"
#include "bullet_btVector3Data.h"
namespace Bullet {
// ---------------------------------------------- //
class btCollisionObjectData
{
public:
btTransformData m_worldTransform;
btTransformData m_interpolationWorldTransform;
btVector3Data m_interpolationLinearVelocity;
btVector3Data m_interpolationAngularVelocity;
btVector3Data m_anisotropicFriction;
int m_hasAnisotropicFriction;
btScalar m_contactProcessingThreshold;
void *m_broadphaseHandle;
void *m_collisionShape;
btCollisionShapeData *m_rootCollisionShape;
int m_collisionFlags;
int m_islandTag1;
int m_companionId;
int m_activationState1;
btScalar m_deactivationTime;
btScalar m_friction;
btScalar m_restitution;
int m_internalType;
void *m_userObjectPointer;
btScalar m_hitFraction;
btScalar m_ccdSweptSphereRadius;
btScalar m_ccdMotionThreshold;
int m_checkCollideWith;
};
}
#endif//__BULLET_BTCOLLISIONOBJECTDATA__H__

View File

@@ -0,0 +1,41 @@
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
#ifndef __BULLET_BTCOLLISIONSHAPEDATA__H__
#define __BULLET_BTCOLLISIONSHAPEDATA__H__
// -------------------------------------------------- //
#include "bullet_Common.h"
namespace Bullet {
// ---------------------------------------------- //
class btCollisionShapeData
{
public:
void *m_userPointer;
int m_shapeType;
char m_padding[4];
};
}
#endif//__BULLET_BTCOLLISIONSHAPEDATA__H__

View File

@@ -0,0 +1,45 @@
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
#ifndef __BULLET_BTCONVEXINTERNALSHAPEDATA__H__
#define __BULLET_BTCONVEXINTERNALSHAPEDATA__H__
// -------------------------------------------------- //
#include "bullet_Common.h"
#include "bullet_btCollisionShapeData.h"
#include "bullet_btVector3Data.h"
namespace Bullet {
// ---------------------------------------------- //
class btConvexInternalShapeData
{
public:
btCollisionShapeData m_collisionShapeData;
btVector3Data m_localScaling;
btVector3Data m_implicitShapeDimensions;
btScalar m_collisionMargin;
char m_padding[4];
};
}
#endif//__BULLET_BTCONVEXINTERNALSHAPEDATA__H__

View File

@@ -0,0 +1,40 @@
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
#ifndef __BULLET_BTMATRIX3X3DATA__H__
#define __BULLET_BTMATRIX3X3DATA__H__
// -------------------------------------------------- //
#include "bullet_Common.h"
#include "bullet_btVector3Data.h"
namespace Bullet {
// ---------------------------------------------- //
class btMatrix3x3Data
{
public:
btVector3Data m_el[3];
};
}
#endif//__BULLET_BTMATRIX3X3DATA__H__

View File

@@ -0,0 +1,42 @@
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
#ifndef __BULLET_BTPHYSICSSYSTEM__H__
#define __BULLET_BTPHYSICSSYSTEM__H__
// -------------------------------------------------- //
#include "bullet_Common.h"
#include "bullet_PointerArray.h"
namespace Bullet {
// ---------------------------------------------- //
class btPhysicsSystem
{
public:
PointerArray m_collisionShapes;
PointerArray m_collisionObjects;
PointerArray m_constraints;
};
}
#endif//__BULLET_BTPHYSICSSYSTEM__H__

View File

@@ -0,0 +1,62 @@
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
#ifndef __BULLET_BTRIGIDBODYDATA__H__
#define __BULLET_BTRIGIDBODYDATA__H__
// -------------------------------------------------- //
#include "bullet_Common.h"
#include "bullet_btCollisionObjectData.h"
#include "bullet_btMatrix3x3Data.h"
#include "bullet_btVector3Data.h"
namespace Bullet {
// ---------------------------------------------- //
class btRigidBodyData
{
public:
btCollisionObjectData m_collisionObjectData;
btMatrix3x3Data m_invInertiaTensorWorld;
btVector3Data m_linearVelocity;
btVector3Data m_angularVelocity;
btScalar m_inverseMass;
btVector3Data m_angularFactor;
btVector3Data m_linearFactor;
btVector3Data m_gravity;
btVector3Data m_gravity_acceleration;
btVector3Data m_invInertiaLocal;
btVector3Data m_totalForce;
btVector3Data m_totalTorque;
btScalar m_linearDamping;
btScalar m_angularDamping;
int m_additionalDamping;
btScalar m_additionalDampingFactor;
btScalar m_additionalLinearDampingThresholdSqr;
btScalar m_additionalAngularDampingThresholdSqr;
btScalar m_additionalAngularDampingFactor;
btScalar m_linearSleepingThreshold;
btScalar m_angularSleepingThreshold;
};
}
#endif//__BULLET_BTRIGIDBODYDATA__H__

View File

@@ -0,0 +1,42 @@
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
#ifndef __BULLET_BTTRANSFORMDATA__H__
#define __BULLET_BTTRANSFORMDATA__H__
// -------------------------------------------------- //
#include "bullet_Common.h"
#include "bullet_btMatrix3x3Data.h"
#include "bullet_btVector3Data.h"
namespace Bullet {
// ---------------------------------------------- //
class btTransformData
{
public:
btMatrix3x3Data m_basis;
btVector3Data m_origin;
};
}
#endif//__BULLET_BTTRANSFORMDATA__H__

View File

@@ -0,0 +1,39 @@
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
#ifndef __BULLET_BTVECTOR3DATA__H__
#define __BULLET_BTVECTOR3DATA__H__
// -------------------------------------------------- //
#include "bullet_Common.h"
namespace Bullet {
// ---------------------------------------------- //
class btVector3Data
{
public:
btScalar m_floats[4];
};
}
#endif//__BULLET_BTVECTOR3DATA__H__

View File

@@ -1,6 +1,6 @@
/*
bParse
Copyright (c) 2006-2010 Charlie C & Erwin Coumans http://gamekit.googlecode.com
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.

View File

@@ -1,6 +1,6 @@
/*
bParse
Copyright (c) 2006-2010 Charlie C & Erwin Coumans http://gamekit.googlecode.com
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.

View File

@@ -1,6 +1,6 @@
/*
bParse
Copyright (c) 2006-2010 Charlie C & Erwin Coumans http://gamekit.googlecode.com
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.

View File

@@ -1,6 +1,6 @@
/*
bParse
Copyright (c) 2006-2010 Charlie C & Erwin Coumans http://gamekit.googlecode.com
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.

View File

@@ -1,6 +1,6 @@
/*
bParse
Copyright (c) 2006-2010 Charlie C & Erwin Coumans http://gamekit.googlecode.com
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2006-2010 Charlie C & Erwin Coumans http://gamekit.googlecode.com
/* Copyright (C) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages

View File

@@ -1,6 +1,6 @@
/*
bParse
Copyright (c) 2006-2010 Charlie C & Erwin Coumans http://gamekit.googlecode.com
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
@@ -417,7 +417,7 @@ static void getElement(int arrayLen, const char *cur, const char *old, char *old
#define setEle(value, current, type, cast, size, ptr)\
if (strcmp(current, type)==0)\
{\
(*(cast*)ptr) = (cast)value;\
(*(cast*)ptr) = value;\
ptr += size;\
}
double value = 0.0;
@@ -438,8 +438,6 @@ static void getElement(int arrayLen, const char *cur, const char *old, char *old
setEle(value, cur, "float", float, sizeof(float), curData);
getEle(value, old, "double", double, sizeof(double), oldPtr);
setEle(value, cur, "double", double, sizeof(double), curData);
getEle(value, old, "btScalar", btScalar, sizeof(btScalar), oldPtr);
setEle(value, cur, "btScalar", btScalar, sizeof(btScalar), curData);
}
}

View File

@@ -1,6 +1,6 @@
/*
bParse
Copyright (c) 2006-2010 Charlie C & Erwin Coumans http://gamekit.googlecode.com
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.

View File

@@ -0,0 +1,252 @@
/*
bParse
Copyright (c) 2006-2010 Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "btBulletFile.h"
#include "bDefines.h"
#include "bDNA.h"
#include <string.h>
// 32 && 64 bit versions
extern unsigned char sBulletDNAstr[];
extern int sBulletDNAlen;
//not yetto. extern unsigned char DNAstr64[];
//not yetto. extern int DNAlen64;
using namespace bParse;
btBulletFile::btBulletFile()
:bFile("", "BULLET ")
{
mMemoryDNA = new bDNA();
mMemoryDNA->init((char*)sBulletDNAstr,sBulletDNAlen);
}
btBulletFile::btBulletFile(const char* fileName)
:bFile(fileName, "BULLET ")
{
}
btBulletFile::btBulletFile(char *memoryBuffer, int len)
:bFile(memoryBuffer,len, "BULLET ")
{
}
btBulletFile::~btBulletFile()
{
}
// ----------------------------------------------------- //
void btBulletFile::parseData()
{
printf ("Building datablocks");
printf ("Chunk size = %d",CHUNK_HEADER_LEN);
printf ("File chunk size = %d",ChunkUtils::getOffset(mFlags));
const bool swap = (mFlags&FD_ENDIAN_SWAP)!=0;
mDataStart = 12;
char *dataPtr = mFileBuffer+mDataStart;
bChunkInd dataChunk;
dataChunk.code = 0;
//dataPtr += ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags);
int seek = ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags);
//dataPtr += ChunkUtils::getOffset(mFlags);
char *dataPtrHead = 0;
while (dataChunk.code != DNA1)
{
// one behind
if (dataChunk.code == SDNA) break;
//if (dataChunk.code == DNA1) break;
// same as (BHEAD+DATA dependancy)
dataPtrHead = dataPtr+ChunkUtils::getOffset(mFlags);
char *id = readStruct(dataPtrHead, dataChunk);
// lookup maps
if (id)
{
mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)id);
m_chunks.push_back(dataChunk);
// block it
//bListBasePtr *listID = mMain->getListBasePtr(dataChunk.code);
//if (listID)
// listID->push_back((bStructHandle*)id);
}
if (dataChunk.code == BT_RIGIDBODY_CODE)
{
m_rigidBodies.push_back((bStructHandle*) id);
}
if (dataChunk.code == BT_COLLISIONOBJECT_CODE)
{
m_collisionObjects.push_back((bStructHandle*) id);
}
if (dataChunk.code == BT_SHAPE_CODE)
{
m_collisionShapes.push_back((bStructHandle*) id);
}
// if (dataChunk.code == GLOB)
// {
// m_glob = (bStructHandle*) id;
// }
// next please!
dataPtr += seek;
seek = ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags);
if (seek < 0)
break;
}
}
void btBulletFile::addDataBlock(char* dataBlock)
{
//mMain->addDatablock(dataBlock);
}
void btBulletFile::writeDNA(FILE* fp)
{
bChunkInd dataChunk;
dataChunk.code = DNA1;
dataChunk.dna_nr = 0;
dataChunk.nr = 1;
if (VOID_IS_8)
{
//dataChunk.len = DNAlen64;
//dataChunk.oldPtr = DNAstr64;
//fwrite(&dataChunk,sizeof(bChunkInd),1,fp);
//fwrite(DNAstr64, DNAlen64,1,fp);
}
else
{
dataChunk.len = sBulletDNAlen;
dataChunk.oldPtr = sBulletDNAstr;
fwrite(&dataChunk,sizeof(bChunkInd),1,fp);
fwrite(sBulletDNAstr, sBulletDNAlen,1,fp);
}
}
void btBulletFile::parse(bool verboseDumpAllTypes)
{
if (VOID_IS_8)
{
exit(0);
//parseInternal(verboseDumpAllTypes,(char*)DNAstr64,DNAlen64);
}
else
{
parseInternal(verboseDumpAllTypes,(char*)sBulletDNAstr,sBulletDNAlen);
}
}
// experimental
int btBulletFile::write(const char* fileName, bool fixupPointers)
{
FILE *fp = fopen(fileName, "wb");
if (fp)
{
char header[SIZEOFBLENDERHEADER] ;
memcpy(header, m_headerString, 7);
int endian= 1;
endian= ((char*)&endian)[0];
if (endian)
{
header[7] = '_';
} else
{
header[7] = '-';
}
if (VOID_IS_8)
{
header[8]='V';
} else
{
header[8]='v';
}
header[9] = '2';
header[10] = '7';
header[11] = '5';
fwrite(header,SIZEOFBLENDERHEADER,1,fp);
writeChunks(fp, fixupPointers);
writeDNA(fp);
fclose(fp);
} else
{
printf("Error: cannot open file %s for writing\n",fileName);
return 0;
}
return 1;
}
void btBulletFile::addStruct(const char* structType,void* data, int len, void* oldPtr, int code)
{
bParse::bChunkInd dataChunk;
dataChunk.code = code;
dataChunk.nr = 1;
dataChunk.len = len;
dataChunk.dna_nr = mMemoryDNA->getReverseType(structType);
dataChunk.oldPtr = oldPtr;
///Perform structure size validation
short* structInfo= mMemoryDNA->getStruct(dataChunk.dna_nr);
int elemBytes = mMemoryDNA->getLength(structInfo[0]);
// int elemBytes = mMemoryDNA->getElementSize(structInfo[0],structInfo[1]);
assert(len==elemBytes);
mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)data);
m_chunks.push_back(dataChunk);
}

View File

@@ -0,0 +1,72 @@
/*
bParse
Copyright (c) 2006-2010 Charlie C & Erwin Coumans http://gamekit.googlecode.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BT_BULLET_FILE_H
#define BT_BULLET_FILE_H
#include "bFile.h"
#include "LinearMath/btAlignedObjectArray.h"
#include "bDefines.h"
#define BT_COLLISIONOBJECT_CODE MAKE_ID('C','O','B','J')
#define BT_RIGIDBODY_CODE MAKE_ID('R','B','D','Y')
#define BT_BOXSHAPE_CODE MAKE_ID('B','O','X','S')
#define BT_SHAPE_CODE MAKE_ID('S','H','A','P')
namespace bParse {
// ----------------------------------------------------- //
class btBulletFile : public bFile
{
protected:
public:
btAlignedObjectArray<bStructHandle*> m_rigidBodies;
btAlignedObjectArray<bStructHandle*> m_collisionObjects;
btAlignedObjectArray<bStructHandle*> m_collisionShapes;
btBulletFile();
btBulletFile(const char* fileName);
btBulletFile(char *memoryBuffer, int len);
virtual ~btBulletFile();
virtual void addDataBlock(char* dataBlock);
// experimental
virtual int write(const char* fileName, bool fixupPointers=false);
virtual void parse(bool verboseDumpAllTypes);
virtual void parseData();
virtual void writeDNA(FILE* fp);
void addStruct(const char* structType,void* data, int len, void* oldPtr, int code);
};
};
#endif //BT_BULLET_FILE_H

View File

@@ -0,0 +1,9 @@
SUBDIRS ( BulletSerialize )
# makesdna and HeaderGenerator are for advanced use only
# makesdna can re-generate the binary DNA representing the Bullet serialization structures
# Be very careful modifying any of this, otherwise the .bullet format becomes incompatible
#SUBDIRS ( BulletFileLoader BlenderSerialize HeaderGenerator makesdna)

View File

@@ -0,0 +1,23 @@
###############################################################################
PROJECT(GEN)
FILE(GLOB cpp_SRC "*.cpp")
FILE(GLOB h_SRC "*.h")
SET(includes
.
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BlenderSerialize
${BULLET_PHYSICS_SOURCE_DIR}/src
)
LINK_LIBRARIES(
BulletFileLoader BlenderSerialize LinearMath
)
INCLUDE_DIRECTORIES(${includes})
SET(Main_LIBS LinearMath)
ADD_EXECUTABLE(HeaderGenerator ${cpp_SRC} ${h_SRC})

View File

@@ -0,0 +1,463 @@
/* Copyright (C) 2006 Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <sstream>
#include "bDNA.h"
#include "bBlenderFile.h"
#include "btBulletFile.h"
#include "bCommon.h"
#include <map>
#include <vector>
bool isBulletFile = false;
using namespace bParse;
typedef std::string bString;
///////////////////////////////////////////////////////////////////////////////
typedef std::map<bString, bString> bStringMap;
typedef std::vector<class bVariable> bVariableList;
typedef std::vector<bString> bStringList;
///////////////////////////////////////////////////////////////////////////////
static FILE *dump = 0;
static bDNA *mDNA =0;
static bStringMap mStructs;
///////////////////////////////////////////////////////////////////////////////
class bVariable
{
public:
bVariable();
~bVariable();
bString dataType;
bString variableName;
bString functionName;
bString classCtor;
bString memberVariable;
bString memberDataType;
bString functionArgs;
void initialize(bString dataType, bString variable, bStringMap refDataTable);
bool isPtr;
bool isFunctionPtr;
bool isPtrToPtr;
bool isArray;
bool isCharArray;
bool isListBase;
bool isPadding;
bool isCommentedOut;
bool isGeneratedType;
bool isbString;
};
///////////////////////////////////////////////////////////////////////////////
bool dataTypeStandard(bString dataType)
{
if (dataType == "char")
return true;
if (dataType == "short")
return true;
if (dataType == "int")
return true;
if (dataType == "long")
return true;
if (dataType == "float")
return true;
if (dataType == "double")
return true;
if (dataType == "void")
return true;
if (dataType == "btScalar")
return true;
return false;
}
///////////////////////////////////////////////////////////////////////////////
void writeTemplate(short *structData)
{
bString type = mDNA->getType(structData[0]);
bString className=type;
bString prefix = isBulletFile? "bullet_" : "blender_";
int thisLen = structData[1];
structData+=2;
bString fileName = prefix+type;
bVariableList dataTypes;
bStringMap includeFiles;
for (int dataVal =0; dataVal<thisLen; dataVal++, structData+=2)
{
bString dataType = mDNA->getType(structData[0]);
bString dataName = mDNA->getName(structData[1]);
{
bString newDataType = "";
bString newDataName = "";
bStringMap::iterator addB = mStructs.find(dataType);
if (addB != mStructs.end())
{
newDataType = addB->second;
newDataName = dataName;
}
else
{
if (dataTypeStandard(dataType))
{
newDataType = dataType;
newDataName = dataName;
}
else
{
// Unresolved
// set it to an empty struct
// if it's not a ptr generate an error
newDataType = "bInvalidHandle";
newDataName = dataName;
if (dataName[0] != '*')
{
}
}
}
if (!newDataType.empty() && !newDataName.empty())
{
bVariable var = bVariable();
var.initialize(newDataType, newDataName, mStructs);
dataTypes.push_back(var);
}
}
bStringMap::iterator include = mStructs.find(dataType);
if (include != mStructs.end())
{
if (dataName[0] != '*')
{
if (includeFiles.find(dataType)== includeFiles.end())
{
includeFiles[dataType]=prefix+dataType;
}
}
}
}
fprintf(dump, "###############################################################\n");
fprintf(dump, "%s = bStructClass()\n", fileName.c_str());
fprintf(dump, "%s.name = '%s'\n", fileName.c_str(), className.c_str());
fprintf(dump, "%s.filename = '%s'\n", fileName.c_str(), fileName.c_str());
bVariableList::iterator vars = dataTypes.begin();
while (vars!= dataTypes.end())
{
fprintf(dump, "%s.dataTypes.append('%s %s')\n", fileName.c_str(), vars->dataType.c_str(), vars->variableName.c_str());
vars++;
}
bStringMap::iterator inc = includeFiles.begin();
while (inc != includeFiles.end())
{
fprintf(dump, "%s.includes.append('%s.h')\n", fileName.c_str(), inc->second.c_str());
inc++;
}
fprintf(dump, "DataTypeList.append(%s)\n", fileName.c_str());
}
///////////////////////////////////////////////////////////////////////////////
char data[]={
"\n"
"class bStructClass:\n"
" def __init__(self):\n"
" self.name = \"\";\n"
" self.filename = \"\";\n"
" self.includes = []\n"
" self.dataTypes = []\n"
"\n\n"
"DataTypeList = []\n"
};
///////////////////////////////////////////////////////////////////////////////
int main(int argc,char** argv)
{
using namespace bParse;
dump = fopen("dump.py", "w");
if (!dump) return 0;
fprintf(dump, "%s\n", data);
char* filename = "../../../Demos/SerializeDemo/testFile.bullet";
if (argc==2)
filename = argv[1];
bString fileStr(filename);
bString extension(".bullet");
int index2 = fileStr.find(extension);
if (index2>=0)
isBulletFile=true;
FILE* fp = fopen (filename,"rb");
if (!fp)
{
printf("error: file not found %s\n",filename);
exit(0);
}
char* memBuf = 0;
int len = 0;
long currentpos = ftell(fp); /* save current cursor position */
long newpos;
int bytesRead;
fseek(fp, 0, SEEK_END); /* seek to end */
newpos = ftell(fp); /* find position of end -- this is the length */
fseek(fp, currentpos, SEEK_SET); /* restore previous cursor position */
len = newpos;
memBuf = (char*)malloc(len);
bytesRead = fread(memBuf,len,1,fp);
bool swap = false;
if (isBulletFile)
{
btBulletFile f(memBuf,len);
swap = f.getFlags() & FD_ENDIAN_SWAP;
} else
{
bBlenderFile f(memBuf,len);
swap = f.getFlags() & FD_ENDIAN_SWAP;
}
char *blenderData = memBuf;
int sdnaPos=0;
int mDataStart = 12;
char *tempBuffer = blenderData;
for (int i=0; i<len; i++)
{
// looking for the data's starting position
// and the start of SDNA decls
if (!mDataStart && strncmp(tempBuffer, "REND", 4)==0)
mDataStart = i;
if (!sdnaPos && strncmp(tempBuffer, "SDNA", 4)==0)
sdnaPos = i;
if (mDataStart && sdnaPos) break;
tempBuffer++;
}
FILE* fpdna = fopen("dnaString.txt","w");
char buf[1024];
for (int i=0;i<len-sdnaPos;i++)
{
int dnaval = (memBuf+sdnaPos)[i];
if ((i%32)==0)
{
sprintf(buf,"%d,\n",dnaval);
} else
{
sprintf(buf,"%d,",dnaval);
}
fwrite(buf,strlen(buf),1,fpdna);
}
fclose(fpdna);
mDNA = new bDNA();
//mDNA->initMemory();
mDNA->init(memBuf+sdnaPos, len-sdnaPos, swap);
for (int i=0; i<mDNA->getNumStructs(); i++)
{
short *structData = mDNA->getStruct(i);
bString type = mDNA->getType(structData[0]);
bString className = type;
mStructs[type]=className;
}
for (int i=0; i<mDNA->getNumStructs(); i++)
{
short *structData = mDNA->getStruct(i);
writeTemplate(structData);
}
delete mDNA;
fclose(dump);
return 0;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
int _getArraySize(char* str)
{
int a, mul=1;
char stri[100], *cp=0;
int len = (int)strlen(str);
memcpy(stri, str, len+1);
for (a=0; a<len; a++)
{
if (str[a]== '[')
cp= &(stri[a+1]);
else if ( str[a]==']' && cp)
{
stri[a]= 0;
mul*= atoi(cp);
}
}
return mul;
}
///////////////////////////////////////////////////////////////////////////////
bVariable::bVariable()
: dataType("invalid"),
variableName("invalid"),
functionName(""),
classCtor(""),
memberVariable(""),
memberDataType(""),
functionArgs(""),
isPtr(false),
isFunctionPtr(false),
isPtrToPtr(false),
isArray(false),
isCharArray(false),
isListBase(false),
isPadding(false),
isCommentedOut(false),
isGeneratedType(false),
isbString(false)
{
}
///////////////////////////////////////////////////////////////////////////////
bVariable::~bVariable()
{
dataType.clear();
variableName.clear();
}
///////////////////////////////////////////////////////////////////////////////
void bVariable::initialize(bString type, bString variable, bStringMap refDataTable)
{
dataType = type;
variableName = variable;
if (variableName[0] == '*')
{
isPtr = true;
if (variableName[1] == '*')
isPtrToPtr = true;
}
if (variableName[0] == '(')
if (variableName[1] == '*')
isFunctionPtr = true;
if (variableName[variableName.size()-1] == ']')
{
isArray = true;
if (type == "char")
isCharArray = true;
}
if (type == "ListBase")
isListBase = true;
if (variableName[0] == 'p')
{
bString sub = variableName.substr(0,3);
if (sub == "pad")
isPadding = true;
}
if (dataType[0] == '/' && dataType[1] == '/')
isCommentedOut = true;
if (refDataTable.find(dataType) != refDataTable.end())
isGeneratedType = true;
if (!isBulletFile)
{
// replace valid float arrays
if (dataType == "float" && isArray)
{
int size = _getArraySize((char*)variableName.c_str());
if (size==3)
{
dataType = "vec3f";
variableName = variableName.substr(0, variableName.find_first_of("["));
}
if (size==4)
{
dataType = "vec4f";
variableName = variableName.substr(0, variableName.find_first_of("["));
}
}
}
memberDataType = dataType;
functionArgs = variableName;
}
// eof

View File

@@ -0,0 +1,111 @@
import dump
header = """/* Copyright (C) 2006 Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
"""
dtList = dump.DataTypeList
out = "../BlenderSerialize/autogenerated/"
spaces = 4
def addSpaces(file, space):
for i in range(0, space):
file.write(" ")
def write(file, spaces, string):
addSpaces(file, spaces)
file.write(string)
###################################################################################
blender = open(out+"blender.h", 'w')
blender.write(header)
blender.write("#ifndef __BLENDER_H__\n")
blender.write("#define __BLENDER_H__\n")
for dt in dtList:
blender.write("#include \"%s.h\"\n"%dt.filename)
blender.write("#endif//__BLENDER_H__")
blender.close()
###################################################################################
blenderC = open(out+"blender_Common.h", 'w')
blenderC.write(header)
blenderC.write("#ifndef __BLENDERCOMMON_H__\n")
blenderC.write("#define __BLENDERCOMMON_H__\n")
strUnRes = """
// put an empty struct in the case
typedef struct bInvalidHandle {
int unused;
}bInvalidHandle;
"""
blenderC.write(strUnRes)
blenderC.write("namespace Blender {\n")
for dt in dtList:
write(blenderC, 4, "class %s;\n"%dt.name)
blenderC.write("}\n")
blenderC.write("#endif//__BLENDERCOMMON_H__")
blenderC.close()
for dt in dtList:
fp = open(out+dt.filename+".h", 'w')
fp.write(header)
strUpper = dt.filename.upper()
fp.write("#ifndef __%s__H__\n"%strUpper)
fp.write("#define __%s__H__\n"%strUpper)
fp.write("\n\n")
fp.write("// -------------------------------------------------- //\n")
fp.write("#include \"blender_Common.h\"\n")
for i in dt.includes:
fp.write("#include \"%s\"\n"%i)
fp.write("\nnamespace Blender {\n")
fp.write("\n\n")
addSpaces(fp,4)
fp.write("// ---------------------------------------------- //\n")
write(fp, 4, "class %s\n"%dt.name)
write(fp, 4, "{\n")
write(fp, 4, "public:\n")
for i in dt.dataTypes:
write(fp, 8, i+";\n")
write(fp, 4, "};\n")
fp.write("}\n")
fp.write("\n\n")
fp.write("#endif//__%s__H__\n"%strUpper)
fp.close()

View File

@@ -0,0 +1,111 @@
import dump
header = """/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// Auto generated from makesdna dna.c
"""
dtList = dump.DataTypeList
out = "../BulletFileLoader/autogenerated/"
spaces = 4
def addSpaces(file, space):
for i in range(0, space):
file.write(" ")
def write(file, spaces, string):
addSpaces(file, spaces)
file.write(string)
###################################################################################
blender = open(out+"bullet.h", 'w')
blender.write(header)
blender.write("#ifndef __BULLET_H__\n")
blender.write("#define __BULLET_H__\n")
for dt in dtList:
blender.write("#include \"%s.h\"\n"%dt.filename)
blender.write("#endif//__BULLET_H__")
blender.close()
###################################################################################
blenderC = open(out+"bullet_Common.h", 'w')
blenderC.write(header)
blenderC.write("#ifndef __BULLETCOMMON_H__\n")
blenderC.write("#define __BULLETCOMMON_H__\n")
strUnRes = """
// put an empty struct in the case
typedef struct bInvalidHandle {
int unused;
}bInvalidHandle;
"""
blenderC.write(strUnRes)
blenderC.write("namespace Bullet {\n")
for dt in dtList:
write(blenderC, 4, "class %s;\n"%dt.name)
blenderC.write("}\n")
blenderC.write("#endif//__BULLETCOMMON_H__")
blenderC.close()
for dt in dtList:
fp = open(out+dt.filename+".h", 'w')
fp.write(header)
strUpper = dt.filename.upper()
fp.write("#ifndef __%s__H__\n"%strUpper)
fp.write("#define __%s__H__\n"%strUpper)
fp.write("\n\n")
fp.write("// -------------------------------------------------- //\n")
fp.write("#include \"bullet_Common.h\"\n")
for i in dt.includes:
fp.write("#include \"%s\"\n"%i)
fp.write("\nnamespace Bullet {\n")
fp.write("\n\n")
addSpaces(fp,4)
fp.write("// ---------------------------------------------- //\n")
write(fp, 4, "class %s\n"%dt.name)
write(fp, 4, "{\n")
write(fp, 4, "public:\n")
for i in dt.dataTypes:
write(fp, 8, i+";\n")
write(fp, 4, "};\n")
fp.write("}\n")
fp.write("\n\n")
fp.write("#endif//__%s__H__\n"%strUpper)
fp.close()

View File

@@ -0,0 +1,3 @@
Debug\HeaderGenerator.exe
python bulletGenerate.py

View File

@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 2.4)
IF(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
ENDIF(COMMAND cmake_policy)
INCLUDE_DIRECTORIES(${BULLET_PHYSICS_SOURCE_DIR}/src )
#FILE(GLOB INC_FILES ../*.h)
SET (INC_FILES
DNA_rigidbody.h
${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btVector3.h
${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btMatrix3x3.h
${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btTransform.h
${BULLET_PHYSICS_SOURCE_DIR}/src/BulletCollision/CollisionShapes/btCollisionShape.h
${BULLET_PHYSICS_SOURCE_DIR}/src/BulletCollision/CollisionShapes/btConvexInternalShape.h
${BULLET_PHYSICS_SOURCE_DIR}/src/BulletCollision/CollisionDispatch/btCollisionObject.h
)
# Build makesdna executable
SET(SRC makesdna.cpp)
ADD_EXECUTABLE(makesdna ${SRC} ${INC_FILES})
# Output BulletDNA.c
ADD_CUSTOM_COMMAND(
OUTPUT ${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btSerializer.cpp
COMMAND ${CMAKE_CFG_INTDIR}/makesdna ${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btSerializer.cpp ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/CommonSerialize/
DEPENDS makesdna
)
# Build bf_dna library
SET(SRC ${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btSerializer.cpp)
ADD_LIBRARY(BulletDNA ${SRC} ${INC_FILES})
MESSAGE(STATUS "Configuring makesdna")

View File

@@ -0,0 +1,29 @@
#ifndef DNA_RIGIDBODY_H
#define DNA_RIGIDBODY_H
struct PointerArray
{
int m_size;
int m_capacity;
void *m_data;
};
struct btPhysicsSystem
{
PointerArray m_collisionShapes;
PointerArray m_collisionObjects;
PointerArray m_constraints;
};
///we need this to compute the pointer sizes
struct ListBase
{
void *first;
void *last;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1252,6 +1252,28 @@ void btCollisionWorld::serializeCollisionObjects(btDefaultSerializer* serializer
chunk->m_oldPtr = colObj;
}
}
///keep track of shapes already serialized
btHashMap<btHashPtr,btCollisionShape*> serializedShapes;
for (i=0;i<m_collisionObjects.size();i++)
{
btCollisionObject* colObj = m_collisionObjects[i];
btCollisionShape* shape = colObj->getCollisionShape();
if (!serializedShapes.find(shape))
{
serializedShapes.insert(shape,shape);
//serialize all collision shapes
int len = shape->calculateSerializeBufferSize();
btChunk* chunk = serializer->allocate(len,1);
const char* structType = shape->serialize(chunk->m_oldPtr);
chunk->m_dna_nr = serializer->getReverseType(structType);
chunk->m_chunkCode = BT_SHAPE_CODE;
chunk->m_oldPtr = shape;
}
}
}
@@ -1273,18 +1295,6 @@ void btCollisionWorld::serialize(btDefaultSerializer* serializer)
serializeCollisionObjects(serializer);
#if 0
{
//serialize all collision shapes
int len = boxShape->calculateSerializeBufferSize();
btChunk* chunk = serializer->allocate(len,1);
const char* structType = boxShape->serialize(chunk->m_oldPtr);
chunk->m_dna_nr = serializer->getReverseType(structType);
chunk->m_chunkCode = BT_BOXSHAPE_CODE;
chunk->m_oldPtr = boxShape;
}
#endif
serializer->writeDNA();
}

View File

@@ -310,43 +310,9 @@ public:
}
}
virtual int calculateSerializeBufferSize();
///fills the dataBuffer and returns the struct name (and 0 on failure)
virtual const char* serialize(void* dataBuffer) const;
};
struct btBoxShapeData
{
btCollisionShapeData m_collisionShapeData;
btVector3Data m_halfExtents;
btVector3Data m_localScaling;
};
SIMD_FORCE_INLINE int btBoxShape::calculateSerializeBufferSize()
{
return sizeof(btBoxShapeData);
}
///fills the dataBuffer and returns the struct name (and 0 on failure)
SIMD_FORCE_INLINE const char* btBoxShape::serialize(void* dataBuffer) const
{
btBoxShapeData* boxData = (btBoxShapeData*) dataBuffer;
btCollisionShape::serialize(&boxData->m_collisionShapeData);
m_implicitShapeDimensions.serialize(boxData->m_halfExtents);
m_localScaling.serialize(boxData->m_localScaling);
return "btBoxShapeData";
}
#endif //OBB_BOX_MINKOWSKI_H

View File

@@ -109,11 +109,54 @@ public:
btAssert(0);
}
virtual int calculateSerializeBufferSize();
///fills the dataBuffer and returns the struct name (and 0 on failure)
virtual const char* serialize(void* dataBuffer) const;
};
struct btConvexInternalShapeData
{
btCollisionShapeData m_collisionShapeData;
btVector3Data m_localScaling;
btVector3Data m_implicitShapeDimensions;
btScalar m_collisionMargin;
char m_padding[4];
};
SIMD_FORCE_INLINE int btConvexInternalShape::calculateSerializeBufferSize()
{
return sizeof(btConvexInternalShapeData);
}
///fills the dataBuffer and returns the struct name (and 0 on failure)
SIMD_FORCE_INLINE const char* btConvexInternalShape::serialize(void* dataBuffer) const
{
btConvexInternalShapeData* shapeData = (btConvexInternalShapeData*) dataBuffer;
btCollisionShape::serialize(&shapeData->m_collisionShapeData);
m_implicitShapeDimensions.serialize(shapeData->m_implicitShapeDimensions);
m_localScaling.serialize(shapeData->m_localScaling);
shapeData->m_collisionMargin = m_collisionMargin;
return "btConvexInternalShapeData";
}
///btConvexInternalAabbCachingShape adds local aabb caching for convex shapes, to avoid expensive bounding box calculations
class btConvexInternalAabbCachingShape : public btConvexInternalShape
{

View File

@@ -1,90 +1,91 @@
unsigned char sBulletDNAstr[]= {
83,68,78,65,78,65,77,69,65,0,0,0,109,95,115,105,122,101,0,109,
83,68,78,65,78,65,77,69,63,0,0,0,109,95,115,105,122,101,0,109,
95,99,97,112,97,99,105,116,121,0,42,109,95,100,97,116,97,0,109,95,
99,111,108,108,105,115,105,111,110,83,104,97,112,101,115,0,109,95,99,111,
108,108,105,115,105,111,110,79,98,106,101,99,116,115,0,109,95,99,111,110,
115,116,114,97,105,110,116,115,0,42,102,105,114,115,116,0,42,108,97,115,
116,0,109,95,102,108,111,97,116,115,91,52,93,0,121,97,119,0,112,105,
116,99,104,0,114,111,108,108,0,109,95,101,108,91,51,93,0,109,95,98,
97,115,105,115,0,109,95,111,114,105,103,105,110,0,42,109,95,117,115,101,
114,80,111,105,110,116,101,114,0,109,95,115,104,97,112,101,84,121,112,101,
0,109,95,112,97,100,100,105,110,103,91,52,93,0,109,95,99,111,108,108,
105,115,105,111,110,83,104,97,112,101,68,97,116,97,0,109,95,104,97,108,
102,69,120,116,101,110,116,115,0,109,95,108,111,99,97,108,83,99,97,108,
105,110,103,0,109,95,119,111,114,108,100,84,114,97,110,115,102,111,114,109,
0,109,95,105,110,116,101,114,112,111,108,97,116,105,111,110,87,111,114,108,
100,84,114,97,110,115,102,111,114,109,0,109,95,105,110,116,101,114,112,111,
108,97,116,105,111,110,76,105,110,101,97,114,86,101,108,111,99,105,116,121,
0,109,95,105,110,116,101,114,112,111,108,97,116,105,111,110,65,110,103,117,
108,97,114,86,101,108,111,99,105,116,121,0,109,95,97,110,105,115,111,116,
114,111,112,105,99,70,114,105,99,116,105,111,110,0,109,95,104,97,115,65,
110,105,115,111,116,114,111,112,105,99,70,114,105,99,116,105,111,110,0,109,
95,99,111,110,116,97,99,116,80,114,111,99,101,115,115,105,110,103,84,104,
114,101,115,104,111,108,100,0,42,109,95,98,114,111,97,100,112,104,97,115,
101,72,97,110,100,108,101,0,42,109,95,99,111,108,108,105,115,105,111,110,
83,104,97,112,101,0,42,109,95,114,111,111,116,67,111,108,108,105,115,105,
111,110,83,104,97,112,101,0,109,95,99,111,108,108,105,115,105,111,110,70,
108,97,103,115,0,109,95,105,115,108,97,110,100,84,97,103,49,0,109,95,
99,111,109,112,97,110,105,111,110,73,100,0,109,95,97,99,116,105,118,97,
116,105,111,110,83,116,97,116,101,49,0,109,95,100,101,97,99,116,105,118,
97,116,105,111,110,84,105,109,101,0,109,95,102,114,105,99,116,105,111,110,
0,109,95,114,101,115,116,105,116,117,116,105,111,110,0,109,95,105,110,116,
101,114,110,97,108,84,121,112,101,0,42,109,95,117,115,101,114,79,98,106,
101,99,116,80,111,105,110,116,101,114,0,109,95,104,105,116,70,114,97,99,
116,105,111,110,0,109,95,99,99,100,83,119,101,112,116,83,112,104,101,114,
101,82,97,100,105,117,115,0,109,95,99,99,100,77,111,116,105,111,110,84,
104,114,101,115,104,111,108,100,0,109,95,99,104,101,99,107,67,111,108,108,
105,100,101,87,105,116,104,0,109,95,99,111,108,108,105,115,105,111,110,79,
98,106,101,99,116,68,97,116,97,0,109,95,105,110,118,73,110,101,114,116,
105,97,84,101,110,115,111,114,87,111,114,108,100,0,109,95,108,105,110,101,
97,114,86,101,108,111,99,105,116,121,0,109,95,97,110,103,117,108,97,114,
86,101,108,111,99,105,116,121,0,109,95,105,110,118,101,114,115,101,77,97,
115,115,0,109,95,97,110,103,117,108,97,114,70,97,99,116,111,114,0,109,
95,108,105,110,101,97,114,70,97,99,116,111,114,0,109,95,103,114,97,118,
105,116,121,0,109,95,103,114,97,118,105,116,121,95,97,99,99,101,108,101,
114,97,116,105,111,110,0,109,95,105,110,118,73,110,101,114,116,105,97,76,
111,99,97,108,0,109,95,116,111,116,97,108,70,111,114,99,101,0,109,95,
116,111,116,97,108,84,111,114,113,117,101,0,109,95,108,105,110,101,97,114,
68,97,109,112,105,110,103,0,109,95,97,110,103,117,108,97,114,68,97,109,
112,105,110,103,0,109,95,97,100,100,105,116,105,111,110,97,108,68,97,109,
112,105,110,103,0,109,95,97,100,100,105,116,105,111,110,97,108,68,97,109,
112,105,110,103,70,97,99,116,111,114,0,109,95,97,100,100,105,116,105,111,
110,97,108,76,105,110,101,97,114,68,97,109,112,105,110,103,84,104,114,101,
115,104,111,108,100,83,113,114,0,109,95,97,100,100,105,116,105,111,110,97,
108,65,110,103,117,108,97,114,68,97,109,112,105,110,103,84,104,114,101,115,
104,111,108,100,83,113,114,0,109,95,97,100,100,105,116,105,111,110,97,108,
65,110,103,117,108,97,114,68,97,109,112,105,110,103,70,97,99,116,111,114,
0,109,95,108,105,110,101,97,114,83,108,101,101,112,105,110,103,84,104,114,
101,115,104,111,108,100,0,109,95,97,110,103,117,108,97,114,83,108,101,101,
112,105,110,103,84,104,114,101,115,104,111,108,100,0,0,0,84,89,80,69,
22,0,0,0,99,104,97,114,0,117,99,104,97,114,0,115,104,111,114,116,
0,117,115,104,111,114,116,0,105,110,116,0,108,111,110,103,0,117,108,111,
110,103,0,102,108,111,97,116,0,100,111,117,98,108,101,0,118,111,105,100,
0,98,116,83,99,97,108,97,114,0,80,111,105,110,116,101,114,65,114,114,
97,121,0,98,116,80,104,121,115,105,99,115,83,121,115,116,101,109,0,76,
105,115,116,66,97,115,101,0,98,116,86,101,99,116,111,114,51,68,97,116,
97,0,69,117,108,101,114,0,98,116,77,97,116,114,105,120,51,120,51,68,
97,116,97,0,98,116,84,114,97,110,115,102,111,114,109,68,97,116,97,0,
98,116,67,111,108,108,105,115,105,111,110,83,104,97,112,101,68,97,116,97,
0,98,116,66,111,120,83,104,97,112,101,68,97,116,97,0,98,116,67,111,
108,108,105,115,105,111,110,79,98,106,101,99,116,68,97,116,97,0,98,116,
82,105,103,105,100,66,111,100,121,68,97,116,97,0,0,0,84,76,69,78,
116,0,109,95,102,108,111,97,116,115,91,52,93,0,109,95,101,108,91,51,
93,0,109,95,98,97,115,105,115,0,109,95,111,114,105,103,105,110,0,42,
109,95,117,115,101,114,80,111,105,110,116,101,114,0,109,95,115,104,97,112,
101,84,121,112,101,0,109,95,112,97,100,100,105,110,103,91,52,93,0,109,
95,99,111,108,108,105,115,105,111,110,83,104,97,112,101,68,97,116,97,0,
109,95,108,111,99,97,108,83,99,97,108,105,110,103,0,109,95,105,109,112,
108,105,99,105,116,83,104,97,112,101,68,105,109,101,110,115,105,111,110,115,
0,109,95,99,111,108,108,105,115,105,111,110,77,97,114,103,105,110,0,109,
95,119,111,114,108,100,84,114,97,110,115,102,111,114,109,0,109,95,105,110,
116,101,114,112,111,108,97,116,105,111,110,87,111,114,108,100,84,114,97,110,
115,102,111,114,109,0,109,95,105,110,116,101,114,112,111,108,97,116,105,111,
110,76,105,110,101,97,114,86,101,108,111,99,105,116,121,0,109,95,105,110,
116,101,114,112,111,108,97,116,105,111,110,65,110,103,117,108,97,114,86,101,
108,111,99,105,116,121,0,109,95,97,110,105,115,111,116,114,111,112,105,99,
70,114,105,99,116,105,111,110,0,109,95,104,97,115,65,110,105,115,111,116,
114,111,112,105,99,70,114,105,99,116,105,111,110,0,109,95,99,111,110,116,
97,99,116,80,114,111,99,101,115,115,105,110,103,84,104,114,101,115,104,111,
108,100,0,42,109,95,98,114,111,97,100,112,104,97,115,101,72,97,110,100,
108,101,0,42,109,95,99,111,108,108,105,115,105,111,110,83,104,97,112,101,
0,42,109,95,114,111,111,116,67,111,108,108,105,115,105,111,110,83,104,97,
112,101,0,109,95,99,111,108,108,105,115,105,111,110,70,108,97,103,115,0,
109,95,105,115,108,97,110,100,84,97,103,49,0,109,95,99,111,109,112,97,
110,105,111,110,73,100,0,109,95,97,99,116,105,118,97,116,105,111,110,83,
116,97,116,101,49,0,109,95,100,101,97,99,116,105,118,97,116,105,111,110,
84,105,109,101,0,109,95,102,114,105,99,116,105,111,110,0,109,95,114,101,
115,116,105,116,117,116,105,111,110,0,109,95,105,110,116,101,114,110,97,108,
84,121,112,101,0,42,109,95,117,115,101,114,79,98,106,101,99,116,80,111,
105,110,116,101,114,0,109,95,104,105,116,70,114,97,99,116,105,111,110,0,
109,95,99,99,100,83,119,101,112,116,83,112,104,101,114,101,82,97,100,105,
117,115,0,109,95,99,99,100,77,111,116,105,111,110,84,104,114,101,115,104,
111,108,100,0,109,95,99,104,101,99,107,67,111,108,108,105,100,101,87,105,
116,104,0,109,95,99,111,108,108,105,115,105,111,110,79,98,106,101,99,116,
68,97,116,97,0,109,95,105,110,118,73,110,101,114,116,105,97,84,101,110,
115,111,114,87,111,114,108,100,0,109,95,108,105,110,101,97,114,86,101,108,
111,99,105,116,121,0,109,95,97,110,103,117,108,97,114,86,101,108,111,99,
105,116,121,0,109,95,105,110,118,101,114,115,101,77,97,115,115,0,109,95,
97,110,103,117,108,97,114,70,97,99,116,111,114,0,109,95,108,105,110,101,
97,114,70,97,99,116,111,114,0,109,95,103,114,97,118,105,116,121,0,109,
95,103,114,97,118,105,116,121,95,97,99,99,101,108,101,114,97,116,105,111,
110,0,109,95,105,110,118,73,110,101,114,116,105,97,76,111,99,97,108,0,
109,95,116,111,116,97,108,70,111,114,99,101,0,109,95,116,111,116,97,108,
84,111,114,113,117,101,0,109,95,108,105,110,101,97,114,68,97,109,112,105,
110,103,0,109,95,97,110,103,117,108,97,114,68,97,109,112,105,110,103,0,
109,95,97,100,100,105,116,105,111,110,97,108,68,97,109,112,105,110,103,0,
109,95,97,100,100,105,116,105,111,110,97,108,68,97,109,112,105,110,103,70,
97,99,116,111,114,0,109,95,97,100,100,105,116,105,111,110,97,108,76,105,
110,101,97,114,68,97,109,112,105,110,103,84,104,114,101,115,104,111,108,100,
83,113,114,0,109,95,97,100,100,105,116,105,111,110,97,108,65,110,103,117,
108,97,114,68,97,109,112,105,110,103,84,104,114,101,115,104,111,108,100,83,
113,114,0,109,95,97,100,100,105,116,105,111,110,97,108,65,110,103,117,108,
97,114,68,97,109,112,105,110,103,70,97,99,116,111,114,0,109,95,108,105,
110,101,97,114,83,108,101,101,112,105,110,103,84,104,114,101,115,104,111,108,
100,0,109,95,97,110,103,117,108,97,114,83,108,101,101,112,105,110,103,84,
104,114,101,115,104,111,108,100,0,0,0,0,84,89,80,69,21,0,0,0,
99,104,97,114,0,117,99,104,97,114,0,115,104,111,114,116,0,117,115,104,
111,114,116,0,105,110,116,0,108,111,110,103,0,117,108,111,110,103,0,102,
108,111,97,116,0,100,111,117,98,108,101,0,118,111,105,100,0,98,116,83,
99,97,108,97,114,0,80,111,105,110,116,101,114,65,114,114,97,121,0,98,
116,80,104,121,115,105,99,115,83,121,115,116,101,109,0,76,105,115,116,66,
97,115,101,0,98,116,86,101,99,116,111,114,51,68,97,116,97,0,98,116,
77,97,116,114,105,120,51,120,51,68,97,116,97,0,98,116,84,114,97,110,
115,102,111,114,109,68,97,116,97,0,98,116,67,111,108,108,105,115,105,111,
110,83,104,97,112,101,68,97,116,97,0,98,116,67,111,110,118,101,120,73,
110,116,101,114,110,97,108,83,104,97,112,101,68,97,116,97,0,98,116,67,
111,108,108,105,115,105,111,110,79,98,106,101,99,116,68,97,116,97,0,98,
116,82,105,103,105,100,66,111,100,121,68,97,116,97,0,0,84,76,69,78,
1,0,1,0,2,0,2,0,4,0,4,0,4,0,4,0,8,0,0,0,
4,0,12,0,36,0,8,0,16,0,12,0,48,0,64,0,12,0,44,0,
-8,0,-32,1,83,84,82,67,11,0,0,0,11,0,3,0,4,0,0,0,
4,0,12,0,36,0,8,0,16,0,48,0,64,0,12,0,52,0,-8,0,
-32,1,0,0,83,84,82,67,10,0,0,0,11,0,3,0,4,0,0,0,
4,0,1,0,9,0,2,0,12,0,3,0,11,0,3,0,11,0,4,0,
11,0,5,0,13,0,2,0,9,0,6,0,9,0,7,0,14,0,1,0,
10,0,8,0,15,0,3,0,10,0,9,0,10,0,10,0,10,0,11,0,
16,0,1,0,14,0,12,0,17,0,2,0,16,0,13,0,14,0,14,0,
18,0,3,0,9,0,15,0,4,0,16,0,0,0,17,0,19,0,3,0,
18,0,18,0,14,0,19,0,14,0,20,0,20,0,23,0,17,0,21,0,
17,0,22,0,14,0,23,0,14,0,24,0,14,0,25,0,4,0,26,0,
10,0,27,0,9,0,28,0,9,0,29,0,18,0,30,0,4,0,31,0,
4,0,32,0,4,0,33,0,4,0,34,0,10,0,35,0,10,0,36,0,
10,0,37,0,4,0,38,0,9,0,39,0,10,0,40,0,10,0,41,0,
10,0,42,0,4,0,43,0,21,0,21,0,20,0,44,0,16,0,45,0,
14,0,46,0,14,0,47,0,10,0,48,0,14,0,49,0,14,0,50,0,
14,0,51,0,14,0,52,0,14,0,53,0,14,0,54,0,14,0,55,0,
10,0,56,0,10,0,57,0,4,0,58,0,10,0,59,0,10,0,60,0,
10,0,61,0,10,0,62,0,10,0,63,0,10,0,64,0,};
10,0,8,0,15,0,1,0,14,0,9,0,16,0,2,0,15,0,10,0,
14,0,11,0,17,0,3,0,9,0,12,0,4,0,13,0,0,0,14,0,
18,0,5,0,17,0,15,0,14,0,16,0,14,0,17,0,10,0,18,0,
0,0,14,0,19,0,23,0,16,0,19,0,16,0,20,0,14,0,21,0,
14,0,22,0,14,0,23,0,4,0,24,0,10,0,25,0,9,0,26,0,
9,0,27,0,17,0,28,0,4,0,29,0,4,0,30,0,4,0,31,0,
4,0,32,0,10,0,33,0,10,0,34,0,10,0,35,0,4,0,36,0,
9,0,37,0,10,0,38,0,10,0,39,0,10,0,40,0,4,0,41,0,
20,0,21,0,19,0,42,0,15,0,43,0,14,0,44,0,14,0,45,0,
10,0,46,0,14,0,47,0,14,0,48,0,14,0,49,0,14,0,50,0,
14,0,51,0,14,0,52,0,14,0,53,0,10,0,54,0,10,0,55,0,
4,0,56,0,10,0,57,0,10,0,58,0,10,0,59,0,10,0,60,0,
10,0,61,0,10,0,62,0,};
int sBulletDNAlen= sizeof(sBulletDNAstr);

View File

@@ -60,6 +60,7 @@ class btSerializer
#define BT_COLLISIONOBJECT_CODE MAKE_ID('C','O','B','J')
#define BT_RIGIDBODY_CODE MAKE_ID('R','B','D','Y')
#define BT_BOXSHAPE_CODE MAKE_ID('B','O','X','S')
#define BT_SHAPE_CODE MAKE_ID('S','H','A','P')
class btDefaultSerializer
{