diff options
author | Aras Pranckevicius <aras@nesnausk.org> | 2022-09-12 21:04:37 +0300 |
---|---|---|
committer | Aras Pranckevicius <aras@nesnausk.org> | 2022-09-12 21:05:57 +0300 |
commit | 8af59cdb16298e71dd75e2221d57bd0cb48cab26 (patch) | |
tree | 6a5529bc05904b4dbc25812a602af8a4a4c0da6e /source/blender | |
parent | 8f6a07bc750ffd09602c4be848968441adbc4a93 (diff) |
Cleanup: obj: rename MTLMaterial & MTLTexMapType members
The members were named after .mtl file syntax ("d") instead of their
meaning ("alpha"). In preparation for extending OBJ code for more
PBR parameters support, rename them for clarity. No functionality
changes, just a pure rename.
Diffstat (limited to 'source/blender')
6 files changed, 165 insertions, 152 deletions
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc index 4d934960010..27526734624 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc @@ -558,24 +558,26 @@ void MTLWriter::write_bsdf_properties(const MTLMaterial &mtl) /* For various material properties, we only capture information * coming from the texture, or the default value of the socket. * When the texture is present, do not emit the default value. */ - if (!mtl.tex_map_of_type(MTLTexMapType::Ns).is_valid()) { - fmt_handler_.write_mtl_float("Ns", mtl.Ns); + if (!mtl.tex_map_of_type(MTLTexMapType::SpecularExponent).is_valid()) { + fmt_handler_.write_mtl_float("Ns", mtl.spec_exponent); } - fmt_handler_.write_mtl_float3("Ka", mtl.Ka.x, mtl.Ka.y, mtl.Ka.z); - if (!mtl.tex_map_of_type(MTLTexMapType::Kd).is_valid()) { - fmt_handler_.write_mtl_float3("Kd", mtl.Kd.x, mtl.Kd.y, mtl.Kd.z); + fmt_handler_.write_mtl_float3( + "Ka", mtl.ambient_color.x, mtl.ambient_color.y, mtl.ambient_color.z); + if (!mtl.tex_map_of_type(MTLTexMapType::Color).is_valid()) { + fmt_handler_.write_mtl_float3("Kd", mtl.color.x, mtl.color.y, mtl.color.z); } - if (!mtl.tex_map_of_type(MTLTexMapType::Ks).is_valid()) { - fmt_handler_.write_mtl_float3("Ks", mtl.Ks.x, mtl.Ks.y, mtl.Ks.z); + if (!mtl.tex_map_of_type(MTLTexMapType::Specular).is_valid()) { + fmt_handler_.write_mtl_float3("Ks", mtl.spec_color.x, mtl.spec_color.y, mtl.spec_color.z); } - if (!mtl.tex_map_of_type(MTLTexMapType::Ke).is_valid()) { - fmt_handler_.write_mtl_float3("Ke", mtl.Ke.x, mtl.Ke.y, mtl.Ke.z); + if (!mtl.tex_map_of_type(MTLTexMapType::Emission).is_valid()) { + fmt_handler_.write_mtl_float3( + "Ke", mtl.emission_color.x, mtl.emission_color.y, mtl.emission_color.z); } - fmt_handler_.write_mtl_float("Ni", mtl.Ni); - if (!mtl.tex_map_of_type(MTLTexMapType::d).is_valid()) { - fmt_handler_.write_mtl_float("d", mtl.d); + fmt_handler_.write_mtl_float("Ni", mtl.ior); + if (!mtl.tex_map_of_type(MTLTexMapType::Alpha).is_valid()) { + fmt_handler_.write_mtl_float("d", mtl.alpha); } - fmt_handler_.write_mtl_illum(mtl.illum); + fmt_handler_.write_mtl_illum(mtl.illum_mode); } void MTLWriter::write_texture_map(const MTLMaterial &mtl_material, @@ -594,8 +596,8 @@ void MTLWriter::write_texture_map(const MTLMaterial &mtl_material, if (texture_map.scale != float3{1.0f, 1.0f, 1.0f}) { options.append(" -s ").append(float3_to_string(texture_map.scale)); } - if (texture_key == MTLTexMapType::bump && mtl_material.map_Bump_strength > 0.0001f) { - options.append(" -bm ").append(std::to_string(mtl_material.map_Bump_strength)); + if (texture_key == MTLTexMapType::Normal && mtl_material.normal_strength > 0.0001f) { + options.append(" -bm ").append(std::to_string(mtl_material.normal_strength)); } std::string path = path_reference( diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc index 6a02695c304..77cad18a040 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc @@ -212,11 +212,11 @@ static void store_bsdf_properties(const bNode *bsdf_node, copy_property_from_node(SOCK_FLOAT, bsdf_node, "IOR", {&refraction_index, 1}); } - float dissolved = material->a; + float alpha = material->a; if (bsdf_node) { - copy_property_from_node(SOCK_FLOAT, bsdf_node, "Alpha", {&dissolved, 1}); + copy_property_from_node(SOCK_FLOAT, bsdf_node, "Alpha", {&alpha, 1}); } - const bool transparent = dissolved != 1.0f; + const bool transparent = alpha != 1.0f; float3 diffuse_col = {material->r, material->g, material->b}; if (bsdf_node) { @@ -253,19 +253,19 @@ static void store_bsdf_properties(const bNode *bsdf_node, /* Transparency: Glass on, Reflection: Ray trace off */ illum = 9; } - r_mtl_mat.Ns = spec_exponent; + r_mtl_mat.spec_exponent = spec_exponent; if (metallic != 0.0f) { - r_mtl_mat.Ka = {metallic, metallic, metallic}; + r_mtl_mat.ambient_color = {metallic, metallic, metallic}; } else { - r_mtl_mat.Ka = {1.0f, 1.0f, 1.0f}; + r_mtl_mat.ambient_color = {1.0f, 1.0f, 1.0f}; } - r_mtl_mat.Kd = diffuse_col; - r_mtl_mat.Ks = {specular, specular, specular}; - r_mtl_mat.Ke = emission_col; - r_mtl_mat.Ni = refraction_index; - r_mtl_mat.d = dissolved; - r_mtl_mat.illum = illum; + r_mtl_mat.color = diffuse_col; + r_mtl_mat.spec_color = {specular, specular, specular}; + r_mtl_mat.emission_color = emission_col; + r_mtl_mat.ior = refraction_index; + r_mtl_mat.alpha = alpha; + r_mtl_mat.illum_mode = illum; } /** @@ -291,7 +291,7 @@ static void store_image_textures(const bNode *bsdf_node, Vector<const bNodeSocket *> linked_sockets; const bNode *normal_map_node{nullptr}; - if (key == (int)MTLTexMapType::bump) { + if (key == (int)MTLTexMapType::Normal) { /* Find sockets linked to destination "Normal" socket in P-BSDF node. */ linked_sockets_to_dest_id(bsdf_node, *node_tree, "Normal", linked_sockets); /* Among the linked sockets, find Normal Map shader node. */ @@ -302,7 +302,7 @@ static void store_image_textures(const bNode *bsdf_node, } else { /* Skip emission map if emission strength is zero. */ - if (key == (int)MTLTexMapType::Ke) { + if (key == (int)MTLTexMapType::Emission) { float emission_strength = 0.0f; copy_property_from_node( SOCK_FLOAT, bsdf_node, "Emission Strength", {&emission_strength, 1}); @@ -331,7 +331,7 @@ static void store_image_textures(const bNode *bsdf_node, if (normal_map_node) { copy_property_from_node( - SOCK_FLOAT, normal_map_node, "Strength", {&r_mtl_mat.map_Bump_strength, 1}); + SOCK_FLOAT, normal_map_node, "Strength", {&r_mtl_mat.normal_strength, 1}); } /* Texture transform options. Only translation (origin offset, "-o") and scale * ("-o") are supported. */ diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh index d8eafff107b..0b94e4e43a3 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh @@ -13,7 +13,16 @@ struct Material; namespace blender::io::obj { -enum class MTLTexMapType { Kd = 0, Ks, Ns, d, refl, Ke, bump, Count }; +enum class MTLTexMapType { + Color = 0, + Specular, + SpecularExponent, + Alpha, + Reflection, + Emission, + Normal, + Count +}; extern const char *tex_map_type_to_socket_id[]; struct MTLTexMap { @@ -47,17 +56,17 @@ struct MTLMaterial { std::string name; /* Always check for negative values while importing or exporting. Use defaults if * any value is negative. */ - float Ns{-1.0f}; - float3 Ka{-1.0f}; - float3 Kd{-1.0f}; - float3 Ks{-1.0f}; - float3 Ke{-1.0f}; - float Ni{-1.0f}; - float d{-1.0f}; - int illum{-1}; + float spec_exponent{-1.0f}; /* Ns */ + float3 ambient_color{-1.0f}; /* Ka */ + float3 color{-1.0f}; /* Kd */ + float3 spec_color{-1.0f}; /* Ks */ + float3 emission_color{-1.0f}; /* Ke */ + float ior{-1.0f}; /* Ni */ + float alpha{-1.0f}; /* d */ + int illum_mode{-1}; MTLTexMap texture_maps[(int)MTLTexMapType::Count]; - /** Only used for Normal Map node: "map_Bump". */ - float map_Bump_strength{-1.0f}; + /* Only used for Normal Map node: "map_Bump". */ + float normal_strength{-1.0f}; }; MTLMaterial mtlmaterial_for_material(const Material *material); diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 2ad8a09bd90..cc98dbdbf92 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -596,26 +596,26 @@ void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries, static MTLTexMapType mtl_line_start_to_texture_type(const char *&p, const char *end) { if (parse_keyword(p, end, "map_Kd")) { - return MTLTexMapType::Kd; + return MTLTexMapType::Color; } if (parse_keyword(p, end, "map_Ks")) { - return MTLTexMapType::Ks; + return MTLTexMapType::Specular; } if (parse_keyword(p, end, "map_Ns")) { - return MTLTexMapType::Ns; + return MTLTexMapType::SpecularExponent; } if (parse_keyword(p, end, "map_d")) { - return MTLTexMapType::d; + return MTLTexMapType::Alpha; } if (parse_keyword(p, end, "refl") || parse_keyword(p, end, "map_refl")) { - return MTLTexMapType::refl; + return MTLTexMapType::Reflection; } if (parse_keyword(p, end, "map_Ke")) { - return MTLTexMapType::Ke; + return MTLTexMapType::Emission; } if (parse_keyword(p, end, "bump") || parse_keyword(p, end, "map_Bump") || parse_keyword(p, end, "map_bump")) { - return MTLTexMapType::bump; + return MTLTexMapType::Normal; } return MTLTexMapType::Count; } @@ -647,7 +647,7 @@ static bool parse_texture_option(const char *&p, return true; } if (parse_keyword(p, end, "-bm")) { - p = parse_float(p, end, 1.0f, material->map_Bump_strength, true, true); + p = parse_float(p, end, 1.0f, material->normal_strength, true, true); return true; } if (parse_keyword(p, end, "-type")) { @@ -780,31 +780,31 @@ void MTLParser::parse_and_store(Map<string, std::unique_ptr<MTLMaterial>> &r_mat } else if (material != nullptr) { if (parse_keyword(p, end, "Ns")) { - parse_float(p, end, 324.0f, material->Ns); + parse_float(p, end, 324.0f, material->spec_exponent); } else if (parse_keyword(p, end, "Ka")) { - parse_floats(p, end, 0.0f, material->Ka, 3); + parse_floats(p, end, 0.0f, material->ambient_color, 3); } else if (parse_keyword(p, end, "Kd")) { - parse_floats(p, end, 0.8f, material->Kd, 3); + parse_floats(p, end, 0.8f, material->color, 3); } else if (parse_keyword(p, end, "Ks")) { - parse_floats(p, end, 0.5f, material->Ks, 3); + parse_floats(p, end, 0.5f, material->spec_color, 3); } else if (parse_keyword(p, end, "Ke")) { - parse_floats(p, end, 0.0f, material->Ke, 3); + parse_floats(p, end, 0.0f, material->emission_color, 3); } else if (parse_keyword(p, end, "Ni")) { - parse_float(p, end, 1.45f, material->Ni); + parse_float(p, end, 1.45f, material->ior); } else if (parse_keyword(p, end, "d")) { - parse_float(p, end, 1.0f, material->d); + parse_float(p, end, 1.0f, material->alpha); } else if (parse_keyword(p, end, "illum")) { /* Some files incorrectly use a float (T60135). */ float val; parse_float(p, end, 1.0f, val); - material->illum = val; + material->illum_mode = val; } else { parse_texture_map(p, end, material, mtl_dir_path_); diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc index 0922a71979e..76568b2ddb4 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc @@ -178,7 +178,7 @@ static void link_sockets(bNodeTree *ntree, static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial &mtl_mat) { - const int illum = mtl_mat.illum; + const int illum = mtl_mat.illum_mode; bool do_highlight = false; bool do_tranparency = false; bool do_reflection = false; @@ -244,21 +244,23 @@ static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial /* Approximations for trying to map obj/mtl material model into * Principled BSDF: */ /* Specular: average of Ks components. */ - float specular = (mtl_mat.Ks[0] + mtl_mat.Ks[1] + mtl_mat.Ks[2]) / 3; + float specular = (mtl_mat.spec_color[0] + mtl_mat.spec_color[1] + mtl_mat.spec_color[2]) / 3; if (specular < 0.0f) { specular = do_highlight ? 1.0f : 0.0f; } /* Roughness: map 0..1000 range to 1..0 and apply non-linearity. */ float roughness; - if (mtl_mat.Ns < 0.0f) { + if (mtl_mat.spec_exponent < 0.0f) { roughness = do_highlight ? 0.0f : 1.0f; } else { - float clamped_ns = std::max(0.0f, std::min(1000.0f, mtl_mat.Ns)); + float clamped_ns = std::max(0.0f, std::min(1000.0f, mtl_mat.spec_exponent)); roughness = 1.0f - sqrt(clamped_ns / 1000.0f); } /* Metallic: average of Ka components. */ - float metallic = (mtl_mat.Ka[0] + mtl_mat.Ka[1] + mtl_mat.Ka[2]) / 3; + float metallic = (mtl_mat.ambient_color[0] + mtl_mat.ambient_color[1] + + mtl_mat.ambient_color[2]) / + 3; if (do_reflection) { if (metallic < 0.0f) { metallic = 1.0f; @@ -268,7 +270,7 @@ static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial metallic = 0.0f; } - float ior = mtl_mat.Ni; + float ior = mtl_mat.ior; if (ior < 0) { if (do_tranparency) { ior = 1.0f; @@ -277,12 +279,12 @@ static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial ior = 1.5f; } } - float alpha = mtl_mat.d; + float alpha = mtl_mat.alpha; if (do_tranparency && alpha < 0) { alpha = 1.0f; } - float3 base_color = {mtl_mat.Kd[0], mtl_mat.Kd[1], mtl_mat.Kd[2]}; + float3 base_color = mtl_mat.color; if (base_color.x >= 0 && base_color.y >= 0 && base_color.z >= 0) { set_property_of_socket(SOCK_RGBA, "Base Color", {base_color, 3}, bsdf); /* Viewport shading uses legacy r,g,b base color. */ @@ -291,11 +293,11 @@ static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial mat->b = base_color.z; } - float3 emission_color = {mtl_mat.Ke[0], mtl_mat.Ke[1], mtl_mat.Ke[2]}; + float3 emission_color = mtl_mat.emission_color; if (emission_color.x >= 0 && emission_color.y >= 0 && emission_color.z >= 0) { set_property_of_socket(SOCK_RGBA, "Emission", {emission_color, 3}, bsdf); } - if (mtl_mat.tex_map_of_type(MTLTexMapType::Ke).is_valid()) { + if (mtl_mat.tex_map_of_type(MTLTexMapType::Emission).is_valid()) { set_property_of_socket(SOCK_FLOAT, "Emission Strength", {1.0f}, bsdf); } set_property_of_socket(SOCK_FLOAT, "Specular", {specular}, bsdf); @@ -341,9 +343,9 @@ static void add_image_textures(Main *bmain, /* Add normal map node if needed. */ bNode *normal_map = nullptr; - if (key == (int)MTLTexMapType::bump) { + if (key == (int)MTLTexMapType::Normal) { normal_map = add_node(ntree, SH_NODE_NORMAL_MAP, node_locx_normalmap, node_locy); - const float bump = std::max(0.0f, mtl_mat.map_Bump_strength); + const float bump = std::max(0.0f, mtl_mat.normal_strength); set_property_of_socket(SOCK_FLOAT, "Strength", {bump}, normal_map); } @@ -362,7 +364,7 @@ static void add_image_textures(Main *bmain, link_sockets(ntree, image_node, "Color", normal_map, "Color"); link_sockets(ntree, normal_map, "Normal", bsdf, "Normal"); } - else if (key == (int)MTLTexMapType::d) { + else if (key == (int)MTLTexMapType::Alpha) { link_sockets(ntree, image_node, "Alpha", bsdf, tex_map_type_to_socket_id[key]); mat->blend_method = MA_BM_BLEND; } diff --git a/source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc b/source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc index 5691aa5bea1..ff9485e99b5 100644 --- a/source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc @@ -50,15 +50,15 @@ class obj_mtl_parser_test : public testing::Test { } const MTLMaterial &got = *materials.lookup(exp.name); const float tol = 0.0001f; - EXPECT_V3_NEAR(exp.Ka, got.Ka, tol); - EXPECT_V3_NEAR(exp.Kd, got.Kd, tol); - EXPECT_V3_NEAR(exp.Ks, got.Ks, tol); - EXPECT_V3_NEAR(exp.Ke, got.Ke, tol); - EXPECT_NEAR(exp.Ns, got.Ns, tol); - EXPECT_NEAR(exp.Ni, got.Ni, tol); - EXPECT_NEAR(exp.d, got.d, tol); - EXPECT_NEAR(exp.map_Bump_strength, got.map_Bump_strength, tol); - EXPECT_EQ(exp.illum, got.illum); + EXPECT_V3_NEAR(exp.ambient_color, got.ambient_color, tol); + EXPECT_V3_NEAR(exp.color, got.color, tol); + EXPECT_V3_NEAR(exp.spec_color, got.spec_color, tol); + EXPECT_V3_NEAR(exp.emission_color, got.emission_color, tol); + EXPECT_NEAR(exp.spec_exponent, got.spec_exponent, tol); + EXPECT_NEAR(exp.ior, got.ior, tol); + EXPECT_NEAR(exp.alpha, got.alpha, tol); + EXPECT_NEAR(exp.normal_strength, got.normal_strength, tol); + EXPECT_EQ(exp.illum_mode, got.illum_mode); for (int key = 0; key < (int)MTLTexMapType::Count; key++) { const MTLTexMap &exp_tex = exp.texture_maps[key]; const MTLTexMap &got_tex = got.texture_maps[key]; @@ -102,20 +102,20 @@ TEST_F(obj_mtl_parser_test, string_newlines_whitespace) "map_Ks sometex_s_spaces_after_name.png \t \r\n"; MTLMaterial mat[6]; mat[0].name = "simple"; - mat[0].Ka = {0.1f, 0.2f, 0.3f}; - mat[0].illum = 4; + mat[0].ambient_color = {0.1f, 0.2f, 0.3f}; + mat[0].illum_mode = 4; mat[1].name = "tab_indentation"; - mat[1].Kd = {0.2f, 0.3f, 0.4f}; + mat[1].color = {0.2f, 0.3f, 0.4f}; mat[2].name = "space_after_name"; - mat[2].Ks = {0.4f, 0.5f, 0.6f}; + mat[2].spec_color = {0.4f, 0.5f, 0.6f}; mat[3].name = "space_before_name"; mat[4].name = "indented_values"; - mat[4].Ka = {0.5f, 0.6f, 0.7f}; - mat[4].Kd = {0.6f, 0.7f, 0.8f}; + mat[4].ambient_color = {0.5f, 0.6f, 0.7f}; + mat[4].color = {0.6f, 0.7f, 0.8f}; mat[5].name = "crlf_ending"; - mat[5].Ns = 5.0f; - mat[5].tex_map_of_type(MTLTexMapType::Kd).image_path = "sometex_d.png"; - mat[5].tex_map_of_type(MTLTexMapType::Ks).image_path = "sometex_s_spaces_after_name.png"; + mat[5].spec_exponent = 5.0f; + mat[5].tex_map_of_type(MTLTexMapType::Color).image_path = "sometex_d.png"; + mat[5].tex_map_of_type(MTLTexMapType::Specular).image_path = "sometex_s_spaces_after_name.png"; check_string(text, mat, ARRAY_SIZE(mat)); } @@ -123,8 +123,8 @@ TEST_F(obj_mtl_parser_test, cube) { MTLMaterial mat; mat.name = "red"; - mat.Ka = {0.2f, 0.2f, 0.2f}; - mat.Kd = {1, 0, 0}; + mat.ambient_color = {0.2f, 0.2f, 0.2f}; + mat.color = {1, 0, 0}; check("cube.mtl", &mat, 1); } @@ -132,28 +132,28 @@ TEST_F(obj_mtl_parser_test, all_objects) { MTLMaterial mat[7]; for (auto &m : mat) { - m.Ka = {1, 1, 1}; - m.Ks = {0.5f, 0.5f, 0.5f}; - m.Ke = {0, 0, 0}; - m.Ns = 250; - m.Ni = 1; - m.d = 1; - m.illum = 2; + m.ambient_color = {1, 1, 1}; + m.spec_color = {0.5f, 0.5f, 0.5f}; + m.emission_color = {0, 0, 0}; + m.spec_exponent = 250; + m.ior = 1; + m.alpha = 1; + m.illum_mode = 2; } mat[0].name = "Blue"; - mat[0].Kd = {0, 0, 1}; + mat[0].color = {0, 0, 1}; mat[1].name = "BlueDark"; - mat[1].Kd = {0, 0, 0.5f}; + mat[1].color = {0, 0, 0.5f}; mat[2].name = "Green"; - mat[2].Kd = {0, 1, 0}; + mat[2].color = {0, 1, 0}; mat[3].name = "GreenDark"; - mat[3].Kd = {0, 0.5f, 0}; + mat[3].color = {0, 0.5f, 0}; mat[4].name = "Material"; - mat[4].Kd = {0.8f, 0.8f, 0.8f}; + mat[4].color = {0.8f, 0.8f, 0.8f}; mat[5].name = "Red"; - mat[5].Kd = {1, 0, 0}; + mat[5].color = {1, 0, 0}; mat[6].name = "RedDark"; - mat[6].Kd = {0.5f, 0, 0}; + mat[6].color = {0.5f, 0, 0}; check("all_objects.mtl", mat, ARRAY_SIZE(mat)); } @@ -161,92 +161,92 @@ TEST_F(obj_mtl_parser_test, materials) { MTLMaterial mat[6]; mat[0].name = "no_textures_red"; - mat[0].Ka = {0.3f, 0.3f, 0.3f}; - mat[0].Kd = {0.8f, 0.3f, 0.1f}; - mat[0].Ns = 5.624998f; + mat[0].ambient_color = {0.3f, 0.3f, 0.3f}; + mat[0].color = {0.8f, 0.3f, 0.1f}; + mat[0].spec_exponent = 5.624998f; mat[1].name = "four_maps"; - mat[1].Ka = {1, 1, 1}; - mat[1].Kd = {0.8f, 0.8f, 0.8f}; - mat[1].Ks = {0.5f, 0.5f, 0.5f}; - mat[1].Ke = {0, 0, 0}; - mat[1].Ns = 1000; - mat[1].Ni = 1.45f; - mat[1].d = 1; - mat[1].illum = 2; - mat[1].map_Bump_strength = 1; + mat[1].ambient_color = {1, 1, 1}; + mat[1].color = {0.8f, 0.8f, 0.8f}; + mat[1].spec_color = {0.5f, 0.5f, 0.5f}; + mat[1].emission_color = {0, 0, 0}; + mat[1].spec_exponent = 1000; + mat[1].ior = 1.45f; + mat[1].alpha = 1; + mat[1].illum_mode = 2; + mat[1].normal_strength = 1; { - MTLTexMap &kd = mat[1].tex_map_of_type(MTLTexMapType::Kd); + MTLTexMap &kd = mat[1].tex_map_of_type(MTLTexMapType::Color); kd.image_path = "texture.png"; - MTLTexMap &ns = mat[1].tex_map_of_type(MTLTexMapType::Ns); + MTLTexMap &ns = mat[1].tex_map_of_type(MTLTexMapType::SpecularExponent); ns.image_path = "sometexture_Roughness.png"; - MTLTexMap &refl = mat[1].tex_map_of_type(MTLTexMapType::refl); + MTLTexMap &refl = mat[1].tex_map_of_type(MTLTexMapType::Reflection); refl.image_path = "sometexture_Metallic.png"; - MTLTexMap &bump = mat[1].tex_map_of_type(MTLTexMapType::bump); + MTLTexMap &bump = mat[1].tex_map_of_type(MTLTexMapType::Normal); bump.image_path = "sometexture_Normal.png"; } mat[2].name = "Clay"; - mat[2].Ka = {1, 1, 1}; - mat[2].Kd = {0.8f, 0.682657f, 0.536371f}; - mat[2].Ks = {0.5f, 0.5f, 0.5f}; - mat[2].Ke = {0, 0, 0}; - mat[2].Ns = 440.924042f; - mat[2].Ni = 1.45f; - mat[2].d = 1; - mat[2].illum = 2; + mat[2].ambient_color = {1, 1, 1}; + mat[2].color = {0.8f, 0.682657f, 0.536371f}; + mat[2].spec_color = {0.5f, 0.5f, 0.5f}; + mat[2].emission_color = {0, 0, 0}; + mat[2].spec_exponent = 440.924042f; + mat[2].ior = 1.45f; + mat[2].alpha = 1; + mat[2].illum_mode = 2; mat[3].name = "Hat"; - mat[3].Ka = {1, 1, 1}; - mat[3].Kd = {0.8f, 0.8f, 0.8f}; - mat[3].Ks = {0.5f, 0.5f, 0.5f}; - mat[3].Ns = 800; - mat[3].map_Bump_strength = 0.5f; + mat[3].ambient_color = {1, 1, 1}; + mat[3].color = {0.8f, 0.8f, 0.8f}; + mat[3].spec_color = {0.5f, 0.5f, 0.5f}; + mat[3].spec_exponent = 800; + mat[3].normal_strength = 0.5f; { - MTLTexMap &kd = mat[3].tex_map_of_type(MTLTexMapType::Kd); + MTLTexMap &kd = mat[3].tex_map_of_type(MTLTexMapType::Color); kd.image_path = "someHatTexture_BaseColor.jpg"; - MTLTexMap &ns = mat[3].tex_map_of_type(MTLTexMapType::Ns); + MTLTexMap &ns = mat[3].tex_map_of_type(MTLTexMapType::SpecularExponent); ns.image_path = "someHatTexture_Roughness.jpg"; - MTLTexMap &refl = mat[3].tex_map_of_type(MTLTexMapType::refl); + MTLTexMap &refl = mat[3].tex_map_of_type(MTLTexMapType::Reflection); refl.image_path = "someHatTexture_Metalness.jpg"; - MTLTexMap &bump = mat[3].tex_map_of_type(MTLTexMapType::bump); + MTLTexMap &bump = mat[3].tex_map_of_type(MTLTexMapType::Normal); bump.image_path = "someHatTexture_Normal.jpg"; } mat[4].name = "Parser_Test"; - mat[4].Ka = {0.1f, 0.2f, 0.3f}; - mat[4].Kd = {0.4f, 0.5f, 0.6f}; - mat[4].Ks = {0.7f, 0.8f, 0.9f}; - mat[4].illum = 6; - mat[4].Ns = 15.5; - mat[4].Ni = 1.5; - mat[4].d = 0.5; - mat[4].map_Bump_strength = 0.1f; + mat[4].ambient_color = {0.1f, 0.2f, 0.3f}; + mat[4].color = {0.4f, 0.5f, 0.6f}; + mat[4].spec_color = {0.7f, 0.8f, 0.9f}; + mat[4].illum_mode = 6; + mat[4].spec_exponent = 15.5; + mat[4].ior = 1.5; + mat[4].alpha = 0.5; + mat[4].normal_strength = 0.1f; { - MTLTexMap &kd = mat[4].tex_map_of_type(MTLTexMapType::Kd); + MTLTexMap &kd = mat[4].tex_map_of_type(MTLTexMapType::Color); kd.image_path = "sometex_d.png"; - MTLTexMap &ns = mat[4].tex_map_of_type(MTLTexMapType::Ns); + MTLTexMap &ns = mat[4].tex_map_of_type(MTLTexMapType::SpecularExponent); ns.image_path = "sometex_ns.psd"; - MTLTexMap &refl = mat[4].tex_map_of_type(MTLTexMapType::refl); + MTLTexMap &refl = mat[4].tex_map_of_type(MTLTexMapType::Reflection); refl.image_path = "clouds.tiff"; refl.scale = {1.5f, 2.5f, 3.5f}; refl.translation = {4.5f, 5.5f, 6.5f}; refl.projection_type = SHD_PROJ_SPHERE; - MTLTexMap &bump = mat[4].tex_map_of_type(MTLTexMapType::bump); + MTLTexMap &bump = mat[4].tex_map_of_type(MTLTexMapType::Normal); bump.image_path = "somebump.tga"; bump.scale = {3, 4, 5}; } mat[5].name = "Parser_ScaleOffset_Test"; { - MTLTexMap &kd = mat[5].tex_map_of_type(MTLTexMapType::Kd); + MTLTexMap &kd = mat[5].tex_map_of_type(MTLTexMapType::Color); kd.translation = {2.5f, 0.0f, 0.0f}; kd.image_path = "OffsetOneValue.png"; - MTLTexMap &ks = mat[5].tex_map_of_type(MTLTexMapType::Ks); + MTLTexMap &ks = mat[5].tex_map_of_type(MTLTexMapType::Specular); ks.scale = {1.5f, 2.5f, 1.0f}; ks.translation = {3.5f, 4.5f, 0.0f}; ks.image_path = "ScaleOffsetBothTwovalues.png"; - MTLTexMap &ns = mat[5].tex_map_of_type(MTLTexMapType::Ns); + MTLTexMap &ns = mat[5].tex_map_of_type(MTLTexMapType::SpecularExponent); ns.scale = {0.5f, 1.0f, 1.0f}; ns.image_path = "1.Value.png"; } |