main.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "tutorial_shared_path.h"
  2. #include <igl/opengl/glfw/Viewer.h>
  3. #include <GLFW/glfw3.h>
  4. #include <string>
  5. #include <iostream>
  6. int main(int argc, char * argv[])
  7. {
  8. igl::opengl::glfw::Viewer viewer;
  9. const auto names =
  10. {"cube.obj","sphere.obj","xcylinder.obj","ycylinder.obj","zcylinder.obj"};
  11. for(const auto & name : names)
  12. {
  13. viewer.load_mesh_from_file(std::string(TUTORIAL_SHARED_PATH) + "/" + name);
  14. }
  15. // Set colors of each mesh by selecting its index first
  16. viewer.selected_data_index = 0;
  17. viewer.data().set_colors(Eigen::RowVector3d(0.8,0.47,0.22));
  18. viewer.selected_data_index = 1;
  19. viewer.data().set_colors(Eigen::RowVector3d(0.6,0.01,0.11));
  20. viewer.selected_data_index = 2;
  21. viewer.data().set_colors(Eigen::RowVector3d(0.37,0.06,0.25));
  22. viewer.selected_data_index = 3;
  23. viewer.data().set_colors(Eigen::RowVector3d(1,1,1));
  24. viewer.callback_key_down =
  25. [&](igl::opengl::glfw::Viewer &, unsigned int key, int mod)
  26. {
  27. if(key == GLFW_KEY_BACKSPACE)
  28. {
  29. viewer.erase_mesh(viewer.selected_data_index);
  30. return true;
  31. }
  32. return false;
  33. };
  34. viewer.launch();
  35. return EXIT_SUCCESS;
  36. }