Merge branch 'Fix_OBJ' into 'master'
Fix obj See merge request OpenMesh/OpenMesh!310
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
<li>OM Writer/Reader: Added support for (re)storing properties of type vector<T></li>
|
||||
<li>OM Reader: Properties can now be restored from files without the need to create the properties beforehand. Custom types need to be registered for this to work using the OM_REGISTER_PROPERTY_TYPE macro.</li>
|
||||
<li>PLY writer: Added option to choose if we want to write texture coordinates as uv or st (Thanks to Ossi Saukko from Centria Research and Development for the patch)</li>
|
||||
<li>OBJ Reader: Fix material reader, when starting with spaces</li>
|
||||
</ul>
|
||||
|
||||
<b>Tools</b>
|
||||
|
||||
@@ -188,17 +188,18 @@ read_material(std::fstream& _in)
|
||||
|
||||
stream >> keyWrd;
|
||||
|
||||
if( ( isspace(line[0]) && line[0] != '\t' ) || line[0] == '#' )
|
||||
if (keyWrd == "newmtl") // begin new material definition
|
||||
{
|
||||
// If we are in a material definition (Already reading a material)
|
||||
// And a material name has been set
|
||||
// And the current material definition is valid
|
||||
// Then Store the current material in our lookup table
|
||||
if (indef && !key.empty() && mat.is_valid())
|
||||
{
|
||||
materials_[key] = mat;
|
||||
mat.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
else if (keyWrd == "newmtl") // begin new material definition
|
||||
{
|
||||
stream >> key;
|
||||
indef = true;
|
||||
}
|
||||
|
||||
9
src/Unittests/TestFiles/CubeCol.mtl
Normal file
9
src/Unittests/TestFiles/CubeCol.mtl
Normal file
@@ -0,0 +1,9 @@
|
||||
newmtl cube
|
||||
Ns 10.0000
|
||||
Ni 1.000
|
||||
d 1.0000
|
||||
illum 2
|
||||
#Ambient, Diffuse, Specular colors
|
||||
Ka 1.0000 0.7000 0.1000
|
||||
Kd 0.1250 0.2500 0.5000
|
||||
Ks 1.0000 0.6000 0.4000
|
||||
28
src/Unittests/TestFiles/CubeCol.obj
Normal file
28
src/Unittests/TestFiles/CubeCol.obj
Normal file
@@ -0,0 +1,28 @@
|
||||
# cube.obj
|
||||
#
|
||||
o cube
|
||||
mtllib CubeCol.mtl
|
||||
|
||||
v -0.500000 -0.500000 0.500000
|
||||
v 0.500000 -0.500000 0.500000
|
||||
v -0.500000 0.500000 0.500000
|
||||
v 0.500000 0.500000 0.500000
|
||||
v -0.500000 0.500000 -0.500000
|
||||
v 0.500000 0.500000 -0.500000
|
||||
v -0.500000 -0.500000 -0.500000
|
||||
v 0.500000 -0.500000 -0.500000
|
||||
|
||||
g cube
|
||||
usemtl cube
|
||||
f 1 2 3
|
||||
f 3 2 4
|
||||
f 3 4 5
|
||||
f 5 4 6
|
||||
f 5 6 7
|
||||
f 7 6 8
|
||||
f 7 8 1
|
||||
f 1 8 2
|
||||
f 2 8 4
|
||||
f 4 8 6
|
||||
f 7 1 5
|
||||
f 5 1 3
|
||||
@@ -623,7 +623,63 @@ TEST_F(OpenMeshReadWriteOBJ, FaceTexCoordTest) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Load, save and load a simple obj
|
||||
*/
|
||||
TEST_F(OpenMeshReadWriteOBJ, ReadOBJMTL) {
|
||||
|
||||
mesh_.clear();
|
||||
mesh_.request_face_colors();
|
||||
|
||||
OpenMesh::IO::Options options;
|
||||
options += OpenMesh::IO::Options::FaceColor;
|
||||
bool ok = OpenMesh::IO::read_mesh(mesh_, "CubeCol.obj", options);
|
||||
|
||||
EXPECT_TRUE(ok) << "Unable to load CubeCol.obj";
|
||||
|
||||
OpenMesh::FaceHandle fh0 = mesh_.face_handle(0);
|
||||
OpenMesh::FaceHandle fh1 = mesh_.face_handle(1);
|
||||
OpenMesh::FaceHandle fh2 = mesh_.face_handle(2);
|
||||
OpenMesh::FaceHandle fh3 = mesh_.face_handle(3);
|
||||
|
||||
|
||||
EXPECT_TRUE(fh0.is_valid()) << "fh0 should be valid";
|
||||
EXPECT_TRUE(fh1.is_valid()) << "fh1 should be valid";
|
||||
EXPECT_TRUE(fh2.is_valid()) << "fh2 should be valid";
|
||||
EXPECT_TRUE(fh3.is_valid()) << "fh3 should be valid";
|
||||
|
||||
|
||||
|
||||
#ifdef TEST_DOUBLE_TRAITS
|
||||
const float value1 = 32.0/255.0;
|
||||
const float value2 = 64.0/255.0;
|
||||
const float value3 = 128.0/255.0;
|
||||
#else
|
||||
const float value1 = 32;
|
||||
const float value2 = 64;
|
||||
const float value3 = 128;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
EXPECT_FLOAT_EQ(value1, mesh_.color(fh0)[0] ) << "Wrong vertex color at face 0 component 0";
|
||||
EXPECT_FLOAT_EQ(value2 , mesh_.color(fh0)[1] ) << "Wrong vertex color at face 0 component 1";
|
||||
EXPECT_FLOAT_EQ(value3, mesh_.color(fh0)[2] ) << "Wrong vertex color at face 0 component 2";
|
||||
|
||||
EXPECT_FLOAT_EQ(value1, mesh_.color(fh1)[0] ) << "Wrong vertex color at face 1 component 0";
|
||||
EXPECT_FLOAT_EQ(value2, mesh_.color(fh1)[1] ) << "Wrong vertex color at face 1 component 1";
|
||||
EXPECT_FLOAT_EQ(value3, mesh_.color(fh1)[2] ) << "Wrong vertex color at face 1 component 2";
|
||||
|
||||
EXPECT_FLOAT_EQ(value1, mesh_.color(fh2)[0] ) << "Wrong vertex color at face 2 component 0";
|
||||
EXPECT_FLOAT_EQ(value2, mesh_.color(fh2)[1] ) << "Wrong vertex color at face 2 component 1";
|
||||
EXPECT_FLOAT_EQ(value3, mesh_.color(fh2)[2] ) << "Wrong vertex color at face 2 component 2";
|
||||
|
||||
EXPECT_FLOAT_EQ(value1, mesh_.color(fh3)[0] ) << "Wrong vertex color at face 3 component 0";
|
||||
EXPECT_FLOAT_EQ(value2, mesh_.color(fh3)[1] ) << "Wrong vertex color at face 3 component 1";
|
||||
EXPECT_FLOAT_EQ(value3, mesh_.color(fh3)[2] ) << "Wrong vertex color at face 3 component 2";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user