Ver código fonte

erase_mesh in tutorial

Former-commit-id: 9067548cb47dfe3dc5fdfa6e63a36f45828e6803
Alec Jacobson 7 anos atrás
pai
commit
d28530e2e0

+ 4 - 1
include/igl/opengl/glfw/Viewer.cpp

@@ -1100,10 +1100,13 @@ namespace glfw
     }
     data_list.erase(data_list.begin()                 + index);
     opengl_state_list.erase(opengl_state_list.begin() + index);
-    if(selected_data_index >= index)
+    if(selected_data_index >= index && selected_data_index>0)
     {
       selected_data_index--;
     }
+    std::cout<<"data: "<<data_list.size()<<std::endl;
+    std::cout<<"opengl_state: "<<opengl_state_list.size()<<std::endl;
+    std::cout<<"selected_data_index: "<<selected_data_index<<std::endl;
     return true;
   }
 

+ 30 - 13
tutorial/107_MultipleMeshes/main.cpp

@@ -1,23 +1,40 @@
 #include "tutorial_shared_path.h"
 #include <igl/opengl/glfw/Viewer.h>
 #include <string>
+#include <iostream>
 
 int main(int argc, char * argv[])
 {
-  igl::opengl::glfw::Viewer v;
-  for(const auto & name : 
-    {"cube.obj","sphere.obj","xcylinder.obj","ycylinder.obj","zcylinder.obj"})
+  igl::opengl::glfw::Viewer viewer;
+  const auto names = 
+    {"cube.obj","sphere.obj","xcylinder.obj","ycylinder.obj","zcylinder.obj"};
+  for(const auto & name : names)
   {
-    v.load_mesh_from_file(std::string(TUTORIAL_SHARED_PATH) + "/" + name);
+    viewer.load_mesh_from_file(std::string(TUTORIAL_SHARED_PATH) + "/" + name);
   }
-  v.selected_data_index = 0;
-  v.selected_data().set_colors(Eigen::RowVector3d(0.8,0.47,0.22));
-  v.selected_data_index = 1;
-  v.selected_data().set_colors(Eigen::RowVector3d(0.6,0.01,0.11));
-  v.selected_data_index = 2;
-  v.selected_data().set_colors(Eigen::RowVector3d(0.37,0.06,0.25));
-  v.selected_data_index = 3;
-  v.selected_data().set_colors(Eigen::RowVector3d(1,1,1));
-  v.launch();
+
+  // Set colors of each mesh by selecting its index first
+  viewer.selected_data_index = 0;
+  viewer.selected_data().set_colors(Eigen::RowVector3d(0.8,0.47,0.22));
+  viewer.selected_data_index = 1;
+  viewer.selected_data().set_colors(Eigen::RowVector3d(0.6,0.01,0.11));
+  viewer.selected_data_index = 2;
+  viewer.selected_data().set_colors(Eigen::RowVector3d(0.37,0.06,0.25));
+  viewer.selected_data_index = 3;
+  viewer.selected_data().set_colors(Eigen::RowVector3d(1,1,1));
+
+  viewer.callback_key_down = 
+    [&](igl::opengl::glfw::Viewer &, unsigned int key, int mod)
+  {
+    // Delete
+    if(key == 3)
+    {
+      viewer.erase_mesh(viewer.selected_data_index);
+      return true;
+    }
+    return false;
+  };
+
+  viewer.launch();
   return EXIT_SUCCESS;
 }