added serialization support for gimpact mesh

improved cmake build system for updating the serialization structures
This commit is contained in:
erwin.coumans
2010-01-29 02:50:34 +00:00
parent 701bc64ab7
commit 37f6df2c32
25 changed files with 721 additions and 459 deletions

View File

@@ -42,6 +42,7 @@
#include "bullet_btCompoundShapeData.h"
#include "bullet_btCylinderShapeData.h"
#include "bullet_btCapsuleShapeData.h"
#include "bullet_btGImpactMeshShapeData.h"
#include "bullet_btConvexHullShapeData.h"
#include "bullet_btCollisionObjectDoubleData.h"
#include "bullet_btCollisionObjectFloatData.h"

View File

@@ -49,6 +49,7 @@ namespace Bullet {
class btCompoundShapeData;
class btCylinderShapeData;
class btCapsuleShapeData;
class btGImpactMeshShapeData;
class btConvexHullShapeData;
class btCollisionObjectDoubleData;
class btCollisionObjectFloatData;

View File

@@ -0,0 +1,46 @@
/* 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_BTGIMPACTMESHSHAPEDATA__H__
#define __BULLET_BTGIMPACTMESHSHAPEDATA__H__
// -------------------------------------------------- //
#include "bullet_Common.h"
#include "bullet_btCollisionShapeData.h"
#include "bullet_btStridingMeshInterfaceData.h"
#include "bullet_btVector3FloatData.h"
namespace Bullet {
// ---------------------------------------------- //
class btGImpactMeshShapeData
{
public:
btCollisionShapeData m_collisionShapeData;
btStridingMeshInterfaceData m_meshInterface;
btVector3FloatData m_localScaling;
float m_collisionMargin;
int m_gimpactSubType;
};
}
#endif//__BULLET_BTGIMPACTMESHSHAPEDATA__H__

View File

@@ -20,13 +20,13 @@ subject to the following restrictions:
// 32 && 64 bit versions
//#ifdef _WIN64
#ifdef _WIN64
extern unsigned char sBulletDNAstr64[];
extern int sBulletDNAlen64;
//#else
#else
extern unsigned char sBulletDNAstr[];
extern int sBulletDNAlen;
//#endif //_WIN64
#endif //_WIN64
using namespace bParse;
@@ -35,16 +35,18 @@ btBulletFile::btBulletFile()
:bFile("", "BULLET ")
{
mMemoryDNA = new bDNA();
//#ifdef _WIN64
if (VOID_IS_8)
#ifdef _WIN64
//if (VOID_IS_8)
mMemoryDNA->init((char*)sBulletDNAstr64,sBulletDNAlen64);
else
//#else
// else
#else
mMemoryDNA->init((char*)sBulletDNAstr,sBulletDNAlen);
//#endif
#endif
}
btBulletFile::btBulletFile(const char* fileName)
:bFile(fileName, "BULLET ")
{
@@ -174,25 +176,25 @@ void btBulletFile::writeDNA(FILE* fp)
if (VOID_IS_8)
{
//#ifdef _WIN64
#ifdef _WIN64
dataChunk.len = sBulletDNAlen64;
dataChunk.oldPtr = sBulletDNAstr64;
fwrite(&dataChunk,sizeof(bChunkInd),1,fp);
fwrite(sBulletDNAstr64, sBulletDNAlen64,1,fp);
//#else
// btAssert(0);
//#endif
#else
btAssert(0);
#endif
}
else
{
//#ifndef _WIN64
#ifndef _WIN64
dataChunk.len = sBulletDNAlen;
dataChunk.oldPtr = sBulletDNAstr;
fwrite(&dataChunk,sizeof(bChunkInd),1,fp);
fwrite(sBulletDNAstr, sBulletDNAlen,1,fp);
//#else
// btAssert(0);
//#endif
#else
btAssert(0);
#endif
}
}
@@ -201,19 +203,19 @@ void btBulletFile::parse(bool verboseDumpAllTypes)
{
if (VOID_IS_8)
{
//#ifdef _WIN64
#ifdef _WIN64
parseInternal(verboseDumpAllTypes,(char*)sBulletDNAstr64,sBulletDNAlen64);
//#else
// btAssert(0);
//#endif
#else
btAssert(0);
#endif
}
else
{
//#ifndef _WIN64
#ifndef _WIN64
parseInternal(verboseDumpAllTypes,(char*)sBulletDNAstr,sBulletDNAlen);
//#else
// btAssert(0);
//#endif
#else
btAssert(0);
#endif
}
}

View File

@@ -3,7 +3,7 @@
#include "btBulletFile.h"
#include "btBulletDynamicsCommon.h"
#include "BulletCollision/gimpact/btGImpactShape.h"
btBulletWorldImporter::btBulletWorldImporter(btDynamicsWorld* world)
:m_dynamicsWorld(world),
@@ -11,6 +11,15 @@ m_verboseDumpAllTypes(false)
{
}
btBulletWorldImporter::~btBulletWorldImporter()
{
for (int i=0;i<m_allocatedCollisionShapes.size();i++)
{
delete m_allocatedCollisionShapes[i];
}
m_allocatedCollisionShapes.clear();
}
bool btBulletWorldImporter::loadFile( const char* fileName)
{
bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile(fileName);
@@ -36,6 +45,45 @@ bool btBulletWorldImporter::loadFileFromMemory( char* memoryBuffer, int len)
return result;
}
btTriangleIndexVertexArray* btBulletWorldImporter::createMeshInterface(btStridingMeshInterfaceData& meshData)
{
btTriangleIndexVertexArray* meshInterface = createTriangleMeshContainer();
for (int i=0;i<meshData.m_numMeshParts;i++)
{
btIndexedMesh meshPart;
if (meshData.m_meshPartsPtr[i].m_indices32)
{
meshPart.m_indexType = PHY_INTEGER;
meshPart.m_triangleIndexStride = 3*sizeof(int);
meshPart.m_triangleIndexBase = (const unsigned char*)meshData.m_meshPartsPtr[i].m_indices32;
} else
{
meshPart.m_indexType = PHY_SHORT;
meshPart.m_triangleIndexStride = 3*sizeof(short int);
meshPart.m_triangleIndexBase = (const unsigned char*)meshData.m_meshPartsPtr[i].m_indices16;
}
if (meshData.m_meshPartsPtr[i].m_vertices3f)
{
meshPart.m_vertexType = PHY_FLOAT;
meshPart.m_vertexStride = sizeof(btVector3FloatData);
meshPart.m_vertexBase = (const unsigned char*)meshData.m_meshPartsPtr[i].m_vertices3f;
} else
{
meshPart.m_vertexType = PHY_DOUBLE;
meshPart.m_vertexStride = sizeof(btVector3DoubleData);
meshPart.m_vertexBase = (const unsigned char*)meshData.m_meshPartsPtr[i].m_vertices3d;
}
meshPart.m_numTriangles = meshData.m_meshPartsPtr[i].m_numTriangles;
meshPart.m_numVertices = meshData.m_meshPartsPtr[i].m_numVertices;
meshInterface->addIndexedMesh(meshPart);
}
return meshInterface;
}
btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShapeData* shapeData )
{
btCollisionShape* shape = 0;
@@ -53,6 +101,25 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
break;
}
case GIMPACT_SHAPE_PROXYTYPE:
{
btGImpactMeshShapeData* gimpactData = (btGImpactMeshShapeData*) shapeData;
if (gimpactData->m_gimpactSubType == CONST_GIMPACT_TRIMESH_SHAPE)
{
btTriangleIndexVertexArray* meshInterface = createMeshInterface(gimpactData->m_meshInterface);
btGImpactMeshShape* gimpactShape = createGimpactShape(meshInterface);
btVector3 localScaling;
localScaling.deSerializeFloat(gimpactData->m_localScaling);
gimpactShape->setLocalScaling(localScaling);
gimpactShape->setMargin(btScalar(gimpactData->m_collisionMargin));
gimpactShape->updateBound();
shape = gimpactShape;
} else
{
printf("unsupported gimpact sub type\n");
}
break;
}
case CYLINDER_SHAPE_PROXYTYPE:
case CAPSULE_SHAPE_PROXYTYPE:
@@ -86,17 +153,17 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
{
case 0:
{
shape = createCapsuleShapeX(implicitShapeDimensions.getY(),implicitShapeDimensions.getX());
shape = createCapsuleShapeX(implicitShapeDimensions.getY(),2*implicitShapeDimensions.getX());
break;
}
case 1:
{
shape = createCapsuleShapeY(implicitShapeDimensions.getX(),implicitShapeDimensions.getY());
shape = createCapsuleShapeY(implicitShapeDimensions.getX(),2*implicitShapeDimensions.getY());
break;
}
case 2:
{
shape = createCapsuleShapeZ(implicitShapeDimensions.getX(),implicitShapeDimensions.getZ());
shape = createCapsuleShapeZ(implicitShapeDimensions.getX(),2*implicitShapeDimensions.getZ());
break;
}
default:
@@ -181,7 +248,11 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
tmpPoints[i].deSerializeDouble(convexData->m_unscaledPointsDoublePtr[i]);
#endif //BT_USE_DOUBLE_PRECISION
}
shape = new btConvexHullShape(&tmpPoints[0].getX(),numPoints,sizeof(btVector3));
btConvexHullShape* hullShape = createConvexHullShape();
for (int i=0;i<numPoints;i++)
{
hullShape->addPoint(tmpPoints[i]);
}
break;
}
default:
@@ -203,42 +274,12 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
case TRIANGLE_MESH_SHAPE_PROXYTYPE:
{
btTriangleMeshShapeData* trimesh = (btTriangleMeshShapeData*)shapeData;
btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray();
for (int i=0;i<trimesh->m_meshInterface.m_numMeshParts;i++)
{
btIndexedMesh meshPart;
if (trimesh->m_meshInterface.m_meshPartsPtr[i].m_indices32)
{
meshPart.m_indexType = PHY_INTEGER;
meshPart.m_triangleIndexStride = 3*sizeof(int);
meshPart.m_triangleIndexBase = (const unsigned char*)trimesh->m_meshInterface.m_meshPartsPtr[i].m_indices32;
} else
{
meshPart.m_indexType = PHY_SHORT;
meshPart.m_triangleIndexStride = 3*sizeof(short int);
meshPart.m_triangleIndexBase = (const unsigned char*)trimesh->m_meshInterface.m_meshPartsPtr[i].m_indices16;
}
btTriangleIndexVertexArray* meshInterface = createMeshInterface(trimesh->m_meshInterface);
if (trimesh->m_meshInterface.m_meshPartsPtr[i].m_vertices3f)
{
meshPart.m_vertexType = PHY_FLOAT;
meshPart.m_vertexStride = sizeof(btVector3FloatData);
meshPart.m_vertexBase = (const unsigned char*)trimesh->m_meshInterface.m_meshPartsPtr[i].m_vertices3f;
} else
{
meshPart.m_vertexType = PHY_DOUBLE;
meshPart.m_vertexStride = sizeof(btVector3DoubleData);
meshPart.m_vertexBase = (const unsigned char*)trimesh->m_meshInterface.m_meshPartsPtr[i].m_vertices3d;
}
meshPart.m_numTriangles = trimesh->m_meshInterface.m_meshPartsPtr[i].m_numTriangles;
meshPart.m_numVertices = trimesh->m_meshInterface.m_meshPartsPtr[i].m_numVertices;
meshInterface->addIndexedMesh(meshPart);
}
btVector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling);
meshInterface->setScaling(scaling);
btBvhTriangleMeshShape* trimeshShape = new btBvhTriangleMeshShape(meshInterface,true);
btCollisionShape* trimeshShape = createBvhTriangleMeshShape(meshInterface);
trimeshShape->setMargin(trimesh->m_collisionMargin);
shape = trimeshShape;
@@ -248,7 +289,7 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
case COMPOUND_SHAPE_PROXYTYPE:
{
btCompoundShapeData* compoundData = (btCompoundShapeData*)shapeData;
btCompoundShape* compoundShape = new btCompoundShape();
btCompoundShape* compoundShape = createCompoundShape();
btAlignedObjectArray<btCollisionShape*> childShapes;
@@ -630,8 +671,6 @@ btCollisionShape* btBulletWorldImporter::createCapsuleShapeZ(btScalar radius, bt
return new btCapsuleShapeZ(radius,height);
}
btCollisionShape* btBulletWorldImporter::createCylinderShapeX(btScalar radius,btScalar height)
{
return new btCylinderShapeX(btVector3(height,radius,radius));
@@ -647,29 +686,29 @@ btCollisionShape* btBulletWorldImporter::createCylinderShapeZ(btScalar radius,bt
return new btCylinderShapeZ(btVector3(radius,radius,height));
}
btTriangleMesh* btBulletWorldImporter::createTriangleMeshContainer()
btTriangleIndexVertexArray* btBulletWorldImporter::createTriangleMeshContainer()
{
return new btTriangleIndexVertexArray();
}
btCollisionShape* btBulletWorldImporter::createBvhTriangleMeshShape(btStridingMeshInterface* trimesh)
{
return new btBvhTriangleMeshShape(trimesh,true);
}
btCollisionShape* btBulletWorldImporter::createConvexTriangleMeshShape(btStridingMeshInterface* trimesh)
{
return 0;
}
btCollisionShape* btBulletWorldImporter::createBvhTriangleMeshShape(btTriangleMesh* trimesh)
btGImpactMeshShape* btBulletWorldImporter::createGimpactShape(btStridingMeshInterface* trimesh)
{
return 0;
}
btCollisionShape* btBulletWorldImporter::createConvexTriangleMeshShape(btTriangleMesh* trimesh)
{
return 0;
}
btCollisionShape* btBulletWorldImporter::createGimpactShape(btTriangleMesh* trimesh)
{
return 0;
return new btGImpactMeshShape(trimesh);
}
btConvexHullShape* btBulletWorldImporter::createConvexHullShape()
{
return 0;
return new btConvexHullShape();
}
btCompoundShape* btBulletWorldImporter::createCompoundShape()
{
return 0;
return new btCompoundShape();
}

View File

@@ -30,6 +30,10 @@ class btDynamicsWorld;
struct ConstraintInput;
class btRigidBodyColladaInfo;
struct btCollisionShapeData;
class btTriangleIndexVertexArray;
class btStridingMeshInterface;
struct btStridingMeshInterfaceData;
class btGImpactMeshShape;
namespace bParse
{
@@ -48,10 +52,16 @@ protected:
btCollisionShape* convertCollisionShape( btCollisionShapeData* shapeData );
btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes;
btTriangleIndexVertexArray* createMeshInterface(btStridingMeshInterfaceData& meshData);
public:
btBulletWorldImporter(btDynamicsWorld* world);
virtual ~btBulletWorldImporter();
bool loadFile(const char* fileName);
///the memoryBuffer might be modified (for example if endian swaps are necessary)
@@ -96,10 +106,10 @@ public:
virtual btCollisionShape* createCylinderShapeX(btScalar radius,btScalar height);
virtual btCollisionShape* createCylinderShapeY(btScalar radius,btScalar height);
virtual btCollisionShape* createCylinderShapeZ(btScalar radius,btScalar height);
virtual class btTriangleMesh* createTriangleMeshContainer();
virtual btCollisionShape* createBvhTriangleMeshShape(btTriangleMesh* trimesh);
virtual btCollisionShape* createConvexTriangleMeshShape(btTriangleMesh* trimesh);
virtual btCollisionShape* createGimpactShape(btTriangleMesh* trimesh);
virtual class btTriangleIndexVertexArray* createTriangleMeshContainer();
virtual btCollisionShape* createBvhTriangleMeshShape(btStridingMeshInterface* trimesh);
virtual btCollisionShape* createConvexTriangleMeshShape(btStridingMeshInterface* trimesh);
virtual btGImpactMeshShape* createGimpactShape(btStridingMeshInterface* trimesh);
virtual class btConvexHullShape* createConvexHullShape();
virtual class btCompoundShape* createCompoundShape();

View File

@@ -1,9 +1,15 @@
SUBDIRS ( BulletFileLoader BulletWorldImporter )
IF(INTERNAL_UPDATE_SERIALIZATION_STRUCTURES)
# 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 BulletWorldImporter BlenderSerialize HeaderGenerator makesdna)
SUBDIRS ( BulletFileLoader BulletWorldImporter BlenderSerialize HeaderGenerator makesdna)
ELSE(INTERNAL_UPDATE_SERIALIZATION_STRUCTURES)
SUBDIRS ( BulletFileLoader BulletWorldImporter )
ENDIF (INTERNAL_UPDATE_SERIALIZATION_STRUCTURES)

View File

@@ -132,6 +132,7 @@ typedef unsigned long uintptr_t;
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
#include "BulletCollision/CollisionShapes/btCylinderShape.h"
#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
#include "BulletCollision/Gimpact/btGImpactShape.h"
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
#include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h"
@@ -168,6 +169,7 @@ char *includefiles[] = {
"../../../src/BulletCollision/CollisionShapes/btCompoundShape.h",
"../../../src/BulletCollision/CollisionShapes/btCylinderShape.h",
"../../../src/BulletCollision/CollisionShapes/btCapsuleShape.h",
"../../../src/BulletCollision/Gimpact/btGImpactShape.h",
"../../../src/BulletCollision/CollisionShapes/btConvexHullShape.h",
"../../../src/BulletCollision/CollisionDispatch/btCollisionObject.h",
"../../../src/BulletDynamics/Dynamics/btRigidBody.h",