From 7f2092b29f80fbdb4fb0b43c225a7b0eca12ecd5 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Tue, 1 Sep 2015 20:20:10 +0900 Subject: [PATCH] Support specular highlight, bump, displacement and alpha texture(Remove non-standard "normal map"). Fixes #53. --- test.cc | 5 ++++- tiny_obj_loader.cc | 38 +++++++++++++++++++++++++++++++++++--- tiny_obj_loader.h | 11 +++++++---- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/test.cc b/test.cc index 1ad6d8c..3f16e3e 100644 --- a/test.cc +++ b/test.cc @@ -45,7 +45,10 @@ static void PrintInfo(const std::vector& shapes, const std::ve printf(" material.map_Ka = %s\n", materials[i].ambient_texname.c_str()); printf(" material.map_Kd = %s\n", materials[i].diffuse_texname.c_str()); printf(" material.map_Ks = %s\n", materials[i].specular_texname.c_str()); - printf(" material.map_Ns = %s\n", materials[i].normal_texname.c_str()); + printf(" material.map_Ns = %s\n", materials[i].specular_highlight_texname.c_str()); + 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()); std::map::const_iterator it(materials[i].unknown_parameter.begin()); std::map::const_iterator itEnd(materials[i].unknown_parameter.end()); for (; it != itEnd; it++) { diff --git a/tiny_obj_loader.cc b/tiny_obj_loader.cc index e9cae10..4d6fc95 100644 --- a/tiny_obj_loader.cc +++ b/tiny_obj_loader.cc @@ -5,6 +5,7 @@ // // +// version 0.9.14: Support specular highlight, bump, displacement and alpha map(#53) // version 0.9.13: Report "Material file not found message" in `err`(#46) // version 0.9.12: Fix groups being ignored if they have 'usemtl' just before 'g' (#44) // version 0.9.11: Invert `Tr` parameter(#43) @@ -344,7 +345,10 @@ void InitMaterial(material_t &material) { material.ambient_texname = ""; material.diffuse_texname = ""; material.specular_texname = ""; - material.normal_texname = ""; + material.specular_highlight_texname = ""; + material.bump_texname = ""; + material.displacement_texname = ""; + material.alpha_texname = ""; for (int i = 0; i < 3; i++) { material.ambient[i] = 0.f; material.diffuse[i] = 0.f; @@ -587,10 +591,38 @@ std::string LoadMtl(std::map &material_map, continue; } - // normal texture + // specular highlight texture if ((0 == strncmp(token, "map_Ns", 6)) && isSpace(token[6])) { token += 7; - material.normal_texname = token; + material.specular_highlight_texname = token; + continue; + } + + // bump texture + if ((0 == strncmp(token, "map_bump", 8)) && isSpace(token[8])) { + token += 9; + material.bump_texname = token; + continue; + } + + // alpha texture + if ((0 == strncmp(token, "map_d", 5)) && isSpace(token[5])) { + token += 6; + material.bump_texname = token; + continue; + } + + // bump texture + if ((0 == strncmp(token, "bump", 4)) && isSpace(token[4])) { + token += 5; + material.bump_texname = token; + continue; + } + + // displacement texture + if ((0 == strncmp(token, "disp", 4)) && isSpace(token[4])) { + token += 5; + material.displacement_texname = token; continue; } diff --git a/tiny_obj_loader.h b/tiny_obj_loader.h index 512f32b..00259e7 100644 --- a/tiny_obj_loader.h +++ b/tiny_obj_loader.h @@ -26,10 +26,13 @@ typedef struct { // illumination model (see http://www.fileformat.info/format/material/) int illum; - std::string ambient_texname; - std::string diffuse_texname; - std::string specular_texname; - std::string normal_texname; + std::string ambient_texname; // map_Ka + std::string diffuse_texname; // map_Kd + std::string specular_texname; // map_Ks + std::string specular_highlight_texname; // map_Ns + std::string bump_texname; // map_bump, bump + std::string displacement_texname; // disp + std::string alpha_texname; // map_d std::map unknown_parameter; } material_t;