added COLLADA Physics export. import will follow soon.

Note that the exporter/importer doesn't handle GIMPACT and btStaticPlaneShape yet.
This commit is contained in:
erwin.coumans
2008-09-19 07:14:48 +00:00
parent ff46ceb519
commit c30a8bf154
10 changed files with 306 additions and 10 deletions

View File

@@ -28,7 +28,7 @@ LDFLAGS =-Wl,-Bsymbolic -shared
BULLET_INCLUDE=-I$(BULLET)/src -I$(BULLET)/Extras/GIMPACT/include
BULLET_LIB=-L$(BULLET)/out/linux/optimize/libs -L$(BULLET)/src \
-lGIMPACT -lGIMPACTUtils -lbulletdynamics \
-lBulletColladaConverter -lcolladadom -llibxml -lGIMPACT -lGIMPACTUtils -lbulletdynamics \
-lbulletmath -lbulletcollision -lbulletopenglsupport
GL_LIB=-lGL -lGLU
@@ -36,7 +36,7 @@ GL_LIB=-lGL -lGLU
MAYA_INCLUDE=-I$(MAYA)/include
MAYA_LIB=-L$(MAYA)/lib -lOpenMaya -lFoundation -lOpenMayaUI -lOpenMayaFX
SOURCES = pluginMain.cpp rigidBodyNode.cpp rigidBodyArrayNode.cpp collisionShapeNode.cpp \
SOURCES = pluginMain.cpp colladaExport.cpp rigidBodyNode.cpp rigidBodyArrayNode.cpp collisionShapeNode.cpp \
solver.cpp bt_solver.cpp dSolverNode.cpp dSolverCmd.cpp dRigidBodyCmd.cpp dRigidBodyArrayCmd.cpp \
pdbIO.cpp drawUtils.cpp

View File

@@ -30,7 +30,7 @@ LDFLAGS =-bundle -ldl -shared
BULLET_INCLUDE=-I$(BULLET)/src -I$(BULLET)/Extras/GIMPACT/include
BULLET_LIB=-L$(BULLET)/out/macosxx86/optimize/libs -L$(BULLET)/src \
-lGIMPACT -lGIMPACTUtils -lbulletdynamics \
-lBulletColladaConverter -lcolladadom -llibxml -lGIMPACT -lGIMPACTUtils -lbulletdynamics \
-lbulletmath -lbulletcollision -lbulletopenglsupport
GL_LIB=-framework OpenGL
@@ -38,7 +38,7 @@ GL_LIB=-framework OpenGL
MAYA_INCLUDE=-I$(MAYA)/include
MAYA_LIB=-L/Applications/Autodesk/maya2008/Maya.app/Contents/MacOS -lOpenMaya -lFoundation -Wl,-executable_path,/Applications/Autodesk/maya2008/Maya.app/Contents/MacOS -lOpenMayaUI -lOpenMayaFX -lOpenMaya -lFoundation
SOURCES = pluginMain.cpp rigidBodyNode.cpp rigidBodyArrayNode.cpp collisionShapeNode.cpp \
SOURCES = pluginMain.cpp colladaExport.cpp rigidBodyNode.cpp rigidBodyArrayNode.cpp collisionShapeNode.cpp \
solver.cpp bt_solver.cpp dSolverNode.cpp dSolverCmd.cpp dRigidBodyCmd.cpp dRigidBodyArrayCmd.cpp \
pdbIO.cpp drawUtils.cpp

View File

@@ -23,14 +23,31 @@ Written by: Nicola Candussi <nicola@fluidinteractive.com>
//bt_solver.cpp
#include "bt_solver.h"
#include "../BulletColladaConverter/ColladaConverter.h"
btVector3 minWorld(-10000,-10000,-10000);
btVector3 maxWorld(10000,10000,10000);
int maxNumObj=32768;
btVector3 worldAabbMin(-10000, -10000, -10000);
btVector3 worldAabbMax(10000, 10000, 10000);
int maxProxies = 32000;
void bt_solver_t::export_collada_file(const char* fileName)
{
ColladaConverter tmpConverter(m_dynamicsWorld.get());
tmpConverter.save(fileName);
}
void bt_solver_t::import_collada_file(const char* filename)
{
//todo: need to create actual bodies etc
ColladaConverter tmpConverter(m_dynamicsWorld.get());
tmpConverter.load(filename);
}
bt_solver_t::bt_solver_t():
m_broadphase(new btAxisSweep3(worldAabbMin, worldAabbMax, maxProxies)),
// m_broadphase(new btAxisSweep3(minWorld,maxWorld,maxNumObj)),
m_broadphase(new btDbvtBroadphase()),
m_solver(new btSequentialImpulseConstraintSolver),
m_collisionConfiguration(new btDefaultCollisionConfiguration),
m_dispatcher(new btCollisionDispatcher(m_collisionConfiguration.get())),
@@ -39,6 +56,7 @@ bt_solver_t::bt_solver_t():
m_solver.get(),
m_collisionConfiguration.get()))
{
//register algorithm for concave meshes
btGImpactCollisionAlgorithm::registerAlgorithm(m_dispatcher.get());

View File

@@ -98,6 +98,11 @@ public:
m_dynamicsWorld->stepSimulation(dt, 1000, 1.0 / 120.0);
}
virtual void export_collada_file(const char* fileName);
virtual void import_collada_file(const char* filename);
protected:
friend class solver_t;
bt_solver_t();

View File

@@ -0,0 +1,148 @@
/*
Bullet Continuous Collision Detection and Physics Library Maya Plugin
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 "colladaExport.h"
#include "solver.h"
#include "solver_impl.h"
#if defined (_WIN32)
#define strcasecmp stricmp
#elif defined (OSMac_)
extern "C" int strcasecmp (const char *, const char *);
#endif
#define NO_SMOOTHING_GROUP -1
#define INITIALIZE_SMOOTHING -2
#define INVALID_ID -1
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
void* ObjTranslator::creator()
{
return new ObjTranslator();
}
//////////////////////////////////////////////////////////////
MStatus ObjTranslator::reader ( const MFileObject& file,
const MString& options,
FileAccessMode mode)
{
fprintf(stderr, "COLLADA Physics import will be available very soon, please stay tuned.\n");
return MS::kFailure;
}
MStatus ObjTranslator::writer ( const MFileObject& file,
const MString& options,
FileAccessMode mode )
{
MStatus status;
MString mname = file.fullName(), unitName;
//just pass in the filename
#if defined (OSMac_)
char fname[256];//MAXPATHLEN];
strcpy (fname, file.fullName().asChar());
// fp = fopen(fname,"wb");//MAYAMACTODO
#else
const char *fname = mname.asChar();
// fp = fopen(fname,"w");
#endif
shared_ptr<solver_impl_t> solv = solver_t::get_solver();
solv->export_collada_file(fname);
return status;
}
//////////////////////////////////////////////////////////////
bool ObjTranslator::haveReadMethod () const
{
return true;
}
//////////////////////////////////////////////////////////////
bool ObjTranslator::haveWriteMethod () const
{
return true;
}
//////////////////////////////////////////////////////////////
MString ObjTranslator::defaultExtension () const
{
return "dae";
}
//////////////////////////////////////////////////////////////
MPxFileTranslator::MFileKind ObjTranslator::identifyFile (
const MFileObject& fileName,
const char* buffer,
short size) const
{
const char * name = fileName.name().asChar();
int nameLength = strlen(name);
if ((nameLength > 4) && !strcasecmp(name+nameLength-4, ".dae"))
return kCouldBeMyFileType;
else
return kNotMyFileType;
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
MStatus ObjTranslator::exportSelected( )
{
MStatus status;
MString filename;
// Create an iterator for the active selection list
//
MSelectionList slist;
MGlobal::getActiveSelectionList( slist );
MItSelectionList iter( slist );
if (iter.isDone()) {
fprintf(stderr,"Error: Nothing is selected.\n");
return MS::kFailure;
}
return status;
}
//////////////////////////////////////////////////////////////
MStatus ObjTranslator::exportAll( )
{
MStatus status = MS::kSuccess;
return status;
}

View File

@@ -0,0 +1,89 @@
/*
Bullet Continuous Collision Detection and Physics Library Maya Plugin
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 COLLADA_EXPORT_H
#define COLLADA_EXPORT_H
#include <string.h>
#include <sys/types.h>
#include <maya/MStatus.h>
#include <maya/MPxCommand.h>
#include <maya/MString.h>
#include <maya/MStringArray.h>
#include <maya/MArgList.h>
#include <maya/MGlobal.h>
#include <maya/MSelectionList.h>
#include <maya/MItSelectionList.h>
#include <maya/MPoint.h>
#include <maya/MPointArray.h>
#include <maya/MDagPath.h>
#include <maya/MDagPathArray.h>
//#include <maya/MFnPlugin.h>
#include <maya/MFnMesh.h>
#include <maya/MFnSet.h>
#include <maya/MItMeshPolygon.h>
#include <maya/MItMeshVertex.h>
#include <maya/MItMeshEdge.h>
#include <maya/MFloatVector.h>
#include <maya/MFloatVectorArray.h>
#include <maya/MFloatArray.h>
#include <maya/MObjectArray.h>
#include <maya/MObject.h>
//#include <maya/MPlug.h>
#include <maya/MPxFileTranslator.h>
#include <maya/MFnDagNode.h>
#include <maya/MItDag.h>
#include <maya/MDistance.h>
#include <maya/MIntArray.h>
#include <maya/MIOStream.h>
//////////////////////////////////////////////////////////////
class ObjTranslator : public MPxFileTranslator {
public:
ObjTranslator () {};
virtual ~ObjTranslator () {};
static void* creator();
MStatus reader ( const MFileObject& file,
const MString& optionsString,
FileAccessMode mode);
MStatus writer ( const MFileObject& file,
const MString& optionsString,
FileAccessMode mode );
bool haveReadMethod () const;
bool haveWriteMethod () const;
MString defaultExtension () const;
MFileKind identifyFile ( const MFileObject& fileName,
const char* buffer,
short size) const;
private:
MStatus exportSelected();
MStatus exportAll();
private:
};
#endif //COLLADA_EXPORT_H

View File

@@ -34,6 +34,17 @@ Written by: Nicola Candussi <nicola@fluidinteractive.com>
#include "dRigidBodyCmd.h"
#include "dRigidBodyArrayCmd.h"
#include "mvl/util.h"
#include "colladaExport.h"
const char *const colladaOptionScript = "colladaExportOptions";
const char *const colladaDefaultOptions =
"groups=1;"
"ptgroups=1;"
"materials=1;"
"smoothing=1;"
"normals=1;"
;
MStatus initializePlugin( MObject obj )
{
@@ -42,6 +53,16 @@ MStatus initializePlugin( MObject obj )
solver_t::initialize();
// Register the translator with the system
status = plugin.registerFileTranslator( "COLLADA Physics export", "none",
ObjTranslator::creator,
(char *)colladaOptionScript,
(char *)colladaDefaultOptions );
MCHECKSTATUS(status,"registerFileTranslator COLLADA Physics export")
//
status = plugin.registerNode( rigidBodyNode::typeName, rigidBodyNode::typeId,
rigidBodyNode::creator,
@@ -121,6 +142,9 @@ MStatus uninitializePlugin( MObject obj )
status = plugin.deregisterNode(rigidBodyNode::typeId);
MCHECKSTATUS(status, "deregistering rigidBodyNode")
status = plugin.deregisterFileTranslator( "OBJexport" );
MCHECKSTATUS(status,"deregistering OBJexport" )
solver_t::cleanup();
return status;

View File

@@ -28,6 +28,12 @@ Written by: Nicola Candussi <nicola@fluidinteractive.com>
shared_ptr<solver_impl_t> solver_t::m_impl;
std::set<rigid_body_t::pointer> solver_t::m_rigid_bodies;
shared_ptr<solver_impl_t> solver_t::get_solver()
{
return m_impl;
}
void solver_t::initialize()
{

View File

@@ -77,6 +77,8 @@ public:
//
static void step_simulation(float dt);
static shared_ptr<solver_impl_t> get_solver();
private:
static shared_ptr<solver_impl_t> m_impl;
static std::set<rigid_body_t::pointer> m_rigid_bodies;

View File

@@ -55,6 +55,10 @@ public:
virtual void set_split_impulse(bool enabled) = 0;
virtual void export_collada_file(const char* fileName) = 0;
virtual void import_collada_file(const char* filename) = 0;
virtual void step_simulation(float dt) = 0;
public: