fix various warning
add b3ResourcePath utility, to locate resources relative to executable
This commit is contained in:
@@ -85,8 +85,6 @@ SET(App_ExampleBrowser_SRCS
|
||||
../Importers/ImportURDFDemo/URDF2Bullet.cpp
|
||||
../Importers/ImportURDFDemo/MyMultiBodyCreator.cpp
|
||||
../Importers/ImportURDFDemo/MyMultiBodyCreator.h
|
||||
../Importers/ImportURDFDemo/ROSURDFImporter.cpp
|
||||
../Importers/ImportURDFDemo/ROSURDFImporter.h
|
||||
../Importers/ImportURDFDemo/UrdfParser.cpp
|
||||
../Importers/ImportURDFDemo/urdfStringSplit.cpp
|
||||
../Importers/ImportURDFDemo/urdfStringSplit.h
|
||||
@@ -141,6 +139,8 @@ SET(App_ExampleBrowser_SRCS
|
||||
../ThirdPartyLibs/urdf/boost_replacement/string_split.h
|
||||
../Utils/b3Clock.cpp
|
||||
../Utils/b3Clock.h
|
||||
../Utils/b3ResourcePath.cpp
|
||||
../Utils/b3ResourcePath.h
|
||||
${ExampleBrowser_SRCS}
|
||||
${ExampleBrowser_HDRS}
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
|
||||
@@ -77,6 +77,7 @@
|
||||
"../ThirdPartyLibs/Wavefront/tiny_obj_loader.*",
|
||||
"../ThirdPartyLibs/tinyxml/*",
|
||||
"../Utils/b3Clock.*",
|
||||
"../Utils/b3ResourcePath.*",
|
||||
"../GyroscopicDemo/GyroscopicSetup.cpp",
|
||||
"../GyroscopicDemo/GyroscopicSetup.h",
|
||||
"../ThirdPartyLibs/urdf/urdfdom/urdf_parser/src/pose.cpp",
|
||||
|
||||
@@ -24,6 +24,7 @@ subject to the following restrictions:
|
||||
#include "../OpenGLWindow/SimpleOpenGL3App.h"
|
||||
#include "LoadMeshFromCollada.h"
|
||||
#include "Bullet3Common/b3FileUtils.h"
|
||||
#include "../../Utils/b3ResourcePath.h"
|
||||
|
||||
#include "../CommonInterfaces/CommonRigidBodyBase.h"
|
||||
|
||||
@@ -86,9 +87,9 @@ void ImportColladaSetup::initPhysics()
|
||||
|
||||
char relativeFileName[1024];
|
||||
|
||||
b3FileUtils f;
|
||||
if (!f.findFile(fileName,relativeFileName,1024))
|
||||
return;
|
||||
if (!b3ResourcePath::findResourcePath(fileName,relativeFileName,1024))
|
||||
return;
|
||||
|
||||
|
||||
btVector3 shift(0,0,0);
|
||||
btVector3 scaling(1,1,1);
|
||||
@@ -209,4 +210,4 @@ void ImportColladaSetup::initPhysics()
|
||||
class CommonExampleInterface* ImportColladaCreateFunc(struct CommonExampleOptions& options)
|
||||
{
|
||||
return new ImportColladaSetup(options.m_guiHelper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ void readLibraryGeometries(TiXmlDocument& doc, btAlignedObjectArray<GLInstanceGr
|
||||
const char* sem = input->Attribute("semantic");
|
||||
std::string semName(sem);
|
||||
// printf("sem=%s\n",sem);
|
||||
const char* src = input->Attribute("source");
|
||||
// const char* src = input->Attribute("source");
|
||||
// printf("src=%s\n",src);
|
||||
const char* srcIdRef = input->Attribute("source");
|
||||
std::string source_name;
|
||||
@@ -192,12 +192,12 @@ void readLibraryGeometries(TiXmlDocument& doc, btAlignedObjectArray<GLInstanceGr
|
||||
std::string normalSourceName;
|
||||
int primitiveCount;
|
||||
primitive->QueryIntAttribute("count", &primitiveCount);
|
||||
bool positionAndNormalInVertex=false;
|
||||
int indexStride=1;
|
||||
int posOffset = 0;
|
||||
int normalOffset = 0;
|
||||
int numIndices = 0;
|
||||
{
|
||||
|
||||
for (TiXmlElement* input = primitive->FirstChildElement("input");input != NULL;input = input->NextSiblingElement("input"))
|
||||
{
|
||||
const char* sem = input->Attribute("semantic");
|
||||
@@ -206,7 +206,8 @@ void readLibraryGeometries(TiXmlDocument& doc, btAlignedObjectArray<GLInstanceGr
|
||||
if ((offset+1)>indexStride)
|
||||
indexStride=offset+1;
|
||||
//printf("sem=%s\n",sem);
|
||||
const char* src = input->Attribute("source");
|
||||
// const char* src = input->Attribute("source");
|
||||
|
||||
//printf("src=%s\n",src);
|
||||
const char* srcIdRef = input->Attribute("source");
|
||||
std::string source_name;
|
||||
@@ -226,7 +227,6 @@ void readLibraryGeometries(TiXmlDocument& doc, btAlignedObjectArray<GLInstanceGr
|
||||
{
|
||||
normalSourceName = vs->m_normalArrayId;
|
||||
normalOffset = offset;
|
||||
positionAndNormalInVertex = true;
|
||||
}
|
||||
}
|
||||
if (semName=="NORMAL")
|
||||
@@ -234,7 +234,6 @@ void readLibraryGeometries(TiXmlDocument& doc, btAlignedObjectArray<GLInstanceGr
|
||||
btAssert(normalSourceName.length()==0);
|
||||
normalSourceName = source_name;
|
||||
normalOffset = offset;
|
||||
positionAndNormalInVertex = false;
|
||||
}
|
||||
}
|
||||
numIndices = primitiveCount * 3;
|
||||
@@ -418,7 +417,7 @@ void readNodeHierarchy(TiXmlElement* node,btHashMap<btHashString,int>& name2Shap
|
||||
int* shapeIndexPtr = name2Shape[geomUrl];
|
||||
if (shapeIndexPtr)
|
||||
{
|
||||
int index = *shapeIndexPtr;
|
||||
// int index = *shapeIndexPtr;
|
||||
printf("found geom with index %d\n", *shapeIndexPtr);
|
||||
ColladaGraphicsInstance& instance = visualShapeInstances.expand();
|
||||
instance.m_shapeIndex = *shapeIndexPtr;
|
||||
@@ -555,7 +554,7 @@ void getUnitMeterScalingAndUpAxisTransform(TiXmlDocument& doc, btTransform& tr,
|
||||
void LoadMeshFromCollada(const char* relativeFileName, btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances, btTransform& upAxisTransform, float& unitMeterScaling,int clientUpAxis)
|
||||
{
|
||||
|
||||
GLInstanceGraphicsShape* instance = 0;
|
||||
// GLInstanceGraphicsShape* instance = 0;
|
||||
|
||||
//usually COLLADA files don't have that many visual geometries/shapes
|
||||
visualShapes.reserve(32);
|
||||
@@ -745,4 +744,4 @@ void LoadMeshFromColladaAssimp(const char* relativeFileName, btAlignedObjectArra
|
||||
|
||||
}
|
||||
|
||||
#endif //COMPARE_WITH_ASSIMP
|
||||
#endif //COMPARE_WITH_ASSIMP
|
||||
|
||||
@@ -117,7 +117,7 @@ ATTRIBUTE_ALIGNED16(class) btMatrix4x4
|
||||
return m_el[0].w() * v.x() + m_el[1].w() * v.y() + m_el[2].w() * v.z() + m_el[3].w() * v.w();
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btMatrix4x4
|
||||
SIMD_FORCE_INLINE btMatrix4x4 &
|
||||
operator*=(const btMatrix4x4& m)
|
||||
{
|
||||
setValue(
|
||||
@@ -125,6 +125,7 @@ ATTRIBUTE_ALIGNED16(class) btMatrix4x4
|
||||
m.tdotx(m_el[1]), m.tdoty(m_el[1]), m.tdotz(m_el[1]),m.tdotw(m_el[1]),
|
||||
m.tdotx(m_el[2]), m.tdoty(m_el[2]), m.tdotz(m_el[2]),m.tdotw(m_el[2]),
|
||||
m.tdotx(m_el[3]), m.tdoty(m_el[3]), m.tdotz(m_el[3]),m.tdotw(m_el[3]));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "../OpenGLWindow/SimpleOpenGL3App.h"
|
||||
#include "Wavefront2GLInstanceGraphicsShape.h"
|
||||
#include "../../Utils/b3ResourcePath.h"
|
||||
#include "Bullet3Common/b3FileUtils.h"
|
||||
|
||||
|
||||
#include "../CommonInterfaces/CommonRigidBodyBase.h"
|
||||
@@ -54,30 +56,17 @@ void ImportObjSetup::initPhysics()
|
||||
this->createEmptyDynamicsWorld();
|
||||
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
|
||||
m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe);
|
||||
const char* fileName = "samurai_monastry.obj";
|
||||
char relativeFileName[1024];
|
||||
const char* prefix[]={"./data/","../data/","../../data/","../../../data/","../../../../data/"};
|
||||
int prefixIndex=-1;
|
||||
{
|
||||
|
||||
int numPrefixes = sizeof(prefix)/sizeof(char*);
|
||||
|
||||
for (int i=0;i<numPrefixes;i++)
|
||||
{
|
||||
FILE* f = 0;
|
||||
sprintf(relativeFileName,"%s%s",prefix[i],fileName);
|
||||
f = fopen(relativeFileName,"r");
|
||||
if (f)
|
||||
{
|
||||
fclose(f);
|
||||
prefixIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prefixIndex<0)
|
||||
return;
|
||||
|
||||
|
||||
const char* fileName = "samurai_monastry.obj";
|
||||
char relativeFileName[1024];
|
||||
if (b3ResourcePath::findResourcePath(fileName, relativeFileName, 1024))
|
||||
{
|
||||
char pathPrefix[1024];
|
||||
|
||||
b3FileUtils::extractPath(relativeFileName, pathPrefix, 1024);
|
||||
|
||||
|
||||
|
||||
btVector3 shift(0,0,0);
|
||||
btVector3 scaling(10,10,10);
|
||||
@@ -86,7 +75,7 @@ void ImportObjSetup::initPhysics()
|
||||
{
|
||||
|
||||
std::vector<tinyobj::shape_t> shapes;
|
||||
std::string err = tinyobj::LoadObj(shapes, relativeFileName, prefix[prefixIndex]);
|
||||
std::string err = tinyobj::LoadObj(shapes, relativeFileName, pathPrefix);
|
||||
|
||||
GLInstanceGraphicsShape* gfxShape = btgCreateGraphicsShapeFromWavefrontObj(shapes);
|
||||
|
||||
@@ -106,7 +95,12 @@ void ImportObjSetup::initPhysics()
|
||||
m_guiHelper->getRenderInterface()->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
|
||||
|
||||
}
|
||||
}}
|
||||
else
|
||||
{
|
||||
b3Warning("Cannot find %s\n", fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CommonExampleInterface* ImportObjCreateFunc(struct CommonExampleOptions& options)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "../OpenGLWindow/SimpleOpenGL3App.h"
|
||||
#include "LoadMeshFromSTL.h"
|
||||
#include "../CommonInterfaces/CommonRigidBodyBase.h"
|
||||
#include "../../Utils/b3ResourcePath.h"
|
||||
|
||||
|
||||
|
||||
@@ -52,28 +53,12 @@ void ImportSTLSetup::initPhysics()
|
||||
|
||||
const char* fileName = "l_finger_tip.stl";
|
||||
char relativeFileName[1024];
|
||||
const char* prefix[]={"./data/","../data/","../../data/","../../../data/","../../../../data/"};
|
||||
int prefixIndex=-1;
|
||||
{
|
||||
|
||||
int numPrefixes = sizeof(prefix)/sizeof(char*);
|
||||
|
||||
for (int i=0;i<numPrefixes;i++)
|
||||
{
|
||||
FILE* f = 0;
|
||||
sprintf(relativeFileName,"%s%s",prefix[i],fileName);
|
||||
f = fopen(relativeFileName,"r");
|
||||
if (f)
|
||||
{
|
||||
fclose(f);
|
||||
prefixIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prefixIndex<0)
|
||||
return;
|
||||
if (!b3ResourcePath::findResourcePath(fileName, relativeFileName, 1024))
|
||||
{
|
||||
b3Warning("Cannot find file %s\n", fileName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
btVector3 shift(0,0,0);
|
||||
btVector3 scaling(10,10,10);
|
||||
|
||||
@@ -24,6 +24,7 @@ subject to the following restrictions:
|
||||
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
|
||||
#include "Bullet3Common/b3FileUtils.h"
|
||||
#include <string>
|
||||
#include "../../Utils/b3ResourcePath.h"
|
||||
|
||||
|
||||
|
||||
@@ -101,7 +102,8 @@ bool BulletURDFImporter::loadURDF(const char* fileName)
|
||||
|
||||
b3FileUtils fu;
|
||||
|
||||
bool fileFound = fu.findFile(fileName, relativeFileName, 1024);
|
||||
//bool fileFound = fu.findFile(fileName, relativeFileName, 1024);
|
||||
bool fileFound = b3ResourcePath::findResourcePath(fileName,relativeFileName,1024);
|
||||
|
||||
std::string xml_string;
|
||||
m_data->m_pathPrefix[0] = 0;
|
||||
@@ -390,7 +392,7 @@ void convertURDFToVisualShape(const UrdfVisual* visual, const char* urdfPathPref
|
||||
upAxis);
|
||||
|
||||
glmesh = new GLInstanceGraphicsShape;
|
||||
int index = 0;
|
||||
// int index = 0;
|
||||
glmesh->m_indices = new b3AlignedObjectArray<int>();
|
||||
glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>();
|
||||
|
||||
@@ -501,7 +503,7 @@ void convertURDFToVisualShape(const UrdfVisual* visual, const char* urdfPathPref
|
||||
|
||||
|
||||
glmesh = new GLInstanceGraphicsShape;
|
||||
int index = 0;
|
||||
// int index = 0;
|
||||
glmesh->m_indices = new b3AlignedObjectArray<int>();
|
||||
glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>();
|
||||
|
||||
@@ -702,7 +704,7 @@ btCollisionShape* convertURDFToCollisionShape(const UrdfCollision* collision, co
|
||||
upAxis );
|
||||
|
||||
glmesh = new GLInstanceGraphicsShape;
|
||||
int index = 0;
|
||||
// int index = 0;
|
||||
glmesh->m_indices = new b3AlignedObjectArray<int>();
|
||||
glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>();
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
#include "BulletDynamics/Featherstone/btMultiBodyJointMotor.h"
|
||||
#include "BulletDynamics/Featherstone/btMultiBodyDynamicsWorld.h"
|
||||
#include "../CommonInterfaces/CommonParameterInterface.h"
|
||||
#ifdef ENABLE_ROS_URDF
|
||||
#include "ROSURDFImporter.h"
|
||||
#endif
|
||||
#include "BulletUrdfImporter.h"
|
||||
|
||||
|
||||
@@ -197,18 +199,20 @@ void ImportUrdfSetup::initPhysics()
|
||||
//now print the tree using the new interface
|
||||
URDFImporterInterface* bla=0;
|
||||
|
||||
static bool newURDF = false;
|
||||
newURDF = !newURDF;
|
||||
static bool newURDF = true;
|
||||
if (newURDF)
|
||||
{
|
||||
b3Printf("using new URDF\n");
|
||||
bla = new BulletURDFImporter(m_guiHelper);
|
||||
} else
|
||||
}
|
||||
#ifdef USE_ROS_URDF
|
||||
else
|
||||
{
|
||||
b3Printf("using ROS URDF\n");
|
||||
bla = new ROSURDFImporter(m_guiHelper);
|
||||
}
|
||||
|
||||
newURDF = !newURDF;
|
||||
#endif//USE_ROS_URDF
|
||||
URDFImporterInterface& u2b = *bla;
|
||||
bool loadOk = u2b.loadURDF(m_fileName);
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#include "URDFJointTypes.h"
|
||||
|
||||
MyMultiBodyCreator::MyMultiBodyCreator(GUIHelperInterface* guiHelper)
|
||||
:m_guiHelper(guiHelper),
|
||||
m_bulletMultiBody(0)
|
||||
:m_bulletMultiBody(0),
|
||||
m_guiHelper(guiHelper)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ bool ROSURDFImporter::loadURDF(const char* fileName)
|
||||
m_data->m_robot->getLinks(m_data->m_links);
|
||||
|
||||
//initialize the 'index' of each link
|
||||
for (int i=0;i<m_data->m_links.size();i++)
|
||||
for (int i=0;i<(int)m_data->m_links.size();i++)
|
||||
{
|
||||
m_data->m_links[i]->m_link_index = i;
|
||||
}
|
||||
@@ -413,7 +413,7 @@ void ROSconvertURDFToVisualShape(const Visual* visual, const char* urdfPathPrefi
|
||||
upAxis);
|
||||
|
||||
glmesh = new GLInstanceGraphicsShape;
|
||||
int index = 0;
|
||||
//int index = 0;
|
||||
glmesh->m_indices = new b3AlignedObjectArray<int>();
|
||||
glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>();
|
||||
|
||||
@@ -524,7 +524,7 @@ void ROSconvertURDFToVisualShape(const Visual* visual, const char* urdfPathPrefi
|
||||
|
||||
|
||||
glmesh = new GLInstanceGraphicsShape;
|
||||
int index = 0;
|
||||
// int index = 0;
|
||||
glmesh->m_indices = new b3AlignedObjectArray<int>();
|
||||
glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>();
|
||||
|
||||
@@ -726,7 +726,7 @@ btCollisionShape* convertURDFToCollisionShape(const Collision* visual, const cha
|
||||
upAxis );
|
||||
|
||||
glmesh = new GLInstanceGraphicsShape;
|
||||
int index = 0;
|
||||
// int index = 0;
|
||||
glmesh->m_indices = new b3AlignedObjectArray<int>();
|
||||
glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>();
|
||||
|
||||
|
||||
@@ -73,9 +73,10 @@ void printTree(const URDFImporterInterface& u2b, int linkIndex, int indentationL
|
||||
struct URDF2BulletCachedData
|
||||
{
|
||||
URDF2BulletCachedData()
|
||||
:m_totalNumJoints1(0),
|
||||
m_currentMultiBodyLinkIndex(-1),
|
||||
m_bulletMultiBody(0)
|
||||
:
|
||||
m_currentMultiBodyLinkIndex(-1),
|
||||
m_bulletMultiBody(0),
|
||||
m_totalNumJoints1(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ static bool parseVector4(btVector4& vec4, const std::string& vector_str)
|
||||
btArray<std::string> pieces;
|
||||
btArray<float> rgba;
|
||||
urdfStringSplit(pieces, vector_str, urdfIsAnyOf(" "));
|
||||
for (unsigned int i = 0; i < pieces.size(); ++i)
|
||||
for (int i = 0; i < pieces.size(); ++i)
|
||||
{
|
||||
if (!pieces[i].empty())
|
||||
{
|
||||
@@ -39,7 +39,7 @@ static bool parseVector3(btVector3& vec3, const std::string& vector_str, ErrorLo
|
||||
btArray<std::string> pieces;
|
||||
btArray<float> rgba;
|
||||
urdfStringSplit(pieces, vector_str, urdfIsAnyOf(" "));
|
||||
for (unsigned int i = 0; i < pieces.size(); ++i)
|
||||
for (int i = 0; i < pieces.size(); ++i)
|
||||
{
|
||||
if (!pieces[i].empty())
|
||||
{
|
||||
@@ -844,4 +844,4 @@ bool UrdfParser::loadUrdf(const char* urdfText, ErrorLogger* logger)
|
||||
|
||||
return initTreeAndRoot(logger);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "PosixSharedMemory.h"
|
||||
#include "Win32SharedMemory.h"
|
||||
|
||||
#include "../Importers/ImportURDFDemo/ROSURDFImporter.h"
|
||||
#include "../Importers/ImportURDFDemo/BulletUrdfImporter.h"
|
||||
#include "../Importers/ImportURDFDemo/MyMultiBodyCreator.h"
|
||||
#include "../Importers/ImportURDFDemo/URDF2Bullet.h"
|
||||
|
||||
@@ -132,7 +132,7 @@ bool PhysicsServer::loadUrdf(const char* fileName, const btVector3& pos, const b
|
||||
bool useMultiBody, bool useFixedBase)
|
||||
{
|
||||
|
||||
ROSURDFImporter u2b(m_guiHelper);
|
||||
BulletURDFImporter u2b(m_guiHelper);
|
||||
bool loadOk = u2b.loadURDF(fileName);
|
||||
if (loadOk)
|
||||
{
|
||||
|
||||
@@ -22,8 +22,9 @@ files {
|
||||
"../Importers/ImportURDFDemo/MultiBodyCreationInterface.h",
|
||||
"../Importers/ImportURDFDemo/MyMultiBodyCreator.cpp",
|
||||
"../Importers/ImportURDFDemo/MyMultiBodyCreator.h",
|
||||
"../Importers/ImportURDFDemo/ROSURDFImporter.cpp",
|
||||
"../Importers/ImportURDFDemo/ROSURDFImporter.h",
|
||||
"../Importers/ImportURDFDemo/BulletUrdfImporter.cpp",
|
||||
"../Importers/ImportURDFDemo/BulletUrdfImporter.h",
|
||||
"../Importers/ImportURDFDemo/UrdfParser.cpp",
|
||||
"../Importers/ImportURDFDemo/BulletUrdfImporter.cpp",
|
||||
"../Importers/ImportURDFDemo/BulletUrdfImporter.h",
|
||||
"../Importers/ImportURDFDemo/urdfStringSplit.cpp",
|
||||
@@ -31,6 +32,7 @@ files {
|
||||
"../Importers/ImportURDFDemo/UrdfParser.h",
|
||||
"../Importers/ImportURDFDemo/URDF2Bullet.cpp",
|
||||
"../Importers/ImportURDFDemo/URDF2Bullet.h",
|
||||
"../Utils/b3ResourcePath.cpp",
|
||||
"../Importers/ImportURDFDemo/URDFImporterInterface.h",
|
||||
"../Importers/ImportURDFDemo/URDFJointTypes.h",
|
||||
"../Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.cpp",
|
||||
|
||||
80
examples/Utils/b3ResourcePath.cpp
Normal file
80
examples/Utils/b3ResourcePath.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "b3ResourcePath.h"
|
||||
#include "Bullet3Common/b3Logging.h"
|
||||
#ifdef __APPLE__
|
||||
#include <mach-o/dyld.h> /* _NSGetExecutablePath */
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
#else
|
||||
//not Mac, not Windows, let's cross the fingers it is Linux :-)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#include "Bullet3Common/b3FileUtils.h"
|
||||
#define B3_MAX_EXE_PATH_LEN 4096
|
||||
|
||||
int b3ResourcePath::getExePath(char* path, int maxPathLenInBytes)
|
||||
{
|
||||
int numBytes = 0;
|
||||
|
||||
#if __APPLE__
|
||||
uint32_t bufsize = uint32_t(maxPathLenInBytes);
|
||||
|
||||
if (_NSGetExecutablePath(path, &bufsize)!=0)
|
||||
{
|
||||
b3Warning("Cannot find executable path\n");
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
numBytes = strlen(path);
|
||||
}
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
#error not yet
|
||||
#else
|
||||
numBytes = (int)readlink("/proc/self/exe", path, maxPathLenInBytes-1);
|
||||
if (numBytes > 0)
|
||||
{
|
||||
path[numBytes] = 0;
|
||||
} else
|
||||
{
|
||||
b3Warning("Cannot find executable path\n");
|
||||
}
|
||||
#endif //_WIN32
|
||||
#endif //__APPLE__
|
||||
|
||||
return numBytes;
|
||||
}
|
||||
|
||||
int b3ResourcePath::findResourcePath(const char* resourceName, char* resourcePath, int resourcePathMaxNumBytes)
|
||||
{
|
||||
//first find in a resource/<exeName> location, then in various folders within 'data' using b3FileUtils
|
||||
char exePath[B3_MAX_EXE_PATH_LEN];
|
||||
|
||||
int l = b3ResourcePath::getExePath(exePath, B3_MAX_EXE_PATH_LEN);
|
||||
if (l)
|
||||
{
|
||||
char pathToExe[B3_MAX_EXE_PATH_LEN];
|
||||
|
||||
int exeNamePos = b3FileUtils::extractPath(exePath,pathToExe,B3_MAX_EXE_PATH_LEN);
|
||||
if (exeNamePos)
|
||||
{
|
||||
sprintf(resourcePath,"%s../resources/%s/%s",pathToExe,&exePath[exeNamePos],resourceName);
|
||||
//printf("try resource at %s\n", resourcePath);
|
||||
if (b3FileUtils::findFile(resourcePath, resourcePath, resourcePathMaxNumBytes))
|
||||
{
|
||||
return strlen(resourcePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool res = b3FileUtils::findFile(resourceName, resourcePath, resourcePathMaxNumBytes);
|
||||
if (res)
|
||||
{
|
||||
return strlen(resourcePath);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
13
examples/Utils/b3ResourcePath.h
Normal file
13
examples/Utils/b3ResourcePath.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _B3_RESOURCE_PATH_H
|
||||
#define _B3_RESOURCE_PATH_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class b3ResourcePath
|
||||
{
|
||||
public:
|
||||
static int getExePath(char* path, int maxPathLenInBytes);
|
||||
static int findResourcePath(const char* sourceName, char* resourcePath, int maxResourcePathLenInBytes);
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -15,7 +15,7 @@ struct b3FileUtils
|
||||
{
|
||||
}
|
||||
|
||||
bool findFile(const char* orgFileName, char* relativeFileName, int maxRelativeFileNameMaxLen)
|
||||
static bool findFile(const char* orgFileName, char* relativeFileName, int maxRelativeFileNameMaxLen)
|
||||
{
|
||||
FILE* f=0;
|
||||
f = fopen(orgFileName,"rb");
|
||||
@@ -33,7 +33,6 @@ struct b3FileUtils
|
||||
|
||||
f=0;
|
||||
bool fileFound = false;
|
||||
int result = 0;
|
||||
|
||||
for (int i=0;!f && i<numPrefixes;i++)
|
||||
{
|
||||
@@ -64,7 +63,7 @@ struct b3FileUtils
|
||||
const char * oriptr;
|
||||
const char * patloc;
|
||||
// find how many times the pattern occurs in the original string
|
||||
for (oriptr = name; patloc = strstr(oriptr, pattern); oriptr = patloc + patlen)
|
||||
for (oriptr = name; (patloc = strstr(oriptr, pattern)); oriptr = patloc + patlen)
|
||||
{
|
||||
patcnt++;
|
||||
}
|
||||
@@ -73,7 +72,7 @@ struct b3FileUtils
|
||||
|
||||
|
||||
|
||||
static void extractPath(const char* fileName, char* path, int maxPathLength)
|
||||
static int extractPath(const char* fileName, char* path, int maxPathLength)
|
||||
{
|
||||
const char* stripped = strip2(fileName, "/");
|
||||
stripped = strip2(stripped, "\\");
|
||||
@@ -91,12 +90,14 @@ struct b3FileUtils
|
||||
path[len]=0;
|
||||
} else
|
||||
{
|
||||
len = 0;
|
||||
b3Assert(maxPathLength>0);
|
||||
if (maxPathLength>0)
|
||||
{
|
||||
path[0] = 0;
|
||||
path[len] = 0;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static char toLowerChar(const char t)
|
||||
|
||||
Reference in New Issue
Block a user