added LICENSE.txt and AUTHORS.txt file
add MultiBody Custom Creation example, to show how to import data from a URDF file and fill up your own data structures. add btMultiBody::setBaseWorldTransform method todo: fix cmake build, this patch is premake only
This commit is contained in:
@@ -1,3 +1,17 @@
|
||||
/* Copyright (C) 2015 Google
|
||||
|
||||
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 CUSTOM_MULTIBODY_CALLBACK_H
|
||||
#define CUSTOM_MULTIBODY_CALLBACK_H
|
||||
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* Copyright (C) 2015 Google
|
||||
|
||||
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 "MultiBodyCustomURDFDemo.h"
|
||||
|
||||
@@ -6,6 +18,9 @@
|
||||
#include "../CommonInterfaces/CommonMultiBodyBase.h"
|
||||
|
||||
#include "../Importers/ImportURDFDemo/URDF2Bullet.h"
|
||||
#include "../Importers/ImportURDFDemo/MyURDFImporter.h"
|
||||
#include "../Importers/ImportURDFDemo/MyMultiBodyCreator.h"
|
||||
|
||||
#include "CustomMultiBodyCreationCallback.h"
|
||||
|
||||
|
||||
@@ -34,31 +49,100 @@ MultiBodyCustomURDFDemo::~MultiBodyCustomURDFDemo()
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void myPrintTree(const URDFImporterInterface& u2b, int linkIndex, int indentationLevel)
|
||||
{
|
||||
btAlignedObjectArray<int> childIndices;
|
||||
u2b.getLinkChildIndices(linkIndex,childIndices);
|
||||
|
||||
int numChildren = childIndices.size();
|
||||
|
||||
indentationLevel+=2;
|
||||
int count = 0;
|
||||
for (int i=0;i<numChildren;i++)
|
||||
{
|
||||
int childLinkIndex = childIndices[i];
|
||||
std::string name = u2b.getLinkName(childLinkIndex);
|
||||
for(int j=0;j<indentationLevel;j++) printf(" "); //indent
|
||||
printf("child(%d).name=%s with childIndex=%d\n",(count++)+1, name.c_str(),childLinkIndex);
|
||||
// first grandchild
|
||||
printTree(u2b,childLinkIndex,indentationLevel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class TestMultiBodyCreationCallback : public CustomMultiBodyCreationCallback
|
||||
{
|
||||
virtual int allocateMultiBodyBase(int urdfLinkIndex, int totalNumJoints,ScalarType baseMass, const Vector3dType& localInertiaDiagonal, bool isFixedBase)
|
||||
{
|
||||
printf("added base\n");
|
||||
}
|
||||
|
||||
virtual void addLinkAndJoint(int jointType, int linkIndex, // 0 to num_links-1
|
||||
int parentIndex,
|
||||
double mass,
|
||||
const Vector3dType& inertia,
|
||||
const QuaternionType &rotParentFrameToLinkFrame, // rotate points in parent frame to this frame, when q = 0
|
||||
const Vector3dType& jointAxisInLinkFrame, // in Link frame
|
||||
const Vector3dType& parentComToThisJointOffset, // vector from parent COM to joint frame, in Parent frame
|
||||
const Vector3dType& thisJointToThisComOffset) // vector from joint frame to my COM, in Link frame);
|
||||
{
|
||||
printf("added link\n");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void MultiBodyCustomURDFDemo::initPhysics()
|
||||
{
|
||||
int upAxis = 2;
|
||||
m_guiHelper->setUpAxis(upAxis);
|
||||
createEmptyDynamicsWorld();
|
||||
btVector3 grav(0,0,0);
|
||||
//grav[upAxis] = -10.f;
|
||||
|
||||
m_dynamicsWorld->setGravity(grav);
|
||||
|
||||
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
|
||||
m_dynamicsWorld->getDebugDrawer()->setDebugMode(
|
||||
//btIDebugDraw::DBG_DrawConstraints
|
||||
+btIDebugDraw::DBG_DrawWireframe
|
||||
+btIDebugDraw::DBG_DrawContactPoints
|
||||
+btIDebugDraw::DBG_DrawAabb
|
||||
);//+btIDebugDraw::DBG_DrawConstraintLimits);
|
||||
|
||||
|
||||
|
||||
|
||||
MyURDFImporter u2b(m_guiHelper);
|
||||
bool loadOk = u2b.loadURDF("r2d2.urdf");
|
||||
|
||||
if (loadOk)
|
||||
{
|
||||
u2b.printTree();
|
||||
int urdfRootLinkIndex = u2b.getRootLinkIndex();
|
||||
myPrintTree(u2b,urdfRootLinkIndex,0);
|
||||
|
||||
btTransform identityTrans;
|
||||
identityTrans.setIdentity();
|
||||
|
||||
btMultiBody* mb = 0;
|
||||
|
||||
|
||||
//todo: move these internal API called inside the 'ConvertURDF2Bullet' call, hidden from the user
|
||||
int rootLinkIndex = u2b.getRootLinkIndex();
|
||||
printf("urdf root link index = %d\n",rootLinkIndex);
|
||||
MyMultiBodyCreator creation(m_guiHelper);
|
||||
|
||||
bool useMultiBody = true;
|
||||
|
||||
ConvertURDF2Bullet(u2b,creation, identityTrans,m_dynamicsWorld,useMultiBody,u2b.getPathPrefix());
|
||||
mb = creation.getBulletMultiBody();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MultiBodyCustomURDFDemo::stepSimulation(float deltaTime)
|
||||
{
|
||||
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
}
|
||||
|
||||
|
||||
class ExampleInterface* MultiBodyCustomURDFDofCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
||||
class ExampleInterface* MultiBodyCustomURDFDemoCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
||||
{
|
||||
return new MultiBodyCustomURDFDemo(helper);
|
||||
}
|
||||
@@ -1,6 +1,20 @@
|
||||
/* Copyright (C) 2015 Google
|
||||
|
||||
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 MULTI_DOF_CUSTOM_URDF_DEMO_H
|
||||
#define MULTI_DOF_CUSTOM_URDF_DEMO_H
|
||||
|
||||
class ExampleInterface* MultiBodyCustomURDFDofCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||
class ExampleInterface* MultiBodyCustomURDFDemoCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||
|
||||
#endif //MULTI_DOF_CUSTOM_URDF_DEMO_H
|
||||
|
||||
43
examples/MultiBody/main.cpp
Normal file
43
examples/MultiBody/main.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2015 Google Inc. 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 "MultiBodyCustomURDFDemo.h"
|
||||
|
||||
#include "../CommonInterfaces/ExampleInterface.h"
|
||||
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
struct PhysicsInterface* pint = 0;
|
||||
|
||||
DummyGUIHelper noGfx;
|
||||
|
||||
int option = 0;
|
||||
|
||||
ExampleInterface* example = MultiBodyCustomURDFDemoCreateFunc(pint, &noGfx, option);
|
||||
|
||||
example->initPhysics();
|
||||
example->stepSimulation(1.f/60.f);
|
||||
example->exitPhysics();
|
||||
|
||||
delete example;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
40
examples/MultiBody/premake4.lua
Normal file
40
examples/MultiBody/premake4.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
project "App_CustomMultiBodyCreation"
|
||||
|
||||
if _OPTIONS["ios"] then
|
||||
kind "WindowedApp"
|
||||
else
|
||||
kind "ConsoleApp"
|
||||
end
|
||||
|
||||
includedirs {".", "../../src", "../ThirdPartyLibs"}
|
||||
|
||||
links {
|
||||
"Bullet3Common", "BulletDynamics","BulletCollision", "LinearMath"
|
||||
}
|
||||
|
||||
language "C++"
|
||||
|
||||
files {
|
||||
"MultiBodyCustomURDFDemo.cpp",
|
||||
"main.cpp",
|
||||
"../Importers/ImportURDFDemo/URDF2Bullet.cpp",
|
||||
"../Importers/ImportURDFDemo/MyURDFImporter.cpp",
|
||||
"../Importers/ImportURDFDemo/MyMultiBodyCreator.cpp",
|
||||
"../Importers/ImportObjDemo/LoadMeshFromObj.cpp",
|
||||
"../Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.cpp",
|
||||
"../Importers/ImportColladaDemo/LoadMeshFromCollada.cpp",
|
||||
"../ThirdPartyLibs/Wavefront/tiny_obj_loader.cpp",
|
||||
"../ThirdPartyLibs/tinyxml/tinystr.cpp",
|
||||
"../ThirdPartyLibs/tinyxml/tinyxml.cpp",
|
||||
"../ThirdPartyLibs/tinyxml/tinyxmlparser.cpp",
|
||||
"../ThirdPartyLibs/tinyxml/tinyxmlerror.cpp",
|
||||
"../ThirdPartyLibs/urdf/boost_replacement/printf_console.cpp",
|
||||
"../ThirdPartyLibs/urdf/boost_replacement/string_split.cpp",
|
||||
"../ThirdPartyLibs/urdf/urdfdom/urdf_parser/src/pose.cpp",
|
||||
"../ThirdPartyLibs/urdf/urdfdom/urdf_parser/src/model.cpp",
|
||||
"../ThirdPartyLibs/urdf/urdfdom/urdf_parser/src/link.cpp",
|
||||
"../ThirdPartyLibs/urdf/urdfdom/urdf_parser/src/joint.cpp",
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user