Dynamica export to Bullet .bullet file, and some fixes in Hull scaling (not using btCompoundShape::setLocalScaling but directly appying the scaling to the hull vertices, and caching the local scaling)
This commit is contained in:
@@ -115,6 +115,7 @@
|
|||||||
</Configuration>
|
</Configuration>
|
||||||
<Configuration
|
<Configuration
|
||||||
Name="DebugDll|x64"
|
Name="DebugDll|x64"
|
||||||
|
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||||
ConfigurationType="1"
|
ConfigurationType="1"
|
||||||
>
|
>
|
||||||
<Tool
|
<Tool
|
||||||
@@ -270,6 +271,7 @@
|
|||||||
</Configuration>
|
</Configuration>
|
||||||
<Configuration
|
<Configuration
|
||||||
Name="ReleaseDll|x64"
|
Name="ReleaseDll|x64"
|
||||||
|
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||||
ConfigurationType="1"
|
ConfigurationType="1"
|
||||||
>
|
>
|
||||||
<Tool
|
<Tool
|
||||||
@@ -699,7 +701,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\colladaExport.cpp"
|
RelativePath=".\bulletExport.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
@@ -791,7 +793,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\colladaExport.h"
|
RelativePath=".\bulletExport.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
|||||||
@@ -59,14 +59,48 @@ public:
|
|||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void set_scale(vec3f const& s) {
|
virtual void set_scale(vec3f const& s1) {
|
||||||
shape()->setLocalScaling(btVector3(s[0], s[1], s[2]));
|
// shape()->setLocalScaling(btVector3(s[0], s[1], s[2]));
|
||||||
|
btVector3 s(s1[0],s1[1],s1[2]);
|
||||||
|
|
||||||
|
float delSq = 0.f;
|
||||||
|
for(int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
float del = s[i] - m_cachedScaling[i];
|
||||||
|
delSq += del * del;
|
||||||
|
}
|
||||||
|
if (delSq > FLT_EPSILON)
|
||||||
|
{
|
||||||
|
// btAssert(shape()->getType()==
|
||||||
|
btCompoundShape* compound =(btCompoundShape*)shape();
|
||||||
|
btConvexHullShape* child = (btConvexHullShape*)compound->getChildShape(0);
|
||||||
|
/*
|
||||||
|
btTransform scaleTransf;
|
||||||
|
scaleTransf.setIdentity();
|
||||||
|
scaleTransf.getBasis()[0][0] = (s/m_cachedScaling)[0];
|
||||||
|
scaleTransf.getBasis()[1][1] = (s/m_cachedScaling)[1];
|
||||||
|
scaleTransf.getBasis()[2][2] = (s/m_cachedScaling)[2];
|
||||||
|
btTransform combinedTr = tr.inverse() * (scaleTransf * (tr * vtx));
|
||||||
|
*/
|
||||||
|
const btTransform& tr = compound->getChildTransform(0);
|
||||||
|
for (int i=0;i<child->getNumPoints();i++)
|
||||||
|
{
|
||||||
|
btVector3 oldPoint = child->getUnscaledPoints()[i];
|
||||||
|
btVector3 parentPoint = tr*oldPoint;
|
||||||
|
btVector3 parentPointScaled = parentPoint*(s/m_cachedScaling);
|
||||||
|
btVector3 childPoint = tr.inverse()*parentPointScaled;
|
||||||
|
child->getUnscaledPoints()[i]=childPoint;
|
||||||
|
}
|
||||||
|
m_cachedScaling = s;
|
||||||
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void get_scale(vec3f& s) {
|
virtual void get_scale(vec3f& s) {
|
||||||
const btVector3& scale = shape()->getLocalScaling();
|
// const btVector3& scale = shape()->getLocalScaling();
|
||||||
s = vec3f(scale.x(), scale.y(), scale.z());
|
// s = vec3f(scale.x(), scale.y(), scale.z());
|
||||||
|
s = vec3f(m_cachedScaling.x(), m_cachedScaling.y(), m_cachedScaling.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual float volume() { return m_volume; }
|
virtual float volume() { return m_volume; }
|
||||||
@@ -103,6 +137,12 @@ protected:
|
|||||||
|
|
||||||
m_ch_shape.reset(new btConvexHullShape((float const*)&(m_vertices[0]), num_vertices, sizeof(vec3f)));
|
m_ch_shape.reset(new btConvexHullShape((float const*)&(m_vertices[0]), num_vertices, sizeof(vec3f)));
|
||||||
btCompoundShape *compound_shape = new btCompoundShape;
|
btCompoundShape *compound_shape = new btCompoundShape;
|
||||||
|
// btTransform childTransf;
|
||||||
|
// childTransf.setIdentity();
|
||||||
|
// childTransf.setOrigin(btVector3(m_center[0], m_center[1], m_center[2]));
|
||||||
|
// compound_shape->addChildShape(childTransf, m_ch_shape.get());
|
||||||
|
|
||||||
|
///*
|
||||||
compound_shape->addChildShape(btTransform(btQuaternion(m_rotation[1],
|
compound_shape->addChildShape(btTransform(btQuaternion(m_rotation[1],
|
||||||
m_rotation[2],
|
m_rotation[2],
|
||||||
m_rotation[3],
|
m_rotation[3],
|
||||||
@@ -111,7 +151,9 @@ protected:
|
|||||||
m_center[1],
|
m_center[1],
|
||||||
m_center[2])),
|
m_center[2])),
|
||||||
m_ch_shape.get());
|
m_ch_shape.get());
|
||||||
|
//*/
|
||||||
set_shape(compound_shape);
|
set_shape(compound_shape);
|
||||||
|
m_cachedScaling[0] = m_cachedScaling[1] = m_cachedScaling[2] = 1.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update()
|
void update()
|
||||||
@@ -147,6 +189,7 @@ private:
|
|||||||
vec3f m_center;
|
vec3f m_center;
|
||||||
quatf m_rotation;
|
quatf m_rotation;
|
||||||
vec3f m_local_inertia;
|
vec3f m_local_inertia;
|
||||||
|
btVector3 m_cachedScaling;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -21,30 +21,44 @@ Written by: Nicola Candussi <nicola@fluidinteractive.com>
|
|||||||
|
|
||||||
Modified by Roman Ponomarev <rponom@gmail.com>
|
Modified by Roman Ponomarev <rponom@gmail.com>
|
||||||
01/22/2010 : Constraints reworked
|
01/22/2010 : Constraints reworked
|
||||||
|
01/27/2010 : Replaced COLLADA export with Bullet binary export
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//bt_solver.cpp
|
//bt_solver.cpp
|
||||||
|
|
||||||
|
#include "LinearMath/btSerializer.h"
|
||||||
#include "bt_solver.h"
|
#include "bt_solver.h"
|
||||||
#include "../BulletColladaConverter/ColladaConverter.h"
|
//#include "../BulletColladaConverter/ColladaConverter.h"
|
||||||
|
//#include "../Serialize/BulletFileLoader/btBulletFile.h"
|
||||||
|
|
||||||
btVector3 minWorld(-10000,-10000,-10000);
|
btVector3 minWorld(-10000,-10000,-10000);
|
||||||
btVector3 maxWorld(10000,10000,10000);
|
btVector3 maxWorld(10000,10000,10000);
|
||||||
int maxNumObj=32768;
|
int maxNumObj=32768;
|
||||||
|
|
||||||
|
|
||||||
void bt_solver_t::export_collada_file(const char* fileName)
|
void bt_solver_t::export_bullet_file(const char* fileName)
|
||||||
{
|
{
|
||||||
ColladaConverter tmpConverter(m_dynamicsWorld.get());
|
// ColladaConverter tmpConverter(m_dynamicsWorld.get());
|
||||||
tmpConverter.save(fileName);
|
// tmpConverter.save(fileName);
|
||||||
|
FILE* f2 = fopen(fileName,"wb");
|
||||||
|
if(f2 == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error: Can't open file %s for writing\n", fileName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int maxSerializeBufferSize = 1024*1024*5;
|
||||||
|
btDefaultSerializer* serializer = new btDefaultSerializer(maxSerializeBufferSize);
|
||||||
|
m_dynamicsWorld->serialize(serializer);
|
||||||
|
fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1,f2);
|
||||||
|
fclose(f2);
|
||||||
|
delete serializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_solver_t::import_collada_file(const char* filename)
|
void bt_solver_t::import_bullet_file(const char* filename)
|
||||||
{
|
{
|
||||||
//todo: need to create actual bodies etc
|
//todo: need to create actual bodies etc
|
||||||
ColladaConverter tmpConverter(m_dynamicsWorld.get());
|
// ColladaConverter tmpConverter(m_dynamicsWorld.get());
|
||||||
tmpConverter.load(filename);
|
// tmpConverter.load(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ Written by: Nicola Candussi <nicola@fluidinteractive.com>
|
|||||||
|
|
||||||
Modified by Roman Ponomarev <rponom@gmail.com>
|
Modified by Roman Ponomarev <rponom@gmail.com>
|
||||||
01/22/2010 : Constraints reworked
|
01/22/2010 : Constraints reworked
|
||||||
|
01/27/2010 : Replaced COLLADA export with Bullet binary export
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//bt_solver.h
|
//bt_solver.h
|
||||||
@@ -127,7 +128,7 @@ public:
|
|||||||
virtual void add_constraint(constraint_impl_t* c)
|
virtual void add_constraint(constraint_impl_t* c)
|
||||||
{
|
{
|
||||||
bt_constraint_t* btc = dynamic_cast<bt_constraint_t*>(c);
|
bt_constraint_t* btc = dynamic_cast<bt_constraint_t*>(c);
|
||||||
m_dynamicsWorld->addConstraint(btc->constraint());
|
m_dynamicsWorld->addConstraint(btc->constraint(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void remove_constraint(constraint_impl_t* c)
|
virtual void remove_constraint(constraint_impl_t* c)
|
||||||
@@ -151,9 +152,9 @@ public:
|
|||||||
m_dynamicsWorld->stepSimulation(dt, 1000, 1.0f / 120.0f);
|
m_dynamicsWorld->stepSimulation(dt, 1000, 1.0f / 120.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void export_collada_file(const char* fileName);
|
virtual void export_bullet_file(const char* fileName);
|
||||||
|
|
||||||
virtual void import_collada_file(const char* filename);
|
virtual void import_bullet_file(const char* filename);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -16,9 +16,11 @@ would be appreciated but is not required.
|
|||||||
not be misrepresented as being the original software.
|
not be misrepresented as being the original software.
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
Modified by Roman Ponomarev <rponom@gmail.com>
|
||||||
|
01/27/2010 : Replaced COLLADA export with Bullet binary export
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "colladaExport.h"
|
#include "bulletExport.h"
|
||||||
#include "solver.h"
|
#include "solver.h"
|
||||||
#include "solver_impl.h"
|
#include "solver_impl.h"
|
||||||
|
|
||||||
@@ -35,6 +37,8 @@ extern "C" int strcasecmp (const char *, const char *);
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
MString ObjTranslator::fExtension = "bullet";
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void* ObjTranslator::creator()
|
void* ObjTranslator::creator()
|
||||||
@@ -48,7 +52,7 @@ MStatus ObjTranslator::reader ( const MFileObject& file,
|
|||||||
const MString& options,
|
const MString& options,
|
||||||
FileAccessMode mode)
|
FileAccessMode mode)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "COLLADA Physics import will be available very soon, please stay tuned.\n");
|
fprintf(stderr, "Bullet Physics import is not available yet\n");
|
||||||
return MS::kFailure;
|
return MS::kFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +80,7 @@ MStatus ObjTranslator::writer ( const MFileObject& file,
|
|||||||
|
|
||||||
shared_ptr<solver_impl_t> solv = solver_t::get_solver();
|
shared_ptr<solver_impl_t> solv = solver_t::get_solver();
|
||||||
|
|
||||||
solv->export_collada_file(fname);
|
solv->export_bullet_file(fname);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
@@ -97,7 +101,8 @@ bool ObjTranslator::haveWriteMethod () const
|
|||||||
|
|
||||||
MString ObjTranslator::defaultExtension () const
|
MString ObjTranslator::defaultExtension () const
|
||||||
{
|
{
|
||||||
return "dae";
|
// return MString("bullet");
|
||||||
|
return fExtension;
|
||||||
}
|
}
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -109,7 +114,7 @@ MPxFileTranslator::MFileKind ObjTranslator::identifyFile (
|
|||||||
const char * name = fileName.name().asChar();
|
const char * name = fileName.name().asChar();
|
||||||
int nameLength = strlen(name);
|
int nameLength = strlen(name);
|
||||||
|
|
||||||
if ((nameLength > 4) && !strcasecmp(name+nameLength-4, ".dae"))
|
if ((nameLength > 7) && !strcasecmp(name+nameLength-7, ".bullet"))
|
||||||
return kCouldBeMyFileType;
|
return kCouldBeMyFileType;
|
||||||
else
|
else
|
||||||
return kNotMyFileType;
|
return kNotMyFileType;
|
||||||
@@ -16,11 +16,13 @@ would be appreciated but is not required.
|
|||||||
not be misrepresented as being the original software.
|
not be misrepresented as being the original software.
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
Modified by Roman Ponomarev <rponom@gmail.com>
|
||||||
|
01/27/2010 : Replaced COLLADA export with Bullet binary export
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef COLLADA_EXPORT_H
|
#ifndef BULLET_EXPORT_H
|
||||||
#define COLLADA_EXPORT_H
|
#define BULLET_EXPORT_H
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -76,6 +78,9 @@ public:
|
|||||||
MFileKind identifyFile ( const MFileObject& fileName,
|
MFileKind identifyFile ( const MFileObject& fileName,
|
||||||
const char* buffer,
|
const char* buffer,
|
||||||
short size) const;
|
short size) const;
|
||||||
|
protected:
|
||||||
|
static MString fExtension;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MStatus exportSelected();
|
MStatus exportSelected();
|
||||||
MStatus exportAll();
|
MStatus exportAll();
|
||||||
@@ -85,5 +90,5 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif //COLLADA_EXPORT_H
|
#endif //BULLET_EXPORT_H
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@ Written by: Nicola Candussi <nicola@fluidinteractive.com>
|
|||||||
|
|
||||||
Modified by Roman Ponomarev <rponom@gmail.com>
|
Modified by Roman Ponomarev <rponom@gmail.com>
|
||||||
01/22/2010 : Constraints reworked
|
01/22/2010 : Constraints reworked
|
||||||
|
01/27/2010 : Replaced COLLADA export with Bullet binary export
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//pluginMain.cpp
|
//pluginMain.cpp
|
||||||
@@ -45,10 +46,10 @@ Modified by Roman Ponomarev <rponom@gmail.com>
|
|||||||
#include "constraint/dSliderConstraintCmd.h"
|
#include "constraint/dSliderConstraintCmd.h"
|
||||||
#include "constraint/dsixdofConstraintCmd.h"
|
#include "constraint/dsixdofConstraintCmd.h"
|
||||||
#include "mvl/util.h"
|
#include "mvl/util.h"
|
||||||
#include "colladaExport.h"
|
#include "bulletExport.h"
|
||||||
|
|
||||||
const char *const colladaOptionScript = "colladaExportOptions";
|
const char *const bulletOptionScript = "bulletExportOptions";
|
||||||
const char *const colladaDefaultOptions =
|
const char *const bulletDefaultOptions =
|
||||||
"groups=1;"
|
"groups=1;"
|
||||||
"ptgroups=1;"
|
"ptgroups=1;"
|
||||||
"materials=1;"
|
"materials=1;"
|
||||||
@@ -66,12 +67,12 @@ MStatus initializePlugin( MObject obj )
|
|||||||
|
|
||||||
|
|
||||||
// Register the translator with the system
|
// Register the translator with the system
|
||||||
status = plugin.registerFileTranslator( "COLLADA Physics export", "none",
|
status = plugin.registerFileTranslator( "Bullet Physics export", "none",
|
||||||
ObjTranslator::creator,
|
ObjTranslator::creator,
|
||||||
(char *)colladaOptionScript,
|
(char *)bulletOptionScript,
|
||||||
(char *)colladaDefaultOptions );
|
(char *)bulletDefaultOptions );
|
||||||
|
|
||||||
MCHECKSTATUS(status,"registerFileTranslator COLLADA Physics export")
|
MCHECKSTATUS(status,"registerFileTranslator Bullet Physics export");
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -226,8 +227,8 @@ MStatus uninitializePlugin( MObject obj )
|
|||||||
status = plugin.deregisterNode(rigidBodyNode::typeId);
|
status = plugin.deregisterNode(rigidBodyNode::typeId);
|
||||||
MCHECKSTATUS(status, "deregistering rigidBodyNode")
|
MCHECKSTATUS(status, "deregistering rigidBodyNode")
|
||||||
|
|
||||||
status = plugin.deregisterFileTranslator( "COLLADA Physics export" );
|
status = plugin.deregisterFileTranslator( "Bullet Physics export" );
|
||||||
MCHECKSTATUS(status,"deregistering COLLADA Physics export" )
|
MCHECKSTATUS(status,"deregistering Bullet Physics export" )
|
||||||
|
|
||||||
solver_t::cleanup();
|
solver_t::cleanup();
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ Written by: Nicola Candussi <nicola@fluidinteractive.com>
|
|||||||
|
|
||||||
Modified by Roman Ponomarev <rponom@gmail.com>
|
Modified by Roman Ponomarev <rponom@gmail.com>
|
||||||
01/22/2010 : Constraints reworked
|
01/22/2010 : Constraints reworked
|
||||||
|
01/27/2010 : Replaced COLLADA export with Bullet binary export
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//solver.cpp
|
//solver.cpp
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ Written by: Nicola Candussi <nicola@fluidinteractive.com>
|
|||||||
|
|
||||||
Modified by Roman Ponomarev <rponom@gmail.com>
|
Modified by Roman Ponomarev <rponom@gmail.com>
|
||||||
01/22/2010 : Constraints reworked
|
01/22/2010 : Constraints reworked
|
||||||
|
01/27/2010 : Replaced COLLADA export with Bullet binary export
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//solver_impl.h
|
//solver_impl.h
|
||||||
@@ -76,9 +77,9 @@ public:
|
|||||||
|
|
||||||
virtual void set_split_impulse(bool enabled) = 0;
|
virtual void set_split_impulse(bool enabled) = 0;
|
||||||
|
|
||||||
virtual void export_collada_file(const char* fileName) = 0;
|
virtual void export_bullet_file(const char* fileName) = 0;
|
||||||
|
|
||||||
virtual void import_collada_file(const char* filename) = 0;
|
virtual void import_bullet_file(const char* filename) = 0;
|
||||||
|
|
||||||
virtual void step_simulation(float dt) = 0;
|
virtual void step_simulation(float dt) = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user