瀏覽代碼

Merge branch 'viewer' of https://github.com/jdumas/libigl

Former-commit-id: ea1057bbe17d5750a2bb2784cd62c1fa18c60fe9
Daniele Panozzo 8 年之前
父節點
當前提交
0b4bad6249

+ 35 - 11
include/igl/viewer/Viewer.cpp

@@ -154,7 +154,7 @@ static void glfw_window_size(GLFWwindow* window, int width, int height)
   int w = width*highdpi;
   int h = height*highdpi;
 
-  __viewer->resize(w, h);
+  __viewer->post_resize(w, h);
 
   // TODO: repositioning of the nanogui
 }
@@ -278,6 +278,8 @@ namespace viewer
 
   IGL_INLINE Viewer::Viewer()
   {
+    window = nullptr;
+
 #ifdef IGL_VIEWER_WITH_NANOGUI
     ngui = nullptr;
     screen = nullptr;
@@ -322,8 +324,8 @@ namespace viewer
   O,o     Toggle orthographic/perspective projection
   T,t     Toggle filled faces
   Z       Snap to canonical view
-  [,]     Toggle between rotation control types (e.g. trackball, two-axis
-          valuator with fixed up))"
+  [,]     Toggle between rotation control types (trackball, two-axis
+          valuator with fixed up, 2D mode with no rotation))"
 #ifdef IGL_VIEWER_WITH_NANOGUI
 		R"(
   ;       Toggle vertex labels
@@ -537,13 +539,12 @@ namespace viewer
       case ']':
       {
         if(core.rotation_type == ViewerCore::ROTATION_TYPE_TRACKBALL)
-        {
-          core.set_rotation_type(
-            ViewerCore::ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP);
-        }else
-        {
+          core.set_rotation_type(ViewerCore::ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP);
+        else if (core.rotation_type == ViewerCore::ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP)
+          core.set_rotation_type(ViewerCore::ROTATION_TYPE_NO_ROTATION);
+        else
           core.set_rotation_type(ViewerCore::ROTATION_TYPE_TRACKBALL);
-        }
+
         return true;
       }
 #ifdef IGL_VIEWER_WITH_NANOGUI
@@ -626,7 +627,11 @@ namespace viewer
     switch (button)
     {
       case MouseButton::Left:
-        mouse_mode = MouseMode::Rotation;
+        if (core.rotation_type == ViewerCore::ROTATION_TYPE_NO_ROTATION) {
+          mouse_mode = MouseMode::Translation;
+        } else {
+          mouse_mode = MouseMode::Rotation;
+        }
         break;
 
       case MouseButton::Right:
@@ -687,6 +692,8 @@ namespace viewer
           {
             default:
               assert(false && "Unknown rotation type");
+            case ViewerCore::ROTATION_TYPE_NO_ROTATION:
+              break;
             case ViewerCore::ROTATION_TYPE_TRACKBALL:
               igl::trackball(
                 core.viewport(2),
@@ -841,8 +848,21 @@ namespace viewer
   }
 
   IGL_INLINE void Viewer::resize(int w,int h)
+  {
+    if (window) {
+      glfwSetWindowSize(window, w/highdpi, h/highdpi);
+    } else {
+      post_resize(w, h);
+    }
+  }
+
+  IGL_INLINE void Viewer::post_resize(int w,int h)
   {
     core.viewport = Eigen::Vector4f(0,0,w,h);
+    for (unsigned int i = 0; i<plugins.size(); ++i)
+    {
+      plugins[i]->post_resize(w, h);
+    }
   }
 
   IGL_INLINE void Viewer::snap_to_canonical_quaternion()
@@ -895,7 +915,11 @@ namespace viewer
     }
     else
     {
-      window = glfwCreateWindow(1280,800,"libigl viewer",nullptr,nullptr);
+      if (core.viewport.tail<2>().any()) {
+        window = glfwCreateWindow(core.viewport(2),core.viewport(3),"libigl viewer",nullptr,nullptr);
+      } else {
+        window = glfwCreateWindow(1280,800,"libigl viewer",nullptr,nullptr);
+      }
     }
 
     if (!window)

+ 2 - 1
include/igl/viewer/Viewer.h

@@ -119,7 +119,8 @@ namespace viewer
     IGL_INLINE void draw();
 
     // OpenGL context resize
-    IGL_INLINE void resize(int w,int h);
+    IGL_INLINE void resize(int w,int h); // explicitly set window size
+    IGL_INLINE void post_resize(int w,int h); // external resize due to user interaction
 
     // Helper functions
     IGL_INLINE void snap_to_canonical_quaternion();

+ 2 - 0
include/igl/viewer/ViewerCore.cpp

@@ -433,6 +433,8 @@ IGL_INLINE igl::viewer::ViewerCore::ViewerCore()
   line_width = 0.5f;
   is_animating = false;
   animation_max_fps = 30.;
+
+  viewport.setZero();
 }
 
 IGL_INLINE void igl::viewer::ViewerCore::init()

+ 2 - 1
include/igl/viewer/ViewerCore.h

@@ -88,7 +88,8 @@ public:
   {
     ROTATION_TYPE_TRACKBALL = 0,
     ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP = 1,
-    NUM_ROTATION_TYPES = 2
+    ROTATION_TYPE_NO_ROTATION = 2,
+    NUM_ROTATION_TYPES = 3
   };
   IGL_INLINE void set_rotation_type(const RotationType & value);
 

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

@@ -96,6 +96,11 @@ public:
     return false;
   }
 
+  // This function is called after the window has been resized
+  IGL_INLINE virtual void post_resize(int w, int h)
+  {
+  }
+
   // This function is called when the mouse button is pressed
   // - button can be GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON
   // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;

+ 2 - 2
python/tutorial/shared.py

@@ -1,8 +1,8 @@
 import pyigl as igl
 import sys
+import os
 
-
-TUTORIAL_SHARED_PATH = "../../tutorial/shared/"
+TUTORIAL_SHARED_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../tutorial/shared/")
 
 def check_dependencies(deps):
     available = [hasattr(igl, m) for m in deps]