diff --git a/src/Unittests/TestFiles/square_material_texture.mtl b/src/Unittests/TestFiles/square_material_texture.mtl new file mode 100644 index 00000000..7ec0e19e --- /dev/null +++ b/src/Unittests/TestFiles/square_material_texture.mtl @@ -0,0 +1,8 @@ +newmtl Texture +Ka 0.500 0.500 0.500 +Kd 0.500 0.500 0.500 +Ks 0.500 0.500 0.500 +Tr 1.000000 +illum 1 +Ns 0.000000 +map_Kd square_material_texture.jpg diff --git a/src/Unittests/TestFiles/square_material_texture.obj b/src/Unittests/TestFiles/square_material_texture.obj new file mode 100644 index 00000000..12f53b03 --- /dev/null +++ b/src/Unittests/TestFiles/square_material_texture.obj @@ -0,0 +1,13 @@ +mtllib square_material_texture.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 Texture +f 1/1 2/2 3/3 4/4 diff --git a/src/Unittests/unittests_read_write_OBJ.cc b/src/Unittests/unittests_read_write_OBJ.cc index 647c2619..88a370b7 100644 --- a/src/Unittests/unittests_read_write_OBJ.cc +++ b/src/Unittests/unittests_read_write_OBJ.cc @@ -214,6 +214,39 @@ TEST_F(OpenMeshReadWriteOBJ, LoadObjWithMaterial) { mesh_.release_face_colors(); } +TEST_F(OpenMeshReadWriteOBJ, LoadObjWithTexture) { + + mesh_.clear(); + + mesh_.request_face_colors(); + mesh_.request_face_texture_index(); + + OpenMesh::IO::Options options; + options += OpenMesh::IO::Options::FaceTexCoord; + + std::string file_name = "square_material_texture.obj"; + + bool ok = OpenMesh::IO::read_mesh(mesh_, file_name, options); + + EXPECT_TRUE(ok) << file_name; + + //check texture mapping for the mesh + OpenMesh::MPropHandleT< std::map< int, std::string > > property; + mesh_.get_property_handle(property, "TextureMapping"); + EXPECT_EQ(mesh_.property(property).size(), 1) << "More than one texture defined"; + std::map< int, std::string >::iterator tex = mesh_.property(property).find(1); + EXPECT_TRUE(tex != mesh_.property(property).end()) << "Could not find texture with id 1"; + EXPECT_TRUE((mesh_.property(property)[1] == std::string("square_material_texture.jpg"))) << "Wrong texture name"; + + //check texture mapping per face + OpenMesh::FaceHandle fh = mesh_.face_handle(mesh_.halfedge_handle(0)); + EXPECT_TRUE(fh.is_valid()) << "fh should be valid"; + EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(),fh),1) << "Face texture index is not set correctly"; + + mesh_.release_face_colors(); + mesh_.release_face_texture_index(); +} + /* * Just load a obj file of a cube with vertex colors defined directly after the vertex definitions */