First pass of load files through an interface (to allow loading from memory, zip file etc). So instead of posix fopen/fread, using CommonFileIOInterface.
A fileIO plugin can override custom file IO operations. As a small test, load files from a zipfile in memory. Default fileIO implementation is in examples/Utils/b3BulletDefaultFileIO.h Affects URDF, SDF, MJCF, Wavefront OBJ, STL, DAE, images.
This commit is contained in:
@@ -24,7 +24,7 @@ subject to the following restrictions:
|
||||
#include "LoadMeshFromCollada.h"
|
||||
#include "Bullet3Common/b3FileUtils.h"
|
||||
#include "../../Utils/b3ResourcePath.h"
|
||||
|
||||
#include "../../Utils/b3BulletDefaultFileIO.h"
|
||||
#include "../CommonInterfaces/CommonRigidBodyBase.h"
|
||||
|
||||
class ImportColladaSetup : public CommonRigidBodyBase
|
||||
@@ -79,7 +79,7 @@ void ImportColladaSetup::initPhysics()
|
||||
|
||||
char relativeFileName[1024];
|
||||
|
||||
if (!b3ResourcePath::findResourcePath(fileName, relativeFileName, 1024))
|
||||
if (!b3ResourcePath::findResourcePath(fileName, relativeFileName, 1024,0))
|
||||
return;
|
||||
|
||||
btVector3 shift(0, 0, 0);
|
||||
@@ -94,7 +94,7 @@ void ImportColladaSetup::initPhysics()
|
||||
btTransform upAxisTrans;
|
||||
upAxisTrans.setIdentity();
|
||||
|
||||
btVector3 color(0, 0, 1);
|
||||
btVector4 color(0, 0, 1,1);
|
||||
|
||||
#ifdef COMPARE_WITH_ASSIMP
|
||||
static int useAssimp = 0;
|
||||
@@ -119,7 +119,8 @@ void ImportColladaSetup::initPhysics()
|
||||
{
|
||||
fileIndex = 0;
|
||||
}
|
||||
LoadMeshFromCollada(relativeFileName, visualShapes, visualShapeInstances, upAxisTrans, unitMeterScaling, upAxis);
|
||||
b3BulletDefaultFileIO fileIO;
|
||||
LoadMeshFromCollada(relativeFileName, visualShapes, visualShapeInstances, upAxisTrans, unitMeterScaling, upAxis,&fileIO);
|
||||
#endif // COMPARE_WITH_ASSIMP
|
||||
|
||||
//at the moment our graphics engine requires instances that share the same visual shape to be added right after registering the shape
|
||||
|
||||
@@ -22,10 +22,11 @@ subject to the following restrictions:
|
||||
#include "../../ThirdPartyLibs/tinyxml2/tinyxml2.h"
|
||||
using namespace tinyxml2;
|
||||
|
||||
#include "Bullet3Common/b3FileUtils.h"
|
||||
|
||||
#include "LinearMath/btHashMap.h"
|
||||
#include <assert.h>
|
||||
#include "btMatrix4x4.h"
|
||||
#include "../../CommonInterfaces/CommonFileIOInterface.h"
|
||||
|
||||
#define MAX_VISUAL_SHAPES 512
|
||||
|
||||
@@ -561,7 +562,7 @@ void getUnitMeterScalingAndUpAxisTransform(XMLDocument& doc, btTransform& tr, fl
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMeshFromCollada(const char* relativeFileName, btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances, btTransform& upAxisTransform, float& unitMeterScaling, int clientUpAxis)
|
||||
void LoadMeshFromCollada(const char* relativeFileName, btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances, btTransform& upAxisTransform, float& unitMeterScaling, int clientUpAxis, struct CommonFileIOInterface* fileIO)
|
||||
{
|
||||
// GLInstanceGraphicsShape* instance = 0;
|
||||
|
||||
@@ -570,16 +571,32 @@ void LoadMeshFromCollada(const char* relativeFileName, btAlignedObjectArray<GLIn
|
||||
|
||||
float extraScaling = 1; //0.01;
|
||||
btHashMap<btHashString, int> name2ShapeIndex;
|
||||
b3FileUtils f;
|
||||
|
||||
char filename[1024];
|
||||
if (!f.findFile(relativeFileName, filename, 1024))
|
||||
if (!fileIO->findResourcePath(relativeFileName, filename, 1024))
|
||||
{
|
||||
b3Warning("File not found: %s\n", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
XMLDocument doc;
|
||||
if (doc.LoadFile(filename) != XML_SUCCESS)
|
||||
//doc.Parse((const char*)filedata, 0, TIXML_ENCODING_UTF8);
|
||||
b3AlignedObjectArray<char> xmlString;
|
||||
int fileHandle = fileIO->fileOpen(filename,"r");
|
||||
if (fileHandle>=0)
|
||||
{
|
||||
int size = fileIO->getFileSize(fileHandle);
|
||||
xmlString.resize(size);
|
||||
int actual = fileIO->fileRead(fileHandle, &xmlString[0],size);
|
||||
if (actual==size)
|
||||
{
|
||||
}
|
||||
}
|
||||
if (xmlString.size()==0)
|
||||
return;
|
||||
|
||||
if (doc.Parse(&xmlString[0], xmlString.size()) != XML_SUCCESS)
|
||||
//if (doc.LoadFile(filename) != XML_SUCCESS)
|
||||
return;
|
||||
|
||||
//We need units to be in meter, so apply a scaling using the asset/units meter
|
||||
|
||||
@@ -28,7 +28,8 @@ void LoadMeshFromCollada(const char* relativeFileName,
|
||||
btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances,
|
||||
btTransform& upAxisTrans,
|
||||
float& unitMeterScaling,
|
||||
int clientUpAxis);
|
||||
int clientUpAxis,
|
||||
struct CommonFileIOInterface* fileIO);
|
||||
|
||||
//#define COMPARE_WITH_ASSIMP
|
||||
#ifdef COMPARE_WITH_ASSIMP
|
||||
|
||||
Reference in New Issue
Block a user