diff --git a/include/igl/viewer/Viewer.cpp b/include/igl/viewer/Viewer.cpp index 5147eb974..560279e4c 100644 --- a/include/igl/viewer/Viewer.cpp +++ b/include/igl/viewer/Viewer.cpp @@ -47,7 +47,8 @@ #include #include -#include +#include +#include #include #include @@ -79,7 +80,7 @@ static int global_KMod = 0; static void glfw_mouse_press(GLFWwindow* window, int button, int action, int modifier) { - bool tw_used = __viewer->ngui->mouseButtonEvent(window,button,action,modifier); + bool tw_used = __viewer->screen->mouseButtonCallbackEvent(button,action,modifier); igl::viewer::Viewer::MouseButton mb; @@ -113,7 +114,7 @@ static void glfw_char_mods_callback(GLFWwindow* window, unsigned int codepoint, { // TODO: pass to nanogui (although it's also using physical key down/up // rather than character codes... - if(! __viewer->ngui->charEvent(window,codepoint) ) + if(! __viewer->screen->charCallbackEvent(codepoint) ) { __viewer->key_pressed(codepoint, modifier); } @@ -124,7 +125,7 @@ static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int act if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GL_TRUE); - if (__viewer->ngui->keyEvent(window,key,scancode,action,modifier) == false) + if (__viewer->screen->keyCallbackEvent(key,scancode,action,modifier) == false) { if (action == GLFW_PRESS) __viewer->key_down(key, modifier); @@ -145,7 +146,7 @@ static void glfw_window_size(GLFWwindow* window, int width, int height) static void glfw_mouse_move(GLFWwindow* window, double x, double y) { - if(__viewer->ngui->cursorPosEvent(window,x,y) == false || __viewer->down) + if(__viewer->screen->cursorPosCallbackEvent(x,y) == false || __viewer->down) { __viewer->mouse_move(x*highdpi, y*highdpi); } @@ -157,13 +158,13 @@ static void glfw_mouse_scroll(GLFWwindow* window, double x, double y) scroll_x += x; scroll_y += y; - if (__viewer->ngui->scrollEvent(window,x,y) == false) + if (__viewer->screen->scrollCallbackEvent(x,y) == false) __viewer->mouse_scroll(y); } static void glfw_drop_callback(GLFWwindow *window,int count,const char **filenames) { - __viewer->ngui->dropEvent(window,count,filenames); + __viewer->screen->dropCallbackEvent(count,filenames); } namespace igl @@ -174,69 +175,68 @@ namespace viewer { using namespace nanogui; - ngui->setInputCellSize(Eigen::Vector2i(60,20)); + ngui->setFixedSize(Eigen::Vector2i(60,20)); // Create nanogui widgets - ngui->addNewWindow(Eigen::Vector2i(10,10),"libIGL-Viewer"); + nanogui::Window *window = ngui->addWindow(Eigen::Vector2i(10,10),"libIGL-Viewer"); // ---------------------- LOADING ---------------------- #ifdef ENABLE_SERIALIZATION - ngui->addNewGroup("Workspace",FormScreen::Layout::Horizontal); + ngui->addGroup("Workspace"); ngui->addButton("Load",[&](){this->load_scene();}); ngui->addButton("Save",[&](){this->save_scene();}); #endif #ifdef ENABLE_IO - ngui->addNewGroup("Mesh",FormScreen::Layout::Horizontal); + ngui->addGroup("Mesh"); ngui->addButton("Load",[&](){this->open_dialog_load_mesh();}); ngui->addButton("Save",[&](){this->open_dialog_save_mesh();}); #endif - ngui->addNewGroup("Viewing Options",FormScreen::Layout::Vertical); + ngui->addGroup("Viewing Options"); ngui->addButton("Center object",[&](){this->core.align_camera_center(this->data.V,this->data.F);}); ngui->addButton("Snap canonical view",[&]() { this->snap_to_canonical_quaternion(); }); - ngui->addVariable(core.camera_zoom,"Zoom"); - ngui->addVariable(core.orthographic,"Orthographic view"); + ngui->addVariable("Zoom", core.camera_zoom); + ngui->addVariable("Orthographic view", core.orthographic); - ngui->addNewGroup("Draw options",FormScreen::Layout::Vertical); + ngui->addGroup("Draw options"); - ngui->addVariable([&](bool checked) + ngui->addVariable("Face-based", [&](bool checked) { this->data.set_face_based(checked); },[&]() { return this->data.face_based; - }, "Face-based",false); + }); - ngui->addVariable(core.show_texture,"Show texture"); + ngui->addVariable("Show texture",core.show_texture); - ngui->addVariable([&](bool checked) + ngui->addVariable("Invert normals",[&](bool checked) { this->data.dirty |= ViewerData::DIRTY_NORMAL; this->core.invert_normals = checked; },[&]() { return this->core.invert_normals; - }, - "Invert normals",false); + }); - ngui->addVariable(core.show_overlay,"Show overlay"); - ngui->addVariable(core.show_overlay_depth,"Show overlay depth"); - ngui->addColorPicker(core.background_color,"Background"); - ngui->addColorPicker(core.line_color,"Line color"); - ngui->addVariable(core.shininess,"Shininess"); + ngui->addVariable("Show overlay", core.show_overlay); + ngui->addVariable("Show overlay depth", core.show_overlay_depth); + ngui->addVariable("Background", (nanogui::Color &) core.background_color); + ngui->addVariable("Line color", (nanogui::Color &) core.line_color); + ngui->addVariable("Shininess", core.shininess); - ngui->addNewGroup("Overlays"); - ngui->addVariable(core.show_lines,"Wireframe"); - ngui->addVariable(core.show_faces,"Fill"); - ngui->addVariable(core.show_vertid,"Show vertex labels"); - ngui->addVariable(core.show_faceid,"Show faces labels"); + ngui->addGroup("Overlays"); + ngui->addVariable("Wireframe", core.show_lines); + ngui->addVariable("Fill", core.show_faces); + ngui->addVariable("Show vertex labels", core.show_vertid); + ngui->addVariable("Show faces labels", core.show_faceid); - ngui->layout(); + screen->performLayout(); core.init(); @@ -250,6 +250,7 @@ namespace viewer IGL_INLINE Viewer::Viewer() { ngui = nullptr; + screen = nullptr; // Temporary variables initialization down = false; @@ -290,7 +291,6 @@ namespace viewer IGL_INLINE Viewer::~Viewer() { - if(!ngui) delete ngui; } IGL_INLINE void Viewer::shutdown_plugins() @@ -646,7 +646,8 @@ namespace viewer if (plugins[i]->post_draw()) break; - ngui->draw(); + ngui->refresh(); + screen->drawWidgets(); } IGL_INLINE bool Viewer::save_scene() @@ -787,8 +788,9 @@ namespace viewer glfwSetInputMode(window,GLFW_CURSOR,GLFW_CURSOR_NORMAL); // Initialize FormScreen - ngui = new nanogui::FormScreen(); - ngui->init(window); + screen = new nanogui::Screen(); + screen->initialize(window, false); + ngui = new nanogui::FormHelper(screen); __viewer = this; @@ -860,6 +862,10 @@ namespace viewer core.shut(); shutdown_plugins(); + delete ngui; + //delete screen; + screen = nullptr; + ngui = nullptr; glfwDestroyWindow(window); glfwTerminate(); diff --git a/include/igl/viewer/Viewer.h b/include/igl/viewer/Viewer.h index d0a31198d..fdae40c9f 100644 --- a/include/igl/viewer/Viewer.h +++ b/include/igl/viewer/Viewer.h @@ -32,7 +32,7 @@ #define IGL_MOD_ALT 0x0004 #define IGL_MOD_SUPER 0x0008 -namespace nanogui { class FormScreen; } +namespace nanogui { class FormHelper; class Screen; } class GLFWwindow; @@ -78,7 +78,8 @@ namespace viewer bool down; bool hack_never_moved; - nanogui::FormScreen* ngui; + nanogui::FormHelper* ngui; + nanogui::Screen* screen; // Keep track of the global position of the scrollwheel float scroll_position; diff --git a/include/igl/viewer/ViewerCore.cpp b/include/igl/viewer/ViewerCore.cpp index ea5d339c5..cc41da4bf 100644 --- a/include/igl/viewer/ViewerCore.cpp +++ b/include/igl/viewer/ViewerCore.cpp @@ -460,8 +460,8 @@ IGL_INLINE igl::viewer::ViewerCore::ViewerCore() shininess = 35.0f; // Default colors - background_color << 0.3f, 0.3f, 0.5f; - line_color << 0.0f, 0.0f, 0.0f; + background_color << 0.3f, 0.3f, 0.5f, 1.0f; + line_color << 0.0f, 0.0f, 0.0f, 1.0f; // Default lights settings light_position << 0.0f, -0.30f, -5.0f; diff --git a/include/igl/viewer/ViewerCore.h b/include/igl/viewer/ViewerCore.h index 88b8a2823..1881bb04f 100644 --- a/include/igl/viewer/ViewerCore.h +++ b/include/igl/viewer/ViewerCore.h @@ -87,8 +87,8 @@ public: float shininess; // Colors - Eigen::Vector3f background_color; - Eigen::Vector3f line_color; + Eigen::Vector4f background_color; + Eigen::Vector4f line_color; // Lighting Eigen::Vector3f light_position; diff --git a/tutorial/106_ViewerMenu/main.cpp b/tutorial/106_ViewerMenu/main.cpp index bb0df0283..c0700baec 100755 --- a/tutorial/106_ViewerMenu/main.cpp +++ b/tutorial/106_ViewerMenu/main.cpp @@ -1,6 +1,7 @@ #include #include -#include +#include +#include #include Eigen::MatrixXd V; @@ -21,29 +22,29 @@ int main(int argc, char *argv[]) viewer.callback_init = [&](igl::viewer::Viewer& viewer) { // Add new group - viewer.ngui->addNewGroup("New Group"); + viewer.ngui->addGroup("New Group"); // Expose variable directly ... - viewer.ngui->addVariable(floatVariable,"float"); + viewer.ngui->addVariable("float",floatVariable); // ... or using a custom callback - viewer.ngui->addVariable([&](bool val) { + viewer.ngui->addVariable("bool",[&](bool val) { boolVariable = val; // set },[&]() { return boolVariable; // get - },"bool",true); + }); // Add a button viewer.ngui->addButton("Print Hello",[](){ std::cout << "Hello\n"; }); // Add an additional bar - viewer.ngui->addNewWindow(Eigen::Vector2i(220,10),"New Window"); + viewer.ngui->addWindow(Eigen::Vector2i(220,10),"New Window"); // Expose the same variable directly ... - viewer.ngui->addVariable(floatVariable,"float"); + viewer.ngui->addVariable("float",floatVariable); // Generate menu - viewer.ngui->layout(); + viewer.screen->performLayout(); return false; }; diff --git a/tutorial/CMakeLists.txt b/tutorial/CMakeLists.txt index 29e21db43..bc405f8ec 100644 --- a/tutorial/CMakeLists.txt +++ b/tutorial/CMakeLists.txt @@ -41,12 +41,6 @@ if(LIBIGL_USE_STATIC_LIBRARY) endif(LIBIGL_USE_STATIC_LIBRARY) include_directories("../include") -# if(True) -#Compile nanogui -add_subdirectory("../external/nanogui/" "nanogui") -include_directories("../external/nanogui/include") -include_directories("../external/nanogui/ext/nanovg/src") -list(APPEND SHARED_LIBRARIES "nanogui" "glfw") #Compile embree option(ENABLE_ISPC_SUPPORT " " OFF) @@ -70,6 +64,18 @@ list(APPEND SHARED_LIBRARIES "embree") # endif(True) +# if(True) +#Compile nanogui +set(NANOGUI_BUILD_PYTHON OFF CACHE BOOL " " FORCE) +set(NANOGUI_BUILD_EXAMPLE OFF CACHE BOOL " " FORCE) +set(NANOGUI_BUILD_SHARED OFF CACHE BOOL " " FORCE) + +add_subdirectory("../external/nanogui/" "nanogui") +include_directories("../external/nanogui/include") +include_directories("../external/nanogui/ext/nanovg/src") +list(APPEND SHARED_LIBRARIES "nanogui") + + #Compile CoMISo (if found) # NOTE: this cmakefile works only with the # comiso available here: https://github.com/libigl/CoMISo