Przeglądaj źródła

some changes in the viewer, untested

Former-commit-id: 5ca19715772d5b74329df62fbb94d82f65ce8cb8
Daniele Panozzo 9 lat temu
rodzic
commit
ac7a11bf5c

+ 21 - 4
include/igl/viewer/Viewer.cpp

@@ -725,10 +725,9 @@ namespace viewer
     this->save_mesh_to_file(fname.c_str());
   }
 
-  IGL_INLINE int Viewer::launch(bool resizable,bool fullscreen)
-  {
-    GLFWwindow* window;
 
+  IGL_INLINE int  Viewer::launch_init(bool resizable,bool fullscreen)
+  {
     glfwSetErrorCallback(glfw_error_callback);
     if (!glfwInit())
       return EXIT_FAILURE;
@@ -817,7 +816,12 @@ namespace viewer
 
     // Initialize IGL viewer
     init();
+  }
 
+  IGL_INLINE bool Viewer::launch_rendering(bool loop)
+  {
+    glfwMakeContextCurrent(window);
+    
     // Rendering loop
     while (!glfwWindowShouldClose(window))
     {
@@ -840,8 +844,14 @@ namespace viewer
       {
         glfwWaitEvents();
       }
+
+      if (!loop)
+        return !glfwWindowShouldClose(window);
     }
+  }
 
+  IGL_INLINE void Viewer::launch_shut()
+  {
     opengl.free();
     core.shut();
 
@@ -849,7 +859,14 @@ namespace viewer
 
     glfwDestroyWindow(window);
     glfwTerminate();
-    return EXIT_SUCCESS;
+    return;
+  }
+
+  IGL_INLINE int Viewer::launch(bool resizable,bool fullscreen)
+  {
+    launch_init(resizable,fullscreen);
+    launch_rendering(true);
+    launch_shut();
   }
 } // end namespace
 }

+ 5 - 0
include/igl/viewer/Viewer.h

@@ -42,8 +42,13 @@ namespace viewer
   class Viewer
   {
   public:
+    GLFWwindow* window;
 
     IGL_INLINE int launch(bool resizable = true,bool fullscreen = false);
+    IGL_INLINE int launch_init(bool resizable = true,bool fullscreen = false);
+    IGL_INLINE bool launch_rendering(bool loop = true);
+    IGL_INLINE void launch_shut();
+
     IGL_INLINE void init();
 
     // Stores all the viewing options

+ 3 - 0
python/py_igl_viewer.cpp

@@ -287,6 +287,9 @@ py::class_<igl::viewer::ViewerCore> viewercore_class(me, "ViewerCore");
     .def_readwrite("data", &igl::viewer::Viewer::data)
     .def_readwrite("core", &igl::viewer::Viewer::core)
     .def("launch", &igl::viewer::Viewer::launch, py::arg("resizable") = true, py::arg("fullscreen") = false)
+    .def("launch_init", &igl::viewer::Viewer::launch_init, py::arg("resizable") = true, py::arg("fullscreen") = false)
+    .def("launch_rendering", &igl::viewer::Viewer::launch_rendering, py::arg("loop") = true)
+    .def("launch_shut", &igl::viewer::Viewer::launch_shut)
     .def("init", &igl::viewer::Viewer::init)
     .def("serialize", [](igl::viewer::Viewer& viewer)
     {