Support specular highlight, bump, displacement and alpha texture(Remove non-standard "normal map"). Fixes #53.
This commit is contained in:
5
test.cc
5
test.cc
@@ -45,7 +45,10 @@ static void PrintInfo(const std::vector<tinyobj::shape_t>& 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<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());
|
||||
for (; it != itEnd; it++) {
|
||||
|
||||
@@ -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<std::string, int> &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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<std::string, std::string> unknown_parameter;
|
||||
} material_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user