more work on serialization, work-in-progress
This commit is contained in:
@@ -14,4 +14,6 @@ bFile.cpp
|
||||
bFile.h
|
||||
btBulletFile.cpp
|
||||
btBulletFile.h
|
||||
btBulletFileLoader.cpp
|
||||
btBulletFileLoader.h
|
||||
)
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include "bullet_btTransformData.h"
|
||||
#include "bullet_btCollisionShapeData.h"
|
||||
#include "bullet_btConvexInternalShapeData.h"
|
||||
#include "bullet_btPositionAndRadius.h"
|
||||
#include "bullet_btMultiSphereShapeData.h"
|
||||
#include "bullet_btCollisionObjectData.h"
|
||||
#include "bullet_btRigidBodyData.h"
|
||||
#endif//__BULLET_H__
|
||||
@@ -34,6 +34,8 @@ namespace Bullet {
|
||||
class btTransformData;
|
||||
class btCollisionShapeData;
|
||||
class btConvexInternalShapeData;
|
||||
class btPositionAndRadius;
|
||||
class btMultiSphereShapeData;
|
||||
class btCollisionObjectData;
|
||||
class btRigidBodyData;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/* 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_BTMULTISPHERESHAPEDATA__H__
|
||||
#define __BULLET_BTMULTISPHERESHAPEDATA__H__
|
||||
|
||||
|
||||
// -------------------------------------------------- //
|
||||
#include "bullet_Common.h"
|
||||
#include "bullet_btConvexInternalShapeData.h"
|
||||
|
||||
namespace Bullet {
|
||||
|
||||
|
||||
// ---------------------------------------------- //
|
||||
class btMultiSphereShapeData
|
||||
{
|
||||
public:
|
||||
btConvexInternalShapeData m_convexInternalShapeData;
|
||||
btPositionAndRadius *m_localPositionArrayPtr;
|
||||
int m_localPositionArraySize;
|
||||
char m_padding[4];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BULLET_BTMULTISPHERESHAPEDATA__H__
|
||||
@@ -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_BTPOSITIONANDRADIUS__H__
|
||||
#define __BULLET_BTPOSITIONANDRADIUS__H__
|
||||
|
||||
|
||||
// -------------------------------------------------- //
|
||||
#include "bullet_Common.h"
|
||||
#include "bullet_btVector3Data.h"
|
||||
|
||||
namespace Bullet {
|
||||
|
||||
|
||||
// ---------------------------------------------- //
|
||||
class btPositionAndRadius
|
||||
{
|
||||
public:
|
||||
btVector3Data m_pos;
|
||||
btScalar m_radius;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BULLET_BTPOSITIONANDRADIUS__H__
|
||||
255
Extras/Serialize/BulletFileLoader/btBulletFileLoader.cpp
Normal file
255
Extras/Serialize/BulletFileLoader/btBulletFileLoader.cpp
Normal file
@@ -0,0 +1,255 @@
|
||||
|
||||
#include "btBulletFileLoader.h"
|
||||
#include "btBulletFile.h"
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
btBulletFileLoader::btBulletFileLoader(btDynamicsWorld* world)
|
||||
:m_dynamicsWorld(world),
|
||||
m_verboseDumpAllTypes(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool btBulletFileLoader::loadFileFromMemory( char* fileName)
|
||||
{
|
||||
bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile("testFile.bullet");
|
||||
|
||||
bool result = loadFileFromMemory(bulletFile2);
|
||||
|
||||
delete bulletFile2;
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool btBulletFileLoader::loadFileFromMemory( char* memoryBuffer, int len)
|
||||
{
|
||||
bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile(memoryBuffer,len);
|
||||
|
||||
bool result = loadFileFromMemory(bulletFile2);
|
||||
|
||||
delete bulletFile2;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool btBulletFileLoader::loadFileFromMemory( bParse::btBulletFile* bulletFile2)
|
||||
{
|
||||
|
||||
|
||||
bool ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0;
|
||||
|
||||
if (ok)
|
||||
bulletFile2->parse(m_verboseDumpAllTypes);
|
||||
else
|
||||
return false;
|
||||
|
||||
if (m_verboseDumpAllTypes)
|
||||
{
|
||||
bulletFile2->dumpChunks(bulletFile2->getFileDNA());
|
||||
}
|
||||
|
||||
int i;
|
||||
btHashMap<btHashPtr,btCollisionShape*> shapeMap;
|
||||
|
||||
for (i=0;i<bulletFile2->m_collisionShapes.size();i++)
|
||||
{
|
||||
btCollisionShapeData* shapeData = (btCollisionShapeData*)bulletFile2->m_collisionShapes[i];
|
||||
switch (shapeData->m_shapeType)
|
||||
{
|
||||
case CYLINDER_SHAPE_PROXYTYPE:
|
||||
case CAPSULE_SHAPE_PROXYTYPE:
|
||||
case BOX_SHAPE_PROXYTYPE:
|
||||
case SPHERE_SHAPE_PROXYTYPE:
|
||||
case MULTI_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 = createBoxShape(implicitShapeDimensions+margin);
|
||||
break;
|
||||
}
|
||||
case SPHERE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
shape = createSphereShape(implicitShapeDimensions.getX());
|
||||
break;
|
||||
}
|
||||
case CAPSULE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
shape = createCapsuleShape(implicitShapeDimensions.getX(),implicitShapeDimensions.getY());
|
||||
break;
|
||||
}
|
||||
case CYLINDER_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btVector3 halfExtents = implicitShapeDimensions+margin;
|
||||
|
||||
shape = createCylinderShapeY(halfExtents.getX(),halfExtents.getY());
|
||||
break;
|
||||
}
|
||||
case MULTI_SPHERE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
#if 1
|
||||
btMultiSphereShapeData* mss = (btMultiSphereShapeData*)bsd;
|
||||
int numSpheres = mss->m_localPositionArraySize;
|
||||
|
||||
btAlignedObjectArray<btVector3> tmpPos;
|
||||
btAlignedObjectArray<btScalar> radii;
|
||||
radii.resize(numSpheres);
|
||||
tmpPos.resize(numSpheres);
|
||||
|
||||
for (int i=0;i<numSpheres;i++)
|
||||
{
|
||||
tmpPos[i].deSerialize(mss->m_localPositionArrayPtr[i].m_pos);
|
||||
radii[i] = mss->m_localPositionArrayPtr[i].m_radius;
|
||||
}
|
||||
|
||||
|
||||
shape = new btMultiSphereShape(&tmpPos[0],&radii[0],numSpheres);
|
||||
#endif
|
||||
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);
|
||||
|
||||
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];
|
||||
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);
|
||||
}
|
||||
|
||||
bool isDynamic = mass!=0.f;
|
||||
createRigidBody(isDynamic,mass,startTransform,shape);
|
||||
|
||||
} else
|
||||
{
|
||||
printf("error: no shape found\n");
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0;i<bulletFile2->m_collisionObjects.size();i++)
|
||||
{
|
||||
btCollisionObjectData* colObjData = (btCollisionObjectData*)bulletFile2->m_collisionObjects[i];
|
||||
printf("bla");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
btTypedConstraint* btBulletFileLoader::createUniversalD6Constraint(class btRigidBody* body0,class btRigidBody* otherBody,
|
||||
btTransform& localAttachmentFrameRef,
|
||||
btTransform& localAttachmentOther,
|
||||
const btVector3& linearMinLimits,
|
||||
const btVector3& linearMaxLimits,
|
||||
const btVector3& angularMinLimits,
|
||||
const btVector3& angularMaxLimits,
|
||||
bool disableCollisionsBetweenLinkedBodies)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
btRigidBody* btBulletFileLoader::createRigidBody(bool isDynamic, float mass, const btTransform& startTransform,btCollisionShape* shape)
|
||||
{
|
||||
btVector3 localInertia;
|
||||
|
||||
if (mass)
|
||||
shape->calculateLocalInertia(mass,localInertia);
|
||||
|
||||
btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);
|
||||
body->setWorldTransform(startTransform);
|
||||
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
btCollisionShape* btBulletFileLoader::createPlaneShape(const btVector3& planeNormal,btScalar planeConstant)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
btCollisionShape* btBulletFileLoader::createBoxShape(const btVector3& halfExtents)
|
||||
{
|
||||
return new btBoxShape(halfExtents);
|
||||
}
|
||||
btCollisionShape* btBulletFileLoader::createSphereShape(btScalar radius)
|
||||
{
|
||||
return new btSphereShape(radius);
|
||||
}
|
||||
|
||||
btCollisionShape* btBulletFileLoader::createCapsuleShape(btScalar radius, btScalar height)
|
||||
{
|
||||
return new btCapsuleShape(radius,height);
|
||||
}
|
||||
|
||||
|
||||
|
||||
btCollisionShape* btBulletFileLoader::createCylinderShapeY(btScalar radius,btScalar height)
|
||||
{
|
||||
return new btCylinderShape(btVector3(radius,height,radius));
|
||||
}
|
||||
btTriangleMesh* btBulletFileLoader::createTriangleMeshContainer()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
btCollisionShape* btBulletFileLoader::createBvhTriangleMeshShape(btTriangleMesh* trimesh)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
btCollisionShape* btBulletFileLoader::createConvexTriangleMeshShape(btTriangleMesh* trimesh)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
btCollisionShape* btBulletFileLoader::createGimpactShape(btTriangleMesh* trimesh)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
btConvexHullShape* btBulletFileLoader::createConvexHullShape()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
btCompoundShape* btBulletFileLoader::createCompoundShape()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
96
Extras/Serialize/BulletFileLoader/btBulletFileLoader.h
Normal file
96
Extras/Serialize/BulletFileLoader/btBulletFileLoader.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2010 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 BULLET_FILE_LOADER_H
|
||||
#define BULLET_FILE_LOADER_H
|
||||
|
||||
#include "LinearMath/btTransform.h"
|
||||
#include "LinearMath/btVector3.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "LinearMath/btHashMap.h"
|
||||
|
||||
class btBulletFile;
|
||||
class btCollisionShape;
|
||||
class btRigidBody;
|
||||
class btTypedConstraint;
|
||||
class btDynamicsWorld;
|
||||
struct ConstraintInput;
|
||||
class btRigidBodyColladaInfo;
|
||||
|
||||
namespace bParse
|
||||
{
|
||||
class btBulletFile;
|
||||
};
|
||||
|
||||
|
||||
class btBulletFileLoader
|
||||
{
|
||||
btDynamicsWorld* m_dynamicsWorld;
|
||||
|
||||
bool m_verboseDumpAllTypes;
|
||||
|
||||
public:
|
||||
|
||||
btBulletFileLoader(btDynamicsWorld* world);
|
||||
|
||||
bool loadFileFromMemory(char* fileName);
|
||||
|
||||
bool loadFileFromMemory(char *memoryBuffer, int len);
|
||||
|
||||
bool loadFileFromMemory(bParse::btBulletFile* file);
|
||||
|
||||
void setVerboseMode(bool verboseDumpAllTypes)
|
||||
{
|
||||
m_verboseDumpAllTypes = verboseDumpAllTypes;
|
||||
}
|
||||
|
||||
bool getVerboseMode() const
|
||||
{
|
||||
return m_verboseDumpAllTypes;
|
||||
}
|
||||
|
||||
///those virtuals are called by load
|
||||
virtual btTypedConstraint* createUniversalD6Constraint(
|
||||
class btRigidBody* body0,class btRigidBody* otherBody,
|
||||
btTransform& localAttachmentFrameRef,
|
||||
btTransform& localAttachmentOther,
|
||||
const btVector3& linearMinLimits,
|
||||
const btVector3& linearMaxLimits,
|
||||
const btVector3& angularMinLimits,
|
||||
const btVector3& angularMaxLimits,
|
||||
bool disableCollisionsBetweenLinkedBodies
|
||||
);
|
||||
|
||||
virtual btRigidBody* createRigidBody(bool isDynamic,
|
||||
float mass,
|
||||
const btTransform& startTransform,
|
||||
btCollisionShape* shape);
|
||||
|
||||
virtual btCollisionShape* createPlaneShape(const btVector3& planeNormal,btScalar planeConstant);
|
||||
virtual btCollisionShape* createBoxShape(const btVector3& halfExtents);
|
||||
virtual btCollisionShape* createSphereShape(btScalar radius);
|
||||
virtual btCollisionShape* createCapsuleShape(btScalar radius, btScalar height);
|
||||
virtual btCollisionShape* createCylinderShapeY(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 btConvexHullShape* createConvexHullShape();
|
||||
virtual class btCompoundShape* createCompoundShape();
|
||||
|
||||
};
|
||||
|
||||
#endif //BULLET_FILE_LOADER_H
|
||||
Reference in New Issue
Block a user