aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyoyo Fujita <syoyo@lighttransport.com>2017-05-24 17:43:45 +0900
committerSyoyo Fujita <syoyo@lighttransport.com>2017-05-24 17:43:45 +0900
commit44bff466e566454086fa462db98f6f846375f64d (patch)
treeff0f03370d2e7e19e69688fbdcfe92aa5cf13978
parent47989b591faa70d7e1f1a05c68d11d5fdce30b6e (diff)
downloadtinyobjloader-44bff466e566454086fa462db98f6f846375f64d.tar.gz
Initial support of reflection map(`refl`).
-rw-r--r--models/refl.mtl25
-rw-r--r--models/refl.obj32
-rw-r--r--tests/tester.cc21
-rw-r--r--tiny_obj_loader.h12
4 files changed, 90 insertions, 0 deletions
diff --git a/models/refl.mtl b/models/refl.mtl
new file mode 100644
index 0000000..7e04f28
--- /dev/null
+++ b/models/refl.mtl
@@ -0,0 +1,25 @@
+newmtl white
+Ka 0 0 0
+Kd 1 1 1
+Ks 0 0 0
+refl reflection.tga
+
+newmtl red
+Ka 0 0 0
+Kd 1 0 0
+Ks 0 0 0
+
+newmtl green
+Ka 0 0 0
+Kd 0 1 0
+Ks 0 0 0
+
+newmtl blue
+Ka 0 0 0
+Kd 0 0 1
+Ks 0 0 0
+
+newmtl light
+Ka 20 20 20
+Kd 1 1 1
+Ks 0 0 0
diff --git a/models/refl.obj b/models/refl.obj
new file mode 100644
index 0000000..e9715f5
--- /dev/null
+++ b/models/refl.obj
@@ -0,0 +1,32 @@
+# Test for `refl` material parameter
+mtllib refl.mtl
+
+v 0.000000 2.000000 2.000000
+v 0.000000 0.000000 2.000000
+v 2.000000 0.000000 2.000000
+v 2.000000 2.000000 2.000000
+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
+# 8 vertices
+
+g front cube
+usemtl white
+f 1 2 3 4
+g back cube
+# expects white material
+f 8 7 6 5
+g right cube
+usemtl red
+f 4 3 7 8
+g top cube
+usemtl white
+f 5 1 4 8
+g left cube
+usemtl green
+f 5 6 2 1
+g bottom cube
+usemtl white
+f 2 6 7 3
+# 6 elements
diff --git a/tests/tester.cc b/tests/tester.cc
index 80736eb..649451d 100644
--- a/tests/tester.cc
+++ b/tests/tester.cc
@@ -145,6 +145,7 @@ static void PrintInfo(const tinyobj::attrib_t &attrib, const std::vector<tinyobj
printf(" material.map_bump = %s\n", materials[i].bump_texname.c_str());
printf(" material.map_d = %s\n", materials[i].alpha_texname.c_str());
printf(" material.disp = %s\n", materials[i].displacement_texname.c_str());
+ printf(" material.refl = %s\n", materials[i].reflection_texname.c_str());
std::map<std::string, std::string>::const_iterator it(materials[i].unknown_parameter.begin());
std::map<std::string, std::string>::const_iterator itEnd(materials[i].unknown_parameter.end());
@@ -564,6 +565,26 @@ TEST_CASE("tr_and_d", "[Issue43]") {
REQUIRE(0.75 == Approx(materials[1].dissolve));
}
+TEST_CASE("refl", "[refl]") {
+ 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/refl.obj", gMtlBasePath);
+
+ if (!err.empty()) {
+ std::cerr << err << std::endl;
+ }
+
+ PrintInfo(attrib, shapes, materials);
+
+ REQUIRE(true == ret);
+ REQUIRE(5 == materials.size());
+
+ REQUIRE(materials[0].reflection_texname.compare("reflection.tga") == 0);
+}
+
#if 0
int
main(
diff --git a/tiny_obj_loader.h b/tiny_obj_loader.h
index bc69ad9..3c80145 100644
--- a/tiny_obj_loader.h
+++ b/tiny_obj_loader.h
@@ -156,6 +156,7 @@ typedef struct {
std::string bump_texname; // map_bump, bump
std::string displacement_texname; // disp
std::string alpha_texname; // map_d
+ std::string reflection_texname; // refl
texture_option_t ambient_texopt;
texture_option_t diffuse_texopt;
@@ -164,6 +165,7 @@ typedef struct {
texture_option_t bump_texopt;
texture_option_t displacement_texopt;
texture_option_t alpha_texopt;
+ texture_option_t reflection_texopt;
// PBR extension
// http://exocortex.com/blog/extending_wavefront_mtl_to_support_pbr
@@ -859,6 +861,7 @@ static void InitMaterial(material_t *material) {
material->specular_highlight_texname = "";
material->bump_texname = "";
material->displacement_texname = "";
+ material->reflection_texname = "";
material->alpha_texname = "";
for (int i = 0; i < 3; i++) {
material->ambient[i] = 0.f;
@@ -1265,6 +1268,15 @@ void LoadMtl(std::map<std::string, int> *material_map,
continue;
}
+ // reflection map
+ if ((0 == strncmp(token, "refl", 4)) && IS_SPACE(token[4])) {
+ token += 5;
+ ParseTextureNameAndOption(&(material.reflection_texname),
+ &(material.reflection_texopt), token,
+ /* is_bump */ false);
+ continue;
+ }
+
// PBR: roughness texture
if ((0 == strncmp(token, "map_Pr", 6)) && IS_SPACE(token[6])) {
token += 7;