From d192402800906ff4a5e70eb07d8e888483fa0043 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Fri, 19 Aug 2016 20:19:28 +0900 Subject: [PATCH] Support `Tf` in MTL. --- models/issue-95-2.mtl | 5 +++++ models/issue-95-2.obj | 7 +++++++ models/issue-95.mtl | 2 +- models/issue-95.obj | 2 +- tests/tester.cc | 35 +++++++++++++++++++++++++++++++++++ tiny_obj_loader.h | 3 ++- 6 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 models/issue-95-2.mtl create mode 100644 models/issue-95-2.obj diff --git a/models/issue-95-2.mtl b/models/issue-95-2.mtl new file mode 100644 index 0000000..68d484c --- /dev/null +++ b/models/issue-95-2.mtl @@ -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 diff --git a/models/issue-95-2.obj b/models/issue-95-2.obj new file mode 100644 index 0000000..456f854 --- /dev/null +++ b/models/issue-95-2.obj @@ -0,0 +1,7 @@ +mtllib issue-95-2.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 diff --git a/models/issue-95.mtl b/models/issue-95.mtl index 68d484c..1d29fee 100644 --- a/models/issue-95.mtl +++ b/models/issue-95.mtl @@ -2,4 +2,4 @@ newmtl default Ka 0 0 0 Kd 0 0 0 Ks 0 0 0 -Tf 0.1 0.2 0.3 +Kt 0.1 0.2 0.3 diff --git a/models/issue-95.obj b/models/issue-95.obj index f7be3b6..8ee267e 100644 --- a/models/issue-95.obj +++ b/models/issue-95.obj @@ -1,4 +1,4 @@ -mtllib issue-92.mtl +mtllib issue-95.mtl o Test v 1.864151 -1.219172 -5.532511 v 0.575869 -0.666304 5.896140 diff --git a/tests/tester.cc b/tests/tester.cc index 8667888..5573bb6 100644 --- a/tests/tester.cc +++ b/tests/tester.cc @@ -385,6 +385,41 @@ TEST_CASE("transmittance_filter", "[Issue95]") { REQUIRE(0.3 == Approx(materials[0].transmittance[2])); } +TEST_CASE("transmittance_filter_Tf", "[Issue95-Tf]") { + tinyobj::attrib_t attrib; + std::vector shapes; + std::vector materials; + + std::string err; + bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/issue-95-2.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])); +} +TEST_CASE("transmittance_filter_Kt", "[Issue95-Kt]") { + tinyobj::attrib_t attrib; + std::vector shapes; + std::vector 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 int main( diff --git a/tiny_obj_loader.h b/tiny_obj_loader.h index 34375e9..c2b49b3 100644 --- a/tiny_obj_loader.h +++ b/tiny_obj_loader.h @@ -740,7 +740,8 @@ void LoadMtl(std::map *material_map, } // 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; float r, g, b; parseFloat3(&r, &g, &b, &token);