如何使用OpenMesh编写具有面法线的OBJ文件?

时间:2019-04-15 16:46:39

标签: c++ openmesh

我正在尝试使用带有面法线的OpenMesh将网格导出为OBJ文件。有什么办法吗?

OpenMesh::IO documentation显示OBJ格式支持脸部法线。但是当我在请求面部法线后尝试导出网格物体时,出现此错误:

[OBJWriter] : FaceNormal not supported by OBJ Writer

这是我尝试使用面法线导出简单的四面体。

MyMesh mesh;

MyMesh::VertexHandle vhandle[4];
vhandle[0] = mesh.add_vertex(MyMesh::Point(-1, 0, 0));
vhandle[1] = mesh.add_vertex(MyMesh::Point( 1, 0, 0));
vhandle[2] = mesh.add_vertex(MyMesh::Point( 0, 1, 0));
vhandle[3] = mesh.add_vertex(MyMesh::Point( 0, 0, 1));

std::vector<MyMesh::VertexHandle> face_vhandles;

face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[3]);
mesh.add_face(face_vhandles);

face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[3]);
mesh.add_face(face_vhandles);

face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[3]);
mesh.add_face(face_vhandles);

face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[1]);
mesh.add_face(face_vhandles);

mesh.request_face_normals();

OpenMesh::IO::Options wopt;
wopt += OpenMesh::IO::Options::FaceNormal;

if (!OpenMesh::IO::write_mesh(mesh, "teste.obj", wopt))
{
    return EXIT_FAILURE;
}

0 个答案:

没有答案