.obj格式文件转.off文件代码|小知识

发布于 2021-07-10  21 次阅读


.obj格式文件转.off文件代码(只需更改目标文件地址即可使用)

//OPENMESH
#define _USE_MATH_DEFINES
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>


#ifdef _DEBUG
#pragma comment(lib, "OpenMeshCored.lib")
#pragma comment(lib, "OpenMeshToolsd.lib")
#else
#pragma comment(lib, "OpenMeshCore.lib")
#pragma comment(lib, "OpenMeshTools.lib")
#endif // _DEBUG


typedef OpenMesh::TriMesh_ArrayKernelT<> MyTriMesh;
using namespace OpenMesh;
using namespace std;

int main(int argc, char** argv)
{


    MyTriMesh mesh;
    IO::Options ropt;
    ropt += IO::Options::Binary;
    ropt += IO::Options::Swap;


    char filename[256];
    for (int i = 0; i < 1; i++) {
        //Load Mesh with openmesh
        sprintf_s(filename, "E:/project/c++/OpenGL/study/glfw_glad练习/test5/models/k526efluton4-House_15/247_House 15_obj.obj", i);
        //要转换的obj文件地址
        if (!IO::read_mesh(mesh, filename, ropt))
        {
            std::cerr << "Error loading mesh from file " << filename << std::endl;
            return false;
        }
        sprintf_s(filename, "E:/project/c++/OpenGL/study/glfw_glad练习/test5/models/k526efluton4-House_15/247_House 15_obj.off", i);
        //目的off文件地址
        if (!OpenMesh::IO::write_mesh(mesh, filename))
        {
            std::cerr << "Cannot write mesh to file " << filename << std::endl;
        }
        else
            cout << "successfully save mesh to " << filename << endl;
    }
}