소스 검색

revert 107; do not rely on imgui

Former-commit-id: eb1d95e24613ec14272ac8395830b9dbb1a51315
Alec Jacobson 7 년 전
부모
커밋
b77c5ba4a9
2개의 변경된 파일15개의 추가작업 그리고 48개의 파일을 삭제
  1. 1 1
      tutorial/107_MultipleMeshes/CMakeLists.txt
  2. 14 47
      tutorial/107_MultipleMeshes/main.cpp

+ 1 - 1
tutorial/107_MultipleMeshes/CMakeLists.txt

@@ -2,4 +2,4 @@ cmake_minimum_required(VERSION 2.8.12)
 project(107_MultipleMeshes)
 project(107_MultipleMeshes)
 
 
 add_executable(${PROJECT_NAME}_bin main.cpp)
 add_executable(${PROJECT_NAME}_bin main.cpp)
-target_link_libraries(${PROJECT_NAME}_bin igl::core igl::opengl igl::opengl_glfw igl::opengl_glfw_imgui tutorials)
+target_link_libraries(${PROJECT_NAME}_bin igl::core igl::opengl igl::opengl_glfw tutorials)

+ 14 - 47
tutorial/107_MultipleMeshes/main.cpp

@@ -1,68 +1,35 @@
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 #include <igl/opengl/glfw/Viewer.h>
 #include <igl/opengl/glfw/Viewer.h>
-#include <igl/opengl/glfw/imgui/ImGuiMenu.h>
-#include <igl/opengl/glfw/imgui/ImGuiHelpers.h>
 #include <string>
 #include <string>
-#include <map>
 #include <iostream>
 #include <iostream>
 
 
-// Add custom data to a viewer mesh
-struct MeshData
-{
-  std::string name;
-  Eigen::RowVector3d color;
-};
-int last_colored_index = -1;
-
-// Set colors of each mesh
-void update_colors(igl::opengl::glfw::Viewer &viewer)
-{
-  for (auto &data : viewer.data_list)
-  {
-    data.set_colors(data.attr<MeshData>().color);
-  }
-  viewer.data_list[viewer.selected_data_index].set_colors(Eigen::RowVector3d(0.9,0.1,0.1));
-  last_colored_index = viewer.selected_data_index;
-}
-
 int main(int argc, char * argv[])
 int main(int argc, char * argv[])
 {
 {
   igl::opengl::glfw::Viewer viewer;
   igl::opengl::glfw::Viewer viewer;
-  auto names = {"cube.obj","sphere.obj","xcylinder.obj","ycylinder.obj","zcylinder.obj"};
+  const auto names = 
+    {"cube.obj","sphere.obj","xcylinder.obj","ycylinder.obj","zcylinder.obj"};
   for(const auto & name : names)
   for(const auto & name : names)
   {
   {
     viewer.load_mesh_from_file(std::string(TUTORIAL_SHARED_PATH) + "/" + name);
     viewer.load_mesh_from_file(std::string(TUTORIAL_SHARED_PATH) + "/" + name);
-    viewer.data().attr<MeshData>().name = name;
-    viewer.data().attr<MeshData>().color = Eigen::RowVector3d::Random();
   }
   }
 
 
-  // Attach a custom menu
-  igl::opengl::glfw::imgui::ImGuiMenu menu;
-  viewer.plugins.push_back(&menu);
-
-  // Customize default menu
-  menu.draw_viewer_menu_func = [&]()
-  {
-    if (ImGui::Combo("Selected Mesh", (int *) &viewer.selected_data_index,
-          [&](int i) { return viewer.data_list[i].attr<MeshData>().name.c_str(); },
-          viewer.data_list.size())
-      || last_colored_index != viewer.selected_data_index)
-    {
-      update_colors(viewer);
-    }
-  };
-
-  // Color each mesh differently
-  update_colors(viewer);
-
-  viewer.callback_key_down =
+  // Set colors of each mesh by selecting its index first
+  viewer.selected_data_index = 0;
+  viewer.data().set_colors(Eigen::RowVector3d(0.8,0.47,0.22));
+  viewer.selected_data_index = 1;
+  viewer.data().set_colors(Eigen::RowVector3d(0.6,0.01,0.11));
+  viewer.selected_data_index = 2;
+  viewer.data().set_colors(Eigen::RowVector3d(0.37,0.06,0.25));
+  viewer.selected_data_index = 3;
+  viewer.data().set_colors(Eigen::RowVector3d(1,1,1));
+
+  viewer.callback_key_down = 
     [&](igl::opengl::glfw::Viewer &, unsigned int key, int mod)
     [&](igl::opengl::glfw::Viewer &, unsigned int key, int mod)
   {
   {
     // Delete
     // Delete
-    if(key == '3')
+    if(key == 3)
     {
     {
       viewer.erase_mesh(viewer.selected_data_index);
       viewer.erase_mesh(viewer.selected_data_index);
-      update_colors(viewer);
       return true;
       return true;
     }
     }
     return false;
     return false;