Skip to content

Commit 646f131

Browse files
committed
Parse 'Tf' field in MTL.
1 parent dea325c commit 646f131

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

experimental/tinyobj_loader_opt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,8 @@ static void LoadMtl(std::map<std::string, int> *material_map,
764764
}
765765

766766
// transmittance
767-
if (token[0] == 'K' && token[1] == 't' && IS_SPACE((token[2]))) {
767+
if ((token[0] == 'K' && token[1] == 't' && IS_SPACE((token[2]))) ||
768+
(token[0] == 'T' && token[1] == 'f' && IS_SPACE((token[2])))) {
768769
token += 2;
769770
float r, g, b;
770771
parseFloat3(&r, &g, &b, &token);

models/issue-95.mtl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
newmtl default
2+
Ka 0 0 0
3+
Kd 0 0 0
4+
Ks 0 0 0
5+
Tf 0.1 0.2 0.3

models/issue-95.obj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mtllib issue-92.mtl
2+
o Test
3+
v 1.864151 -1.219172 -5.532511
4+
v 0.575869 -0.666304 5.896140
5+
v 0.940448 1.000000 -1.971128
6+
usemtl default
7+
f 1 2 3

tests/tester.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,24 @@ TEST_CASE("trailing_whitespace_in_mtl", "[Issue92]") {
367367
REQUIRE(0 == materials[0].diffuse_texname.compare("tmp.png"));
368368
}
369369

370+
TEST_CASE("transmittance_filter", "[Issue95]") {
371+
tinyobj::attrib_t attrib;
372+
std::vector<tinyobj::shape_t> shapes;
373+
std::vector<tinyobj::material_t> materials;
374+
375+
std::string err;
376+
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/issue-95.obj", gMtlBasePath);
377+
378+
if (!err.empty()) {
379+
std::cerr << err << std::endl;
380+
}
381+
REQUIRE(true == ret);
382+
REQUIRE(1 == materials.size());
383+
REQUIRE(0.1 == Approx(materials[0].transmittance[0]));
384+
REQUIRE(0.2 == Approx(materials[0].transmittance[1]));
385+
REQUIRE(0.3 == Approx(materials[0].transmittance[2]));
386+
}
387+
370388
#if 0
371389
int
372390
main(

0 commit comments

Comments
 (0)