collada_urdf: first try assimp, then fallback to STLLoader
This commit is contained in:
parent
6fd7f8a489
commit
1a48be8bb4
|
@ -101,8 +101,6 @@ void STLLoader::readBinary(FILE* filein, Mesh* mesh) {
|
|||
|
||||
int face_num = readLongInt(filein);
|
||||
|
||||
std::cout << "Reading " << face_num << " faces " << std::endl;
|
||||
|
||||
for (int iface = 0; iface < face_num; iface++) {
|
||||
Vector3 normal(readFloat(filein), readFloat(filein), readFloat(filein));
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
|
|
@ -279,7 +279,23 @@ public:
|
|||
return;
|
||||
}
|
||||
|
||||
if (true) {
|
||||
// Try assimp first, then STLLoader
|
||||
if (!loadMeshWithAssimp(resource, mesh))
|
||||
if (!loadMeshWithSTLLoader(resource, mesh))
|
||||
cerr << "*** Can't load " << filename << endl;
|
||||
}
|
||||
|
||||
bool loadMeshWithAssimp(const resource_retriever::MemoryResource& resource, domGeometryRef mesh) {
|
||||
// Import the mesh using assimp
|
||||
const aiScene* scene = importer_.ReadFileFromMemory(resource.data.get(), resource.size, aiProcess_SortByPType /* aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices */);
|
||||
if (!scene)
|
||||
return false;
|
||||
|
||||
buildMeshFromAssimp(scene->mRootNode, mesh);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loadMeshWithSTLLoader(const resource_retriever::MemoryResource& resource, domGeometryRef mesh) {
|
||||
// Write the resource to a temporary file
|
||||
char tmp_filename[] = "/tmp/collada_urdf_XXXXXX";
|
||||
int fd = mkstemp(tmp_filename);
|
||||
|
@ -288,22 +304,18 @@ public:
|
|||
|
||||
// Import the mesh using STLLoader
|
||||
STLLoader loader;
|
||||
Mesh* mesh = loader.load(string(tmp_filename));
|
||||
delete mesh;
|
||||
Mesh* stl_mesh = loader.load(string(tmp_filename));
|
||||
buildMeshFromSTLLoader(stl_mesh, mesh);
|
||||
delete stl_mesh;
|
||||
|
||||
// Delete the temporary file
|
||||
unlink(tmp_filename);
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
// Import the mesh using assimp
|
||||
const aiScene* scene = importer_.ReadFileFromMemory(resource.data.get(), resource.size, aiProcess_SortByPType /* aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices */);
|
||||
if (!scene)
|
||||
cerr << "Unable to import mesh " << filename << ": " << importer_.GetErrorString() << endl;
|
||||
else {
|
||||
cout << "Successfully loaded mesh " << filename << endl;
|
||||
buildMeshFromAssimp(scene->mRootNode, mesh);
|
||||
}
|
||||
}
|
||||
|
||||
void buildMeshFromSTLLoader(Mesh* mesh, daeElementRef parent) {
|
||||
//
|
||||
}
|
||||
|
||||
void buildMeshFromAssimp(aiNode* node, daeElementRef parent) {
|
||||
|
|
Loading…
Reference in New Issue