3 #include <gtest/gtest.h>
7 #include "testing/testing.h"
19 std::string tmp_file_name =
"mtl_test.mtl";
20 std::string tmp_file_path = tmp_dir +
"/" + tmp_file_name;
21 FILE *tmp_file =
BLI_fopen(tmp_file_path.c_str(),
"wb");
22 fputs(text, tmp_file);
25 check_impl(tmp_file_name, tmp_dir, expect, expect_count);
27 BLI_delete(tmp_file_path.c_str(),
false,
false);
31 std::string obj_dir = blender::tests::flags_test_asset_dir() +
"/io_tests/obj/";
39 MTLParser parser(mtl_file_path, file_dir +
"dummy.obj");
43 for (
int i = 0; i < expect_count; ++i) {
46 fprintf(stderr,
"Material '%s' was expected in parsed result\n",
exp.name.c_str());
51 const float tol = 0.0001f;
52 EXPECT_V3_NEAR(
exp.Ka, got.
Ka, tol);
53 EXPECT_V3_NEAR(
exp.Kd, got.
Kd, tol);
54 EXPECT_V3_NEAR(
exp.Ks, got.
Ks, tol);
55 EXPECT_V3_NEAR(
exp.Ke, got.
Ke, tol);
56 EXPECT_NEAR(
exp.Ns, got.
Ns, tol);
57 EXPECT_NEAR(
exp.Ni, got.
Ni, tol);
58 EXPECT_NEAR(
exp.d, got.
d, tol);
61 for (
const auto &it :
exp.texture_maps.items()) {
66 EXPECT_V3_NEAR(exp_tex.
scale, got_tex.
scale, tol);
78 " # indented comment\n"
79 "# comment with CRLF line ending\r\n"
86 "newmtl\ttab_indentation\n"
87 "Kd\t \t0.2 0.3\t0.4 \t \n"
89 "newmtl space_after_name \t \n"
92 "newmtl space_before_name\n"
94 "newmtl indented_values\n"
96 "\t\t\tKd 0.6 0.7 0.8\n"
98 "newmtl crlf_ending\r\n"
100 "map_Kd sometex_d.png\r\n"
101 "map_Ks sometex_s_spaces_after_name.png \t \r\n";
103 mat[0].
name =
"simple";
104 mat[0].
Ka = {0.1f, 0.2f, 0.3f};
106 mat[1].
name =
"tab_indentation";
107 mat[1].
Kd = {0.2f, 0.3f, 0.4f};
108 mat[2].
name =
"space_after_name";
109 mat[2].
Ks = {0.4f, 0.5f, 0.6f};
110 mat[3].
name =
"space_before_name";
111 mat[4].
name =
"indented_values";
112 mat[4].
Ka = {0.5f, 0.6f, 0.7f};
113 mat[4].
Kd = {0.6f, 0.7f, 0.8f};
114 mat[5].
name =
"crlf_ending";
125 mat.
Ka = {0.2f, 0.2f, 0.2f};
127 check(
"cube.mtl", &mat, 1);
133 for (
auto &m : mat) {
135 m.Ks = {0.5f, 0.5f, 0.5f};
142 mat[0].
name =
"Blue";
143 mat[0].
Kd = {0, 0, 1};
144 mat[1].
name =
"BlueDark";
145 mat[1].
Kd = {0, 0, 0.5f};
146 mat[2].
name =
"Green";
147 mat[2].
Kd = {0, 1, 0};
148 mat[3].
name =
"GreenDark";
149 mat[3].
Kd = {0, 0.5f, 0};
150 mat[4].
name =
"Material";
151 mat[4].
Kd = {0.8f, 0.8f, 0.8f};
153 mat[5].
Kd = {1, 0, 0};
154 mat[6].
name =
"RedDark";
155 mat[6].
Kd = {0.5f, 0, 0};
156 check(
"all_objects.mtl", mat,
ARRAY_SIZE(mat));
162 mat[0].
name =
"no_textures_red";
163 mat[0].
Ka = {0.3f, 0.3f, 0.3f};
164 mat[0].
Kd = {0.8f, 0.3f, 0.1f};
165 mat[0].
Ns = 5.624998f;
167 mat[1].
name =
"four_maps";
168 mat[1].
Ka = {1, 1, 1};
169 mat[1].
Kd = {0.8f, 0.8f, 0.8f};
170 mat[1].
Ks = {0.5f, 0.5f, 0.5f};
171 mat[1].
Ke = {0, 0, 0};
188 mat[2].
name =
"Clay";
189 mat[2].
Ka = {1, 1, 1};
190 mat[2].
Kd = {0.8f, 0.682657f, 0.536371f};
191 mat[2].
Ks = {0.5f, 0.5f, 0.5f};
192 mat[2].
Ke = {0, 0, 0};
193 mat[2].
Ns = 440.924042f;
199 mat[3].
Ka = {1, 1, 1};
200 mat[3].
Kd = {0.8f, 0.8f, 0.8f};
201 mat[3].
Ks = {0.5f, 0.5f, 0.5f};
206 kd.
image_path =
"someHatTexture_BaseColor.jpg";
208 ns.
image_path =
"someHatTexture_Roughness.jpg";
210 refl.
image_path =
"someHatTexture_Metalness.jpg";
212 bump.
image_path =
"someHatTexture_Normal.jpg";
215 mat[4].
name =
"Parser_Test";
216 mat[4].
Ka = {0.1f, 0.2f, 0.3f};
217 mat[4].
Kd = {0.4f, 0.5f, 0.6f};
218 mat[4].
Ks = {0.7f, 0.8f, 0.9f};
231 refl.
scale = {1.5f, 2.5f, 3.5f};
236 bump.
scale = {3, 4, 5};
239 mat[5].
name =
"Parser_ScaleOffset_Test";
245 ks.
scale = {1.5f, 2.5f, 1.0f};
247 ks.
image_path =
"ScaleOffsetBothTwovalues.png";
249 ns.
scale = {0.5f, 1.0f, 1.0f};
void BKE_tempdir_init(const char *userdir)
const char * BKE_tempdir_base(void)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_delete(const char *file, bool dir, bool recursive) ATTR_NONNULL()
void parse_and_store(Map< std::string, std::unique_ptr< MTLMaterial >> &r_materials)
void check(const char *file, const MTLMaterial *expect, size_t expect_count)
void check_impl(StringRefNull mtl_file_path, StringRefNull file_dir, const MTLMaterial *expect, size_t expect_count)
void check_string(const char *text, const MTLMaterial *expect, size_t expect_count)
smooth(Type::VEC4, "color_mul") .smooth(Type gpFillTexture gpSceneDepthTexture materials[GPENCIL_MATERIAL_BUFFER_LEN]
ccl_device_inline float3 exp(float3 v)
TEST_F(obj_exporter_test, filter_objects_curves_as_mesh)
Map< const eMTLSyntaxElement, tex_map_XX > texture_maps
const tex_map_XX & tex_map_of_type(const eMTLSyntaxElement key) const