add starting point for btGeneric6DofSpring2ConstraintData import, not all parameters are deserialized though
restore activation state after picking add .bullet file import (only tested/available on Windows)
This commit is contained in:
@@ -25,6 +25,7 @@ struct CommonRigidBodyBase : public CommonExampleInterface
|
||||
//data for picking objects
|
||||
class btRigidBody* m_pickedBody;
|
||||
class btTypedConstraint* m_pickedConstraint;
|
||||
int m_savedState;
|
||||
btVector3 m_oldPickingPos;
|
||||
btVector3 m_hitPos;
|
||||
btScalar m_oldPickingDist;
|
||||
@@ -156,6 +157,19 @@ struct CommonRigidBodyBase : public CommonExampleInterface
|
||||
|
||||
virtual bool keyboardCallback(int key, int state)
|
||||
{
|
||||
if ((key==B3G_F3) && state && m_dynamicsWorld)
|
||||
{
|
||||
btDefaultSerializer* serializer = new btDefaultSerializer();
|
||||
m_dynamicsWorld->serialize(serializer);
|
||||
|
||||
FILE* file = fopen("testFile.bullet","wb");
|
||||
fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1, file);
|
||||
fclose(file);
|
||||
//b3Printf("btDefaultSerializer wrote testFile.bullet");
|
||||
delete serializer;
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;//don't handle this key
|
||||
}
|
||||
|
||||
@@ -329,6 +343,7 @@ struct CommonRigidBodyBase : public CommonExampleInterface
|
||||
if (!(body->isStaticObject() || body->isKinematicObject()))
|
||||
{
|
||||
m_pickedBody = body;
|
||||
m_savedState = m_pickedBody->getActivationState();
|
||||
m_pickedBody->setActivationState(DISABLE_DEACTIVATION);
|
||||
//printf("pickPos=%f,%f,%f\n",pickPos.getX(),pickPos.getY(),pickPos.getZ());
|
||||
btVector3 localPivot = body->getCenterOfMassTransform().inverse() * pickPos;
|
||||
@@ -378,6 +393,8 @@ struct CommonRigidBodyBase : public CommonExampleInterface
|
||||
{
|
||||
if (m_pickedConstraint)
|
||||
{
|
||||
m_pickedBody->forceActivationState(m_savedState);
|
||||
m_pickedBody->activate();
|
||||
m_dynamicsWorld->removeConstraint(m_pickedConstraint);
|
||||
delete m_pickedConstraint;
|
||||
m_pickedConstraint = 0;
|
||||
|
||||
@@ -33,9 +33,12 @@
|
||||
#include "../OpenGLWindow/SimpleOpenGL2Renderer.h"
|
||||
#include "ExampleEntries.h"
|
||||
#include "OpenGLGuiHelper.h"
|
||||
#include "Bullet3Common/b3FileUtils.h"
|
||||
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
//quick test for file import, @todo(erwincoumans) make it more general and add other file formats
|
||||
#include "../Importers/ImportURDFDemo/ImportURDFSetup.h"
|
||||
#include "../Importers/ImportBullet/SerializeSetup.h"
|
||||
|
||||
static CommonGraphicsApp* s_app=0;
|
||||
|
||||
@@ -191,7 +194,7 @@ static void MyMouseButtonCallback(int button, int state, float x, float y)
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void openURDFDemo(const char* filename)
|
||||
void openFileDemo(const char* filename)
|
||||
{
|
||||
|
||||
if (sCurrentDemo)
|
||||
@@ -211,7 +214,21 @@ void openURDFDemo(const char* filename)
|
||||
CommonExampleOptions options(s_guiHelper,0);
|
||||
options.m_fileName = filename;
|
||||
|
||||
sCurrentDemo = ImportURDFCreateFunc(options);
|
||||
char fullPath[1024];
|
||||
int fileType = 0;
|
||||
sprintf(fullPath, "%s", filename);
|
||||
b3FileUtils::toLower(fullPath);
|
||||
if (strstr(fullPath, ".urdf"))
|
||||
{
|
||||
sCurrentDemo = ImportURDFCreateFunc(options);
|
||||
} else
|
||||
{
|
||||
if (strstr(fullPath, ".bullet"))
|
||||
{
|
||||
sCurrentDemo = SerializeBulletCreateFunc(options);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//physicsSetup->setFileName(filename);
|
||||
|
||||
@@ -471,7 +488,7 @@ void fileOpenCallback()
|
||||
{
|
||||
//todo(erwincoumans) check if it is actually URDF
|
||||
//printf("file open:%s\n", filename);
|
||||
openURDFDemo(filename);
|
||||
openFileDemo(filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,19 @@
|
||||
|
||||
class SerializeSetup : public CommonRigidBodyBase
|
||||
{
|
||||
|
||||
char m_fileName[1024];
|
||||
|
||||
public:
|
||||
SerializeSetup(struct GUIHelperInterface* helper);
|
||||
SerializeSetup(struct GUIHelperInterface* helper, const char* fileName);
|
||||
virtual ~SerializeSetup();
|
||||
|
||||
virtual void initPhysics();
|
||||
virtual void stepSimulation(float deltaTime);
|
||||
|
||||
virtual void setFileName(const char* fileName)
|
||||
{
|
||||
memcpy(m_fileName,fileName,strlen(fileName)+1);
|
||||
}
|
||||
virtual void resetCamera()
|
||||
{
|
||||
float dist = 9.5;
|
||||
@@ -25,10 +31,16 @@ public:
|
||||
};
|
||||
|
||||
|
||||
SerializeSetup::SerializeSetup(struct GUIHelperInterface* helper)
|
||||
SerializeSetup::SerializeSetup(struct GUIHelperInterface* helper, const char* fileName)
|
||||
:CommonRigidBodyBase(helper)
|
||||
{
|
||||
|
||||
if (fileName)
|
||||
{
|
||||
setFileName(fileName);
|
||||
} else
|
||||
{
|
||||
setFileName("spider.bullet");
|
||||
}
|
||||
}
|
||||
SerializeSetup::~SerializeSetup()
|
||||
{
|
||||
@@ -41,9 +53,9 @@ void SerializeSetup::initPhysics()
|
||||
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
|
||||
m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints);
|
||||
btBulletWorldImporter* importer = new btBulletWorldImporter(m_dynamicsWorld);
|
||||
const char* someFileName="spider.bullet";
|
||||
|
||||
|
||||
const char* prefix[]={"./","./data/","../data/","../../data/","../../../data/","../../../../data/"};
|
||||
const char* prefix[]={"","./","./data/","../data/","../../data/","../../../data/","../../../../data/"};
|
||||
int numPrefixes = sizeof(prefix)/sizeof(const char*);
|
||||
char relativeFileName[1024];
|
||||
FILE* f=0;
|
||||
@@ -52,7 +64,7 @@ void SerializeSetup::initPhysics()
|
||||
|
||||
for (int i=0;!f && i<numPrefixes;i++)
|
||||
{
|
||||
sprintf(relativeFileName,"%s%s",prefix[i],someFileName);
|
||||
sprintf(relativeFileName,"%s%s",prefix[i],m_fileName);
|
||||
f = fopen(relativeFileName,"rb");
|
||||
if (f)
|
||||
{
|
||||
@@ -84,7 +96,7 @@ void SerializeSetup::initPhysics()
|
||||
btDefaultSerializer* serializer = new btDefaultSerializer();
|
||||
m_dynamicsWorld->serialize(serializer);
|
||||
|
||||
FILE* file = fopen("testFile.bullet","wb");
|
||||
FILE* file = fopen("SerializeSetupTestFile.bullet","wb");
|
||||
fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1, file);
|
||||
fclose(file);
|
||||
|
||||
@@ -101,5 +113,5 @@ void SerializeSetup::stepSimulation(float deltaTime)
|
||||
|
||||
class CommonExampleInterface* SerializeBulletCreateFunc(struct CommonExampleOptions& options)
|
||||
{
|
||||
return new SerializeSetup(options.m_guiHelper);
|
||||
return new SerializeSetup(options.m_guiHelper, options.m_fileName);
|
||||
}
|
||||
|
||||
@@ -157,13 +157,13 @@ int Win32OpenGLWindow::fileOpenDialog(char* fileName, int maxFileNameLength)
|
||||
ofn.lpstrFile = bla;
|
||||
ofn.lpstrFile[0] = '\0';
|
||||
ofn.nMaxFile = 1023;
|
||||
ofn.lpstrFilter = L"URDF\0*.urdf\0";
|
||||
ofn.lpstrFilter = L"All Files\0*.*\0URDF\0*.urdf\0.bullet\0*.bullet\0";
|
||||
#else
|
||||
ofn.lpstrFile = fileName;
|
||||
ofn.lpstrFile[0] = '\0';
|
||||
ofn.nMaxFile = 1023;
|
||||
//ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
|
||||
ofn.lpstrFilter = "URDF\0*.urdf\0";
|
||||
ofn.lpstrFilter = "All Files\0*.*\0URDF\0*.urdf\0.bullet\0*.bullet\0";
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -64,10 +64,7 @@ int getAsciiCodeFromVirtualKeycode(int virtualKeyCode)
|
||||
{
|
||||
return virtualKeyCode;
|
||||
}
|
||||
if (virtualKeyCode >= 'a' && virtualKeyCode <= 'z')
|
||||
{
|
||||
return virtualKeyCode;
|
||||
}
|
||||
|
||||
if (virtualKeyCode >= 'A' && virtualKeyCode <= 'Z')
|
||||
{
|
||||
return virtualKeyCode+32;//todo: fix the ascii A vs a input
|
||||
|
||||
Reference in New Issue
Block a user