5#include <gtest/gtest.h>
11#include "testing/testing.h"
24 std::string tmp_file_name =
"mtl_test.mtl";
25 std::string tmp_file_path = tmp_dir +
SEP_STR + tmp_file_name;
26 FILE *tmp_file =
BLI_fopen(tmp_file_path.c_str(),
"wb");
27 fputs(text, tmp_file);
30 check_impl(tmp_file_name, tmp_dir, expect, expect_count);
32 BLI_delete(tmp_file_path.c_str(),
false,
false);
36 std::string obj_dir = blender::tests::flags_test_asset_dir() +
38 check_impl(file, obj_dir, expect, expect_count);
45 MTLParser parser(mtl_file_path, file_dir +
"dummy.obj");
49 for (
int i = 0; i < expect_count; ++i) {
51 if (!materials.contains(
exp.name)) {
52 fprintf(stderr,
"Material '%s' was expected in parsed result\n",
exp.name.c_str());
57 const float tol = 0.0001f;
59 EXPECT_V3_NEAR(
exp.color, got.
color, tol);
64 EXPECT_NEAR(
exp.ior, got.
ior, tol);
65 EXPECT_NEAR(
exp.alpha, got.
alpha, tol);
70 EXPECT_NEAR(
exp.sheen, got.
sheen, tol);
73 EXPECT_NEAR(
exp.aniso, got.
aniso, tol);
80 EXPECT_V3_NEAR(exp_tex.
scale, got_tex.
scale, tol);
84 EXPECT_EQ(materials.size(), expect_count);
92 " # indented comment\n"
93 "# comment with CRLF line ending\r\n"
100 "newmtl\ttab_indentation\n"
101 "Kd\t \t0.2 0.3\t0.4 \t \n"
103 "newmtl space_after_name \t \n"
106 "newmtl space_before_name\n"
108 "newmtl indented_values\n"
110 "\t\t\tKd 0.6 0.7 0.8\n"
112 "newmtl crlf_ending\r\n"
114 "map_Kd sometex_d.png\r\n"
115 "map_Ks sometex_s_spaces_after_name.png \t \r\n";
117 mat[0].
name =
"simple";
120 mat[1].
name =
"tab_indentation";
121 mat[1].
color = {0.2f, 0.3f, 0.4f};
122 mat[2].
name =
"space_after_name";
124 mat[3].
name =
"space_before_name";
125 mat[4].
name =
"indented_values";
127 mat[4].
color = {0.6f, 0.7f, 0.8f};
128 mat[5].
name =
"crlf_ending";
140 mat.
color = {1, 0, 0};
141 check(
"cube.mtl", &mat, 1);
147 for (
auto &m : mat) {
149 m.spec_color = {0.5f, 0.5f, 0.5f};
150 m.emission_color = {0, 0, 0};
151 m.spec_exponent = 250;
156 mat[0].
name =
"Blue";
157 mat[0].
color = {0, 0, 1};
158 mat[1].
name =
"BlueDark";
159 mat[1].
color = {0, 0, 0.5f};
160 mat[2].
name =
"Green";
161 mat[2].
color = {0, 1, 0};
162 mat[3].
name =
"GreenDark";
163 mat[3].
color = {0, 0.5f, 0};
164 mat[4].
name =
"Material";
165 mat[4].
color = {0.8f, 0.8f, 0.8f};
167 mat[5].
color = {1, 0, 0};
168 mat[6].
name =
"RedDark";
169 mat[6].
color = {0.5f, 0, 0};
170 check(
"all_objects.mtl", mat,
ARRAY_SIZE(mat));
176 mat[0].
name =
"no_textures_red";
178 mat[0].
color = {0.8f, 0.3f, 0.1f};
181 mat[1].
name =
"four_maps";
183 mat[1].
color = {0.8f, 0.8f, 0.8f};
202 mat[2].
name =
"Clay";
204 mat[2].
color = {0.8f, 0.682657f, 0.536371f};
214 mat[3].
color = {0.8f, 0.8f, 0.8f};
220 kd.
image_path =
"someHatTexture_BaseColor.jpg";
222 ns.
image_path =
"someHatTexture_Roughness.jpg";
224 refl.
image_path =
"someHatTexture_Metalness.jpg";
226 bump.
image_path =
"someHatTexture_Normal.jpg";
229 mat[4].
name =
"Parser_Test";
231 mat[4].
color = {0.4f, 0.5f, 0.6f};
254 refl.
scale = {1.5f, 2.5f, 3.5f};
259 bump.
scale = {3, 4, 5};
262 mat[5].
name =
"Parser_ScaleOffset_Test";
268 ks.
scale = {1.5f, 2.5f, 1.0f};
270 ks.
image_path =
"ScaleOffsetBothTwovalues.png";
272 ns.
scale = {0.5f, 1.0f, 1.0f};
282 mat[0].
name =
"Mat1";
285 mat[0].
color = {0.8f, 0.276449f, 0.101911f};
292 mat[1].
name =
"Mat2";
294 mat[1].
color = {0.8f, 0.8f, 0.8f};
301 ns.
image_path =
"../blend_geometry/texture_roughness.png";
303 ke.
image_path =
"../blend_geometry/texture_illum.png";
306 check(
"materials_without_pbr.mtl", mat,
ARRAY_SIZE(mat));
312 mat[0].
name =
"Mat1";
313 mat[0].
color = {0.8f, 0.276449f, 0.101911f};
321 mat[0].
sheen = 0.06f;
327 mat[1].
name =
"Mat2";
328 mat[1].
color = {0.8f, 0.8f, 0.8f};
340 pr.
image_path =
"../blend_geometry/texture_roughness.png";
342 ps.
image_path =
"../blend_geometry/texture_checker.png";
344 ke.
image_path =
"../blend_geometry/texture_illum.png";
347 check(
"materials_pbr.mtl", mat,
ARRAY_SIZE(mat));
void BKE_tempdir_init(const char *userdir)
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
void parse_and_store(Map< std::string, std::unique_ptr< MTLMaterial > > &r_materials)
void check_string(const char *text, 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(const char *file, const MTLMaterial *expect, size_t expect_count)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline float3 exp(float3 v)
TEST_F(OBJExportTest, filter_objects_curves_as_mesh)
const MTLTexMap & tex_map_of_type(MTLTexMapType key) const
MTLTexMap texture_maps[int(MTLTexMapType::Count)]