Parse 'Tf' field in MTL.

This commit is contained in:
Syoyo Fujita
2016-08-18 16:13:27 +09:00
parent dea325cdcb
commit 646f1312f1
4 changed files with 32 additions and 1 deletions

View File

@@ -764,7 +764,8 @@ static void LoadMtl(std::map<std::string, int> *material_map,
} }
// transmittance // transmittance
if (token[0] == 'K' && token[1] == 't' && IS_SPACE((token[2]))) { if ((token[0] == 'K' && token[1] == 't' && IS_SPACE((token[2]))) ||
(token[0] == 'T' && token[1] == 'f' && IS_SPACE((token[2])))) {
token += 2; token += 2;
float r, g, b; float r, g, b;
parseFloat3(&r, &g, &b, &token); parseFloat3(&r, &g, &b, &token);

5
models/issue-95.mtl Normal file
View File

@@ -0,0 +1,5 @@
newmtl default
Ka 0 0 0
Kd 0 0 0
Ks 0 0 0
Tf 0.1 0.2 0.3

7
models/issue-95.obj Normal file
View File

@@ -0,0 +1,7 @@
mtllib issue-92.mtl
o Test
v 1.864151 -1.219172 -5.532511
v 0.575869 -0.666304 5.896140
v 0.940448 1.000000 -1.971128
usemtl default
f 1 2 3

View File

@@ -367,6 +367,24 @@ TEST_CASE("trailing_whitespace_in_mtl", "[Issue92]") {
REQUIRE(0 == materials[0].diffuse_texname.compare("tmp.png")); REQUIRE(0 == materials[0].diffuse_texname.compare("tmp.png"));
} }
TEST_CASE("transmittance_filter", "[Issue95]") {
tinyobj::attrib_t attrib;
std::vector<tinyobj::shape_t> shapes;
std::vector<tinyobj::material_t> materials;
std::string err;
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/issue-95.obj", gMtlBasePath);
if (!err.empty()) {
std::cerr << err << std::endl;
}
REQUIRE(true == ret);
REQUIRE(1 == materials.size());
REQUIRE(0.1 == Approx(materials[0].transmittance[0]));
REQUIRE(0.2 == Approx(materials[0].transmittance[1]));
REQUIRE(0.3 == Approx(materials[0].transmittance[2]));
}
#if 0 #if 0
int int
main( main(