74 lines
1.8 KiB
C++
74 lines
1.8 KiB
C++
#include "per_vertex_normals.h"
|
|
#include "per_corner_normals.h"
|
|
#include "per_face_normals.h"
|
|
#include <igl/read_triangle_mesh.h>
|
|
#include <igl/opengl/glfw/Viewer.h>
|
|
|
|
int main(int argc, char * argv[])
|
|
{
|
|
// parse command line arguments
|
|
std::string path_to_obj;
|
|
if (argc == 2) {
|
|
std::string args = argv[1];
|
|
// check if ends with .obj
|
|
if (args.size() > 4 && args.substr(args.size() - 3, 3) == "obj") {
|
|
path_to_obj = args;
|
|
}
|
|
}
|
|
if (argc != 2 || path_to_obj.empty()) {
|
|
printf(
|
|
"Error: received unexpected command line arguments. \n"
|
|
"Correct usage: \n"
|
|
" Linux: ./normals <path to obj file> \n"
|
|
" Windows: normals.exe <path to obj file> \n"
|
|
"For example: \n"
|
|
" Linux: ./normals ../data/cube.obj \n"
|
|
" Windows: normals.exe ../../../data/cube.obj \n"
|
|
);
|
|
return -1;
|
|
}
|
|
Eigen::MatrixXd V;
|
|
Eigen::MatrixXi F;
|
|
igl::read_triangle_mesh(path_to_obj,V,F);
|
|
Eigen::MatrixXd VN,FN,CN;
|
|
// Compute different types of normals
|
|
per_face_normals(V,F,FN);
|
|
per_vertex_normals(V,F,VN);
|
|
per_corner_normals(V,F,20,CN);
|
|
// Set up and launch a little mesh viewer
|
|
igl::opengl::glfw::Viewer v;
|
|
v.data().set_mesh(V,F);
|
|
v.data().set_normals(VN);
|
|
// Keyboard interaction handling
|
|
v.callback_key_down = [&VN,&FN,&CN](
|
|
igl::opengl::glfw::Viewer & v,
|
|
unsigned char key,
|
|
int /*modifier*/
|
|
)->bool
|
|
{
|
|
switch(key)
|
|
{
|
|
default:
|
|
return false;
|
|
case '1':
|
|
v.data().set_normals(FN);
|
|
break;
|
|
case '2':
|
|
// viewer is weird and need to convince it out of CN mode
|
|
v.data().set_normals(FN);
|
|
v.data().set_normals(VN);
|
|
break;
|
|
case '3':
|
|
v.data().set_normals(CN);
|
|
break;
|
|
}
|
|
return true;
|
|
};
|
|
std::cout<< R"(
|
|
1 Use per-face normals
|
|
2 Use per-vertex normals
|
|
3 Use per-corner normals
|
|
)";
|
|
v.launch();
|
|
}
|
|
|