Created
January 11, 2021 11:55
-
-
Save maz-1/541238abfe1e4169e0e397e649b6bba5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// assimp | |
#include <assimp/Importer.hpp> // C++ importer interface | |
#include <assimp/scene.h> // Output data structure | |
#include <assimp/postprocess.h> // Post processing flags | |
#include <assimp/Exporter.hpp> | |
// openmesh | |
#include <OpenMesh/Core/IO/MeshIO.hh> | |
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh> | |
// write to buffer | |
size_t length = 200 * mesh_cloud.number_of_vertices(); | |
std::cout << length << std::endl; | |
auto pBuf = new char[length]; // allocate memory | |
struct membuf: std::streambuf // derive because std::streambuf constructor is protected | |
{ | |
membuf(char* p, size_t size) | |
{ | |
setp( p, p + size); // set start end end pointers | |
} | |
size_t written() {return pptr()-pbase();} // how many bytes were really written? | |
}; | |
membuf sbuf( pBuf, length ); // our buffer object | |
std::ostream out( &sbuf ); // stream using our buffer | |
OpenMesh::IO::write_mesh(mesh_out, out, "obj"); | |
out.flush(); | |
std::cout << "Nr of written bytes: " << sbuf.written() << std::endl; | |
// write with assimp | |
Assimp::Importer importer; | |
const aiScene* scene = importer.ReadFileFromMemory( pBuf, sbuf.written(), | |
aiProcess_Triangulate | | |
aiProcess_JoinIdenticalVertices | | |
aiProcess_SortByPType); | |
if( !scene) | |
{ | |
std::cerr << "import error" << std::endl; | |
} | |
else | |
{ | |
Assimp::Exporter exporter; | |
size_t exportFormatCount = exporter.GetExportFormatCount(); | |
const aiExportFormatDesc* format = nullptr; | |
for (size_t i = 0; i < exportFormatCount; ++i) | |
{ | |
if (strcmp("fbx",exporter.GetExportFormatDescription(i)->id)) | |
{ | |
format = exporter.GetExportFormatDescription(i); | |
break; | |
} | |
} | |
if (!format) | |
{ | |
std::cerr << "cannot export fbx" << std::endl; | |
} | |
else | |
{ | |
aiReturn ret = exporter.Export(scene, format->id, out_topograpy_mesh, scene->mFlags); | |
std::cout << "export fbx done" << std::endl; | |
} | |
} | |
delete pBuf; // free memory | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment