5#include <gtest/gtest.h>
11#include "testing/testing.h"
97TEST(obj_exporter_utils, append_negative_frame_to_filename)
101 const int frame = -12;
102 char path_with_frame[
FILE_MAX] = {0};
105 EXPECT_STREQ(path_with_frame, path_truth);
108TEST(obj_exporter_utils, append_positive_frame_to_filename)
112 const int frame = 12;
113 char path_with_frame[
FILE_MAX] = {0};
116 EXPECT_STREQ(path_with_frame, path_truth);
119TEST(obj_exporter_utils, append_large_positive_frame_to_filename)
123 const int frame = 1234567;
124 char path_with_frame[
FILE_MAX] = {0};
127 EXPECT_STREQ(path_with_frame, path_truth);
135 if (buffer !=
nullptr) {
136 res.assign((
const char *)buffer, buffer_len);
158 const char *
const temp_file_path =
"output\xc4\x84\xd0\x96.OBJ";
164 const std::string &out_filepath)
167 auto writer = std::make_unique<OBJWriter>(out_filepath.c_str(),
params);
170 catch (
const std::system_error &ex) {
171 std::cerr << ex.code().category().name() <<
": " << ex.what() <<
": " << ex.code().message()
182 std::string out_file_path = get_temp_obj_filename();
185 std::unique_ptr<OBJWriter> writer = init_writer(_export.
params, out_file_path);
190 writer->write_header();
193 using namespace std::string_literals;
199 std::string out_file_path = get_temp_obj_filename();
202 std::unique_ptr<OBJWriter> writer = init_writer(_export.
params, out_file_path);
207 writer->write_mtllib_name(
"/Users/blah.mtl");
208 writer->write_mtllib_name(
"\\C:\\blah.mtl");
211 ASSERT_EQ(
result,
"mtllib blah.mtl\nmtllib blah.mtl\n");
214TEST(obj_exporter_writer, format_handler_buffer_chunking)
230 ASSERT_EQ(got_blocks, 7);
233 using namespace std::string_literals;
234 const char *expected = R
"(o abc
238o 012345678901234567890123456789abcd
243 ASSERT_EQ(got_string, expected);
249 const size_t a_len = a.size();
250 const size_t b_len =
b.size();
251 const size_t a_next = a.find_first_of(
'\n');
252 const size_t b_next =
b.find_first_of(
'\n');
253 if (a_next == std::string::npos || b_next == std::string::npos) {
254 std::cout <<
"Couldn't find newline in one of args\n";
257 if (a.compare(a_next, a_len - a_next,
b, b_next, b_len - b_next) != 0) {
258 for (
int i = 0; i < a_len - a_next && i < b_len - b_next; ++i) {
259 if (a[a_next + i] !=
b[b_next + i]) {
260 std::cout <<
"Difference found at pos " << a_next + i <<
" of a\n";
261 std::cout <<
"a: " << a.substr(a_next + i, 100) <<
" ...\n";
262 std::cout <<
"b: " <<
b.substr(b_next + i, 100) <<
" ... \n";
272class OBJExportRegressionTest :
public OBJExportTest {
282 const std::string &golden_obj,
283 const std::string &golden_mtl,
295 std::string golden_file_path = blender::tests::flags_test_asset_dir() +
SEP_STR + golden_obj;
297 golden_file_path.c_str(),
params.file_base_for_tests,
sizeof(
params.file_base_for_tests));
304 printf(
"failing test output in %s\n", out_file_path.c_str());
306 ASSERT_TRUE(are_equal);
308 BLI_delete(out_file_path.c_str(),
false,
false);
310 if (!golden_mtl.empty()) {
313 std::string golden_mtl_file_path = blender::tests::flags_test_asset_dir() +
SEP_STR +
318 printf(
"failing test output in %s\n", out_mtl_file_path.c_str());
320 ASSERT_TRUE(are_equal);
322 BLI_delete(out_mtl_file_path.c_str(),
false,
false);
331 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "all_tris.blend",
337TEST_F(OBJExportRegressionTest, all_quads)
339 OBJExportParamsDefault _export;
340 _export.params.global_scale = 2.0f;
341 _export.params.export_materials =
false;
342 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "all_quads.blend",
348TEST_F(OBJExportRegressionTest, fgons)
350 OBJExportParamsDefault _export;
353 _export.params.export_materials =
false;
354 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "fgons.blend",
360TEST_F(OBJExportRegressionTest, edges)
362 OBJExportParamsDefault _export;
365 _export.params.export_materials =
false;
366 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "edges.blend",
372TEST_F(OBJExportRegressionTest, vertices)
374 OBJExportParamsDefault _export;
377 _export.params.export_materials =
false;
378 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
379 "cube_loose_edges_verts.blend",
385TEST_F(OBJExportRegressionTest, cube_loose_edges)
387 OBJExportParamsDefault _export;
390 _export.params.export_materials =
false;
391 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "vertices.blend",
397TEST_F(OBJExportRegressionTest, non_uniform_scale)
399 OBJExportParamsDefault _export;
400 _export.params.export_materials =
false;
401 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
402 "non_uniform_scale.blend",
408TEST_F(OBJExportRegressionTest, nurbs_as_nurbs)
410 OBJExportParamsDefault _export;
413 _export.params.export_materials =
false;
414 _export.params.export_curves_as_nurbs =
true;
415 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "nurbs.blend",
421TEST_F(OBJExportRegressionTest, nurbs_curves_as_nurbs)
423 OBJExportParamsDefault _export;
426 _export.params.export_materials =
false;
427 _export.params.export_curves_as_nurbs =
true;
428 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "nurbs_curves.blend",
434TEST_F(OBJExportRegressionTest, nurbs_as_mesh)
436 OBJExportParamsDefault _export;
439 _export.params.export_materials =
false;
440 _export.params.export_curves_as_nurbs =
false;
441 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "nurbs.blend",
447TEST_F(OBJExportRegressionTest, cube_all_data_triangulated)
449 OBJExportParamsDefault _export;
452 _export.params.export_materials =
false;
453 _export.params.export_triangulated_mesh =
true;
454 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "cube_all_data.blend",
455 "io_tests" SEP_STR "obj" SEP_STR "cube_all_data_triangulated.obj",
460TEST_F(OBJExportRegressionTest, cube_normal_edit)
462 OBJExportParamsDefault _export;
465 _export.params.export_materials =
false;
466 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
467 "cube_normal_edit.blend",
473TEST_F(OBJExportRegressionTest, cube_vertex_groups)
475 OBJExportParamsDefault _export;
476 _export.params.export_materials =
false;
477 _export.params.export_normals =
false;
478 _export.params.export_uv =
false;
479 _export.params.export_vertex_groups =
true;
480 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
481 "cube_vertex_groups.blend",
487TEST_F(OBJExportRegressionTest, cubes_positioned)
489 OBJExportParamsDefault _export;
490 _export.params.export_materials =
false;
491 _export.params.global_scale = 2.0f;
492 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
493 "cubes_positioned.blend",
499TEST_F(OBJExportRegressionTest, cubes_vertex_colors)
501 OBJExportParamsDefault _export;
502 _export.params.export_colors =
true;
503 _export.params.export_normals =
false;
504 _export.params.export_uv =
false;
505 _export.params.export_materials =
false;
506 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
507 "cubes_vertex_colors.blend",
513TEST_F(OBJExportRegressionTest, cubes_with_textures_strip)
515 OBJExportParamsDefault _export;
517 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
518 "cubes_with_textures.blend",
524TEST_F(OBJExportRegressionTest, cubes_with_textures_relative)
526 OBJExportParamsDefault _export;
528 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
529 "cubes_with_textures.blend",
535TEST_F(OBJExportRegressionTest, suzanne_all_data)
537 OBJExportParamsDefault _export;
540 _export.params.export_materials =
false;
541 _export.params.export_smooth_groups =
true;
542 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
543 "suzanne_all_data.blend",
549TEST_F(OBJExportRegressionTest, all_curves)
553 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_curves.blend",
559TEST_F(OBJExportRegressionTest, all_curves_as_nurbs)
561 OBJExportParamsDefault _export;
562 _export.params.export_materials =
false;
563 _export.params.export_curves_as_nurbs =
true;
564 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_curves.blend",
570TEST_F(OBJExportRegressionTest, all_objects)
572 OBJExportParamsDefault _export;
575 _export.params.export_smooth_groups =
true;
576 _export.params.export_colors =
true;
577 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_objects.blend",
583TEST_F(OBJExportRegressionTest, all_objects_mat_groups)
585 OBJExportParamsDefault _export;
588 _export.params.export_smooth_groups =
true;
589 _export.params.export_material_groups =
true;
590 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_objects.blend",
596TEST_F(OBJExportRegressionTest, materials_without_pbr)
598 OBJExportParamsDefault _export;
599 _export.params.export_normals =
false;
601 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "materials_pbr.blend",
607TEST_F(OBJExportRegressionTest, materials_pbr)
609 OBJExportParamsDefault _export;
610 _export.params.export_normals =
false;
612 _export.params.export_pbr_extensions =
true;
613 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "materials_pbr.blend",
void BKE_tempdir_init(const char *userdir)
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
void BKE_tempdir_session_purge()
const char * BKE_blender_version_string(void)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
File and directory operations.
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
void * BLI_file_read_text_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
#define STRNCPY(dst, src)
external readfile function prototypes.
@ PATH_REFERENCE_RELATIVE
BPy_StructRNA * depsgraph
virtual void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode)
bool blendfile_load(const char *filepath)
struct Depsgraph * depsgraph
struct BlendFileData * bfile
void compare_obj_export_to_golden(const std::string &blendfile, const std::string &golden_obj, const std::string &golden_mtl, OBJExportParams ¶ms)
bool load_file_and_depsgraph(const std::string &filepath, const eEvaluationMode eval_mode=DAG_EVAL_VIEWPORT)
std::unique_ptr< OBJWriter > init_writer(const OBJExportParams ¶ms, const std::string &out_filepath)
std::string get_temp_obj_filename()
local_group_size(16, 16) .push_constant(Type b
void MEM_freeN(void *vmemh)
bool append_frame_to_filename(const char *filepath, const int frame, char r_filepath_with_frames[1024])
static bool strings_equal_after_first_lines(const std::string &a, const std::string &b)
TEST_F(OBJExportTest, filter_objects_curves_as_mesh)
TEST(obj_exporter_utils, append_negative_frame_to_filename)
constexpr bool save_failing_test_output
const std::string all_objects_file
static std::string read_temp_file_in_string(const std::string &file_path)
std::pair< Vector< std::unique_ptr< OBJMesh > >, Vector< std::unique_ptr< OBJCurve > > > filter_supported_objects(Depsgraph *depsgraph, const OBJExportParams &export_params)
void export_frame(Depsgraph *depsgraph, const OBJExportParams &export_params, const char *filepath)
bool export_curves_as_nurbs
bool export_selected_objects
void * BKE_tempdir_session