瀏覽代碼

embree fix
fixed bug in viewer for texture with odd size


Former-commit-id: b5bfb448092feca867fa82c79f34801001d03573

Daniele Panozzo 10 年之前
父節點
當前提交
adccda6807

+ 5 - 2
include/igl/embree/unproject_onto_mesh.cpp

@@ -52,8 +52,11 @@ IGL_INLINE bool igl::unproject_onto_mesh(
   Eigen::Vector3f bc;
   bool hit = unproject_onto_mesh(pos,F,model,proj,viewport,ei,fid,bc);
   int i;
-  bc.maxCoeff(&i);
-  vid = F(fid,i);
+  if (hit)
+  {
+    bc.maxCoeff(&i);
+    vid = F(fid,i);
+  }
   return hit;
 }
 

+ 1 - 1
include/igl/png/texture_from_png.cpp

@@ -62,7 +62,7 @@ IGL_INLINE bool igl::texture_from_png(
       R(i,j) = yimg.at(yimg.width()-1-i,yimg.height()-1-j).r;
       G(i,j) = yimg.at(yimg.width()-1-i,yimg.height()-1-j).g;
       B(i,j) = yimg.at(yimg.width()-1-i,yimg.height()-1-j).b;
-      A(i,j) = yimg.at(yimg.width()-1-i,yimg.height()-1-j).a;
+      //1A(i,j) = yimg.at(yimg.width()-1-i,yimg.height()-1-j).a;
     }
   }
 

+ 1 - 0
include/igl/viewer/OpenGL_state.cpp

@@ -293,6 +293,7 @@ IGL_INLINE void igl::OpenGL_state::bind_mesh()
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_u, tex_v, 0, GL_RGB, GL_UNSIGNED_BYTE, tex.data());
   }
   glUniform1i(shader_mesh.uniform("tex"), 0);

+ 1 - 1
include/igl/viewer/ViewerData.cpp

@@ -199,7 +199,7 @@ IGL_INLINE void igl::ViewerData::set_uv(const Eigen::MatrixXd& UV)
 IGL_INLINE void igl::ViewerData::set_uv(const Eigen::MatrixXd& UV_V, const Eigen::MatrixXi& UV_F)
 {
   set_face_based(true);
-  V_uv = UV_V;
+  V_uv = UV_V.block(0,0,UV_V.rows(),2);
   F_uv = UV_F;
   dirty |= DIRTY_UV;
 }