more work on Bullet serialization (added support for btConvexHullSupport)
This commit is contained in:
@@ -12,15 +12,36 @@ 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}/Extras/ConvexDecomposition
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/ConvexDecomposition
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
||||
)
|
||||
|
||||
IF (USE_GLUT)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath BulletFileLoader ConvexDecomposition ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppConvexDecompositionDemo
|
||||
main.cpp
|
||||
ConvexDecompositionDemo.cpp
|
||||
ConvexDecompositionDemo.h
|
||||
)
|
||||
ELSE (USE_GLUT)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ConvexDecomposition ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath BulletFileLoader ConvexDecomposition ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppConvexDecompositionDemo
|
||||
main.cpp
|
||||
ConvexDecompositionDemo.cpp
|
||||
)
|
||||
ADD_EXECUTABLE(AppConvexDecompositionDemo
|
||||
WIN32
|
||||
../OpenGL/Win32AppMain.cpp
|
||||
ConvexDecompositionDemo.cpp
|
||||
ConvexDecompositionDemo.h
|
||||
Win32ConvexDecompositionDemo.cpp
|
||||
)
|
||||
|
||||
ENDIF (USE_GLUT)
|
||||
|
||||
|
||||
@@ -23,6 +23,14 @@ subject to the following restrictions:
|
||||
#include "LinearMath/btGeometryUtil.h"
|
||||
#include "BulletCollision/CollisionShapes/btShapeHull.h"
|
||||
|
||||
#define TEST_SERIALIZATION
|
||||
|
||||
#ifdef TEST_SERIALIZATION
|
||||
#include "LinearMath/btSerializer.h"
|
||||
#include "btBulletFile.h"
|
||||
#include "btBulletFileLoader.h"
|
||||
#endif
|
||||
|
||||
//#define USE_PARALLEL_DISPATCHER 1
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
#include "../../Extras/BulletMultiThreaded/SpuGatheringCollisionDispatcher.h"
|
||||
@@ -91,27 +99,9 @@ bool MyContactCallback (
|
||||
}
|
||||
|
||||
|
||||
void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
void ConvexDecompositionDemo::setupEmptyDynamicsWorld()
|
||||
{
|
||||
gContactAddedCallback = &MyContactCallback;
|
||||
|
||||
setTexturing(true);
|
||||
setShadows(true);
|
||||
|
||||
setCameraDistance(26.f);
|
||||
|
||||
ConvexDecomposition::WavefrontObj wo;
|
||||
|
||||
tcount = wo.loadObj(filename);
|
||||
|
||||
if (!tcount)
|
||||
{
|
||||
//when running this app from visual studio, the default starting folder is different, so make a second attempt...
|
||||
tcount = wo.loadObj("../../file.obj");
|
||||
}
|
||||
|
||||
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
#ifdef USE_WIN32_THREADING
|
||||
@@ -151,6 +141,30 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;
|
||||
#endif //USE_PARALLEL_DISPATCHER
|
||||
|
||||
}
|
||||
|
||||
void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
{
|
||||
gContactAddedCallback = &MyContactCallback;
|
||||
|
||||
setTexturing(true);
|
||||
setShadows(true);
|
||||
|
||||
setCameraDistance(26.f);
|
||||
|
||||
ConvexDecomposition::WavefrontObj wo;
|
||||
|
||||
tcount = wo.loadObj(filename);
|
||||
|
||||
if (!tcount)
|
||||
{
|
||||
//when running this app from visual studio, the default starting folder is different, so make a second attempt...
|
||||
tcount = wo.loadObj("../../file.obj");
|
||||
}
|
||||
|
||||
|
||||
setupEmptyDynamicsWorld();
|
||||
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,-4.5,0));
|
||||
@@ -293,7 +307,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
btConvexHullShape* convexShape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
|
||||
#endif
|
||||
|
||||
convexShape->setMargin(0.01);
|
||||
convexShape->setMargin(0.01f);
|
||||
m_convexShapes.push_back(convexShape);
|
||||
m_convexCentroids.push_back(centroid);
|
||||
m_convexDemo->m_collisionShapes.push_back(convexShape);
|
||||
@@ -371,7 +385,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,2,0));
|
||||
startTransform.setOrigin(btVector3(0,2,14));
|
||||
|
||||
localCreateRigidBody(mass, startTransform,convexShape);
|
||||
|
||||
@@ -438,6 +452,9 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
trans.setOrigin(centroid);
|
||||
btConvexHullShape* convexShape = convexDecomposition.m_convexShapes[i];
|
||||
compound->addChildShape(trans,convexShape);
|
||||
|
||||
btRigidBody* body = localCreateRigidBody( 1.0, trans,convexShape);
|
||||
|
||||
}
|
||||
btScalar mass=10.f;
|
||||
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||
@@ -464,6 +481,30 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST_SERIALIZATION
|
||||
//test serializing this
|
||||
|
||||
int maxSerializeBufferSize = 1024*1024*5;
|
||||
|
||||
btDefaultSerializer* serializer = new btDefaultSerializer(maxSerializeBufferSize);
|
||||
m_dynamicsWorld->serialize(serializer);
|
||||
|
||||
FILE* f2 = fopen("testFile.bullet","wb");
|
||||
fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1,f2);
|
||||
fclose(f2);
|
||||
|
||||
exitPhysics();
|
||||
|
||||
//now try again from the loaded file
|
||||
setupEmptyDynamicsWorld();
|
||||
|
||||
btBulletFileLoader* fileLoader = new btBulletFileLoader(m_dynamicsWorld);
|
||||
|
||||
fileLoader->loadFileFromMemory("testFile.bullet");
|
||||
|
||||
|
||||
|
||||
#endif //TEST_SERIALIZATION
|
||||
|
||||
}
|
||||
|
||||
@@ -481,7 +522,7 @@ void ConvexDecompositionDemo::clientMoveAndDisplay()
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
swapBuffers();
|
||||
|
||||
}
|
||||
|
||||
@@ -499,7 +540,7 @@ void ConvexDecompositionDemo::displayCallback(void) {
|
||||
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
||||
@@ -532,12 +573,16 @@ void ConvexDecompositionDemo::exitPhysics()
|
||||
delete shape;
|
||||
}
|
||||
|
||||
m_collisionShapes.clear();
|
||||
|
||||
for (i=0;i<m_trimeshes.size();i++)
|
||||
{
|
||||
btTriangleMesh* mesh = m_trimeshes[i];
|
||||
delete mesh;
|
||||
}
|
||||
|
||||
m_trimeshes.clear();
|
||||
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
@@ -15,7 +15,15 @@ subject to the following restrictions:
|
||||
#ifndef CONVEX_DECOMPOSITION_DEMO_H
|
||||
#define CONVEX_DECOMPOSITION_DEMO_H
|
||||
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "Win32DemoApplication.h"
|
||||
#define PlatformDemoApplication Win32DemoApplication
|
||||
#else
|
||||
#include "GlutDemoApplication.h"
|
||||
#define PlatformDemoApplication GlutDemoApplication
|
||||
#endif
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btBroadphaseInterface;
|
||||
@@ -28,9 +36,10 @@ class btDefaultCollisionConfiguration;
|
||||
class btTriangleMesh;
|
||||
|
||||
///ConvexDecompositionDemo shows automatic convex decomposition of a concave mesh
|
||||
class ConvexDecompositionDemo : public GlutDemoApplication
|
||||
class ConvexDecompositionDemo : public PlatformDemoApplication
|
||||
{
|
||||
|
||||
void setupEmptyDynamicsWorld();
|
||||
public:
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifdef _WINDOWS
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2010 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
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 "ConvexDecompositionDemo.h"
|
||||
|
||||
///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo
|
||||
DemoApplication* createDemo()
|
||||
{
|
||||
return new ConvexDecompositionDemo();
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user