Jelajahi Sumber

draw mesh with TC, lens flare had weird stray line

Former-commit-id: 5b2504efc045b0b45d0e971d99f52715f0e9341d
Alec Jacobson (jalec 11 tahun lalu
induk
melakukan
de5bb8e10c
4 mengubah file dengan 95 tambahan dan 12 penghapusan
  1. 2 1
      include/igl/draw_floor.h
  2. 72 2
      include/igl/draw_mesh.cpp
  3. 15 3
      include/igl/draw_mesh.h
  4. 6 6
      include/igl/lens_flare.cpp

+ 2 - 1
include/igl/draw_floor.h

@@ -5,7 +5,8 @@
 namespace igl
 {
   // Draw a checkerboard floor aligned with current (X,Z) plane using OpenGL
-  // calls.
+  // calls. side=50 centered at (0,0):
+  //   (-25,-25)-->(-25,25)-->(25,25)-->(25,-25)
   //
   // Use glPushMatrix(), glScaled(), glTranslated() to arrange the floor.
   // 

+ 72 - 2
include/igl/draw_mesh.cpp

@@ -42,8 +42,74 @@ IGL_INLINE void igl::draw_mesh(
     // loop over corners of triangle
     for(int j = 0;j<3;j++)
     {
-      glColor3d(C(F(i,j),0),C(F(i,j),1),C(F(i,j),2));
-      if(C.rows() == V.rows())
+      if(C.rows() == 1)
+      {
+        glColor3d(C(0,0),C(0,1),C(0,2));
+      }else if(C.rows() == V.rows())
+      {
+        glColor3d(C(F(i,j),0),C(F(i,j),1),C(F(i,j),2));
+      }else if(C.rows() == F.rows()*3)
+      {
+        glColor3d(C(i*3+j,0),C(i*3+j,1),C(i*3+j,2));
+      }else if(C.rows() == F.rows())
+      {
+        glColor3d(C(i,0),C(i,1),C(i,2));
+      }else
+      {
+        assert(C.size() == 0);
+      }
+      if(N.rows() == V.rows())
+      {
+        glNormal3d(N(F(i,j),0),N(F(i,j),1),N(F(i,j),2));
+      }else if(N.rows() == F.rows()*3)
+      {
+        glNormal3d(N(i*3+j,0),N(i*3+j,1),N(i*3+j,2));
+      }else if(N.rows() == F.rows())
+      {
+        glNormal3d(N(i,0),N(i,1),N(i,2));
+      }
+      glVertex3d(V(F(i,j),0),V(F(i,j),1),V(F(i,j),2));
+    }
+  }
+  glEnd();
+}
+
+IGL_INLINE void igl::draw_mesh(
+  const Eigen::MatrixXd & V,
+  const Eigen::MatrixXi & F,
+  const Eigen::MatrixXd & N,
+  const Eigen::MatrixXd & C,
+  const Eigen::MatrixXd & TC)
+{
+  glBegin(GL_TRIANGLES);
+  // loop over faces
+  for(int i = 0; i<F.rows();i++)
+  {
+    // loop over corners of triangle
+    for(int j = 0;j<3;j++)
+    {
+
+      if(TC.rows() == 1)
+      {
+        glTexCoord2d(TC(F(i,j),0),TC(F(i,j),1));
+      }else if(TC.rows() == V.rows())
+      {
+        glTexCoord2d(TC(F(i,j),0),TC(F(i,j),1));
+      }else if(TC.rows() == F.rows()*2)
+      {
+        glTexCoord2d(TC(i*2+j,0),TC(i*2+j,1));
+      }else if(TC.rows() == F.rows())
+      {
+        glTexCoord2d(TC(i,0),TC(i,1));
+      }else
+      {
+        assert(TC.size() == 0);
+      }
+
+      if(C.rows() == 1)
+      {
+        glColor3d(C(0,0),C(0,1),C(0,2));
+      }else if(C.rows() == V.rows())
       {
         glColor3d(C(F(i,j),0),C(F(i,j),1),C(F(i,j),2));
       }else if(C.rows() == F.rows()*3)
@@ -52,7 +118,11 @@ IGL_INLINE void igl::draw_mesh(
       }else if(C.rows() == F.rows())
       {
         glColor3d(C(i,0),C(i,1),C(i,2));
+      }else
+      {
+        assert(C.size() == 0);
       }
+
       if(N.rows() == V.rows())
       {
         glNormal3d(N(F(i,j),0),N(F(i,j),1),N(F(i,j),2));

+ 15 - 3
include/igl/draw_mesh.h

@@ -14,7 +14,7 @@ namespace igl
   // Inputs:
   //   V  #V by 3 eigen Matrix of mesh vertex 3D positions
   //   F  #F by 3 eigne Matrix of face (triangle) indices
-  //   N  #V by 3 eigen Matrix of mesh vertex 3D normals
+  //   N  #V|#F by 3 eigen Matrix of 3D normals
   IGL_INLINE void draw_mesh(
     const Eigen::MatrixXd & V,
     const Eigen::MatrixXi & F,
@@ -26,13 +26,25 @@ namespace igl
   // Inputs:
   //   V  #V by 3 eigen Matrix of mesh vertex 3D positions
   //   F  #F by 3 eigne Matrix of face (triangle) indices
-  //   N  #V by 3 eigen Matrix of mesh vertex 3D normals
-  //   C  #V by 3 eigen Matrix of mesh vertex RGB colors
+  //   N  #V|#F by 3 eigen Matrix of 3D normals
+  //   C  #V|#F|1 by 3 eigen Matrix of RGB colors
   IGL_INLINE void draw_mesh(
     const Eigen::MatrixXd & V,
     const Eigen::MatrixXi & F,
     const Eigen::MatrixXd & N,
     const Eigen::MatrixXd & C);
+  // Inputs:
+  //   V  #V by 3 eigen Matrix of mesh vertex 3D positions
+  //   F  #F by 3 eigne Matrix of face (triangle) indices
+  //   N  #V|#F by 3 eigen Matrix of 3D normals
+  //   C  #V|#F|1 by 3 eigen Matrix of RGB colors
+  //   TC  #V|#F|1 by 3 eigen Matrix of Texture Coordinates
+  IGL_INLINE void draw_mesh(
+    const Eigen::MatrixXd & V,
+    const Eigen::MatrixXi & F,
+    const Eigen::MatrixXd & N,
+    const Eigen::MatrixXd & C,
+    const Eigen::MatrixXd & TC);
   
   // Draw OpenGL commands needed to display a mesh with normals, per-vertex
   // colors and LBS weights

+ 6 - 6
include/igl/lens_flare.cpp

@@ -129,12 +129,12 @@ void igl::lens_flare_draw(
   Vector3f center = unproject(Vector3f(0.5*vp[2],0.5*vp[3],plight[2]-1e-3));
   //Vector3f center(0,0,1);
   Vector3f axis = light-center;
-  glLineWidth(4.);
-  glColor3f(1,0,0);
-  glBegin(GL_LINES);
-  glVertex3fv(center.data());
-  glVertex3fv(light.data());
-  glEnd();
+  //glLineWidth(4.);
+  //glColor3f(1,0,0);
+  //glBegin(GL_LINES);
+  //glVertex3fv(center.data());
+  //glVertex3fv(light.data());
+  //glEnd();
 
   const Vector3f SX = unproject(psx).normalized();
   const Vector3f SY = unproject(psy).normalized();