Commit 83722b8e authored by Isaak Lim's avatar Isaak Lim

- fixed a bug with OBJReader that prevented the material color to be loaded correctly

- added a corresponding unittest

Thanks for the patch by Karthik Nathan

closes #1473

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@823 fdac6126-5c0c-442c-9429-916003d36597
parent 3d72b7db
......@@ -574,9 +574,10 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
}
fh = _bi.add_face(faceVertices);
// note that add_face can possibly triangulate the faces, which is why we have to
// store the current number of faces first
size_t n_faces = _bi.n_faces();
fh = _bi.add_face(faceVertices);
if (!vhandles.empty() && fh.is_valid() )
_bi.add_face_texcoords(fh, vhandles[0], face_texcoords);
......
newmtl Colored
Ka 0.500 0.500 0.500
Kd 0.500 0.500 0.500
Ks 0.500 0.500 0.500
mtllib square_material.mtl
v 0.000000 2.000000 0.000000
v 0.000000 0.000000 0.000000
v 2.000000 0.000000 0.000000
v 2.000000 2.000000 0.000000
vt 0.000000 1.000000 0.000000
vt 0.000000 0.000000 0.000000
vt 1.000000 0.000000 0.000000
vt 1.000000 1.000000 0.000000
usemtl Colored
f 1/1 2/2 3/3 4/4
......@@ -185,6 +185,34 @@ TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJCheckTexCoords) {
mesh_.release_halfedge_texcoords2D();
}
/*
* Just load a obj file of a square with a material
*/
TEST_F(OpenMeshReadWriteOBJ, LoadObjWithMaterial) {
mesh_.clear();
mesh_.request_face_colors();
OpenMesh::IO::Options options;
options += OpenMesh::IO::Options::FaceColor;
std::string file_name = "square_material.obj";
bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
EXPECT_TRUE(ok) << file_name;
OpenMesh::FaceHandle fh = mesh_.face_handle(mesh_.halfedge_handle(0));
EXPECT_TRUE(fh.is_valid()) << "fh should be valid";
EXPECT_EQ(128, mesh_.color(fh)[0] ) << "Wrong vertex color at vertex 0 component 0";
EXPECT_EQ(128, mesh_.color(fh)[1] ) << "Wrong vertex color at vertex 0 component 1";
EXPECT_EQ(128, mesh_.color(fh)[2] ) << "Wrong vertex color at vertex 0 component 2";
mesh_.release_face_colors();
}
/*
* Just load a obj file of a cube with vertex colors defined directly after the vertex definitions
......
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