main.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include <igl/readOFF.h>
  2. #include <igl/opengl/glfw/Viewer.h>
  3. #include <igl/opengl/glfw/imgui/ImGuiMenu.h>
  4. #include <igl/opengl/glfw/imgui/ImGuiHelpers.h>
  5. #include <imgui/imgui.h>
  6. #include <iostream>
  7. #include "tutorial_shared_path.h"
  8. class MyMenu : public igl::opengl::glfw::imgui::ImGuiMenu
  9. {
  10. float floatVariable = 0.1f; // Shared between two menus
  11. virtual void draw_viewer_menu() override
  12. {
  13. // Draw parent menu
  14. ImGuiMenu::draw_viewer_menu();
  15. // Add new group
  16. if (ImGui::CollapsingHeader("New Group", ImGuiTreeNodeFlags_DefaultOpen))
  17. {
  18. // Expose variable directly ...
  19. ImGui::InputFloat("float", &floatVariable, 0, 0, 3);
  20. // ... or using a custom callback
  21. static bool boolVariable = true;
  22. if (ImGui::Checkbox("bool", &boolVariable))
  23. {
  24. // do something
  25. std::cout << "boolVariable: " << std::boolalpha << boolVariable << std::endl;
  26. }
  27. // Expose an enumeration type
  28. enum Orientation { Up=0, Down, Left, Right };
  29. static Orientation dir = Up;
  30. ImGui::Combo("Direction", (int *)(&dir), "Up\0Down\0Left\0Right\0\0");
  31. // We can also use a std::vector<std::string> defined dynamically
  32. static int num_choices = 3;
  33. static std::vector<std::string> choices;
  34. static int idx_choice = 0;
  35. if (ImGui::InputInt("Num letters", &num_choices))
  36. {
  37. num_choices = std::max(1, std::min(26, num_choices));
  38. }
  39. if (num_choices != (int) choices.size())
  40. {
  41. choices.resize(num_choices);
  42. for (int i = 0; i < num_choices; ++i)
  43. choices[i] = std::string(1, 'A' + i);
  44. if (idx_choice >= num_choices)
  45. idx_choice = num_choices - 1;
  46. }
  47. ImGui::Combo("Letter", &idx_choice, choices);
  48. // Add a button
  49. if (ImGui::Button("Print Hello", ImVec2(-1,0)))
  50. {
  51. std::cout << "Hello\n";
  52. }
  53. }
  54. }
  55. virtual void draw_other_menu() override
  56. {
  57. // Define next window position + size
  58. ImGui::SetNextWindowPos(ImVec2(180.f * menu_scaling(), 10), ImGuiSetCond_FirstUseEver);
  59. ImGui::SetNextWindowSize(ImVec2(200, 160), ImGuiSetCond_FirstUseEver);
  60. ImGui::Begin(
  61. "New Window", nullptr,
  62. ImGuiWindowFlags_NoSavedSettings
  63. );
  64. // Expose the same variable directly ...
  65. ImGui::PushItemWidth(-80);
  66. ImGui::DragFloat("float", &floatVariable, 0.0, 0.0, 3.0);
  67. ImGui::PopItemWidth();
  68. static std::string str = "bunny";
  69. ImGui::InputText("Name", str);
  70. ImGui::End();
  71. }
  72. };
  73. int main(int argc, char *argv[])
  74. {
  75. Eigen::MatrixXd V;
  76. Eigen::MatrixXi F;
  77. // Load a mesh in OFF format
  78. igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
  79. // Init the viewer
  80. igl::opengl::glfw::Viewer viewer;
  81. // Attach a custom menu
  82. MyMenu menu;
  83. // viewer.core.is_animating = true;
  84. viewer.plugins.push_back(&menu);
  85. // Plot the mesh
  86. viewer.data().set_mesh(V, F);
  87. viewer.launch();
  88. }