Commit 22bb3078 authored by David Bommes's avatar David Bommes

Added OBJ-Reader Texcoords per Halfedge Support

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@87 fdac6126-5c0c-442c-9429-916003d36597
parent c55b0664
......@@ -77,6 +77,9 @@ public:
typedef std::vector<VertexHandle> VHandles;
virtual FaceHandle add_face(const VHandles& _indices) = 0;
// add texture coordinates per face, _vh references the first texcoord
virtual void add_face_texcoords( FaceHandle _fh, VertexHandle _vh, const std::vector<Vec2f>& _face_texcoords) = 0;
// set vertex normal
virtual void set_normal(VertexHandle _vh, const Vec3f& _normal) = 0;
......@@ -89,6 +92,9 @@ public:
// set vertex texture coordinate
virtual void set_texcoord(VertexHandle _vh, const Vec2f& _texcoord) = 0;
// set vertex texture coordinate
virtual void set_texcoord(HalfedgeHandle _heh, const Vec2f& _texcoord) = 0;
// set face normal
virtual void set_normal(FaceHandle _fh, const Vec3f& _normal) = 0;
......
......@@ -121,6 +121,24 @@ public:
}
virtual void add_face_texcoords( FaceHandle _fh, VertexHandle _vh, const std::vector<Vec2f>& _face_texcoords)
{
// get first halfedge handle
HalfedgeHandle cur_heh = mesh_.halfedge_handle(_fh);
HalfedgeHandle end_heh = mesh_.prev_halfedge_handle(cur_heh);
// find start heh
while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
cur_heh = mesh_.next_halfedge_handle( cur_heh);
for(unsigned int i=0; i<_face_texcoords.size(); ++i)
{
set_texcoord( cur_heh, _face_texcoords[i]);
cur_heh = mesh_.next_halfedge_handle( cur_heh);
}
}
// vertex attributes
virtual void set_normal(VertexHandle _vh, const Vec3f& _normal)
......@@ -148,6 +166,12 @@ public:
mesh_.set_texcoord2D(_vh, vector_cast<TexCoord2D>(_texcoord));
}
virtual void set_texcoord(HalfedgeHandle _heh, const Vec2f& _texcoord)
{
if (mesh_.has_halfedge_texcoords2D())
mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
}
// face attributes
......
......@@ -239,6 +239,8 @@ read(std::fstream& _in, BaseImporter& _bi, Options& _opt)
std::vector<Vec3f> normals;
std::vector<Vec2f> texcoords;
std::vector<Vec2f> face_texcoords;
std::map<std::string,Material> materials;
std::string matname;
......@@ -343,6 +345,7 @@ read(std::fstream& _in, BaseImporter& _bi, Options& _opt)
int value;
vhandles.clear();
face_texcoords.clear();
// read full line after detecting a face
std::string faceLine;
......@@ -419,6 +422,7 @@ read(std::fstream& _in, BaseImporter& _bi, Options& _opt)
assert(!vhandles.empty());
assert((unsigned int)(value-1) < texcoords.size());
_bi.set_texcoord(vhandles.back(), texcoords[value-1]);
face_texcoords.push_back( texcoords[value-1] );
break;
case 2: // normal
......@@ -446,6 +450,9 @@ read(std::fstream& _in, BaseImporter& _bi, Options& _opt)
size_t n_faces = _bi.n_faces();
FaceHandle fh = _bi.add_face(vhandles);
if( !vhandles.empty() )
_bi.add_face_texcoords( fh, vhandles[0], face_texcoords );
if ( !matname.empty() && materials_[matname].has_Kd() )
{
std::vector<FaceHandle> newfaces;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment