Fix #116520: OBJ exporter does not add leading zeros in frame filenames

When exporting animation (one .obj file per animation frame), the old
Python OBJ exporter used to emit frame number with leading zeros, e.g.
"000012" which made sorting files by frame easier. The new C++ OBJ
exporter does not do that.

Fix that by reintroducing leading zeros. However, use 4 digits
("0012") since that matches 4 digits used in many other places, and
also it's very unlikely that someone would export more than several
thousand frames into OBJ. If that happens, it all works correctly
anyway, just without leading zeroes.

Fixes #116520
This commit is contained in:
Aras Pranckevicius 2023-12-25 21:47:54 +02:00
parent 72a74ae8cc
commit 140f5f619d
2 changed files with 16 additions and 6 deletions

View File

@ -305,8 +305,7 @@ bool append_frame_to_filename(const char *filepath, const int frame, char *r_fil
{
BLI_strncpy(r_filepath_with_frames, filepath, FILE_MAX);
BLI_path_extension_strip(r_filepath_with_frames);
const int digits = frame == 0 ? 1 : integer_digits_i(abs(frame));
BLI_path_frame(r_filepath_with_frames, FILE_MAX, frame, digits);
BLI_path_frame(r_filepath_with_frames, FILE_MAX, frame, 4);
return BLI_path_extension_replace(r_filepath_with_frames, FILE_MAX, ".obj");
}

View File

@ -97,8 +97,8 @@ TEST_F(obj_exporter_test, filter_objects_selected)
TEST(obj_exporter_utils, append_negative_frame_to_filename)
{
const char path_original[FILE_MAX] = SEP_STR "my_file.obj";
const char path_truth[FILE_MAX] = SEP_STR "my_file-123.obj";
const int frame = -123;
const char path_truth[FILE_MAX] = SEP_STR "my_file-0012.obj";
const int frame = -12;
char path_with_frame[FILE_MAX] = {0};
const bool ok = append_frame_to_filename(path_original, frame, path_with_frame);
EXPECT_TRUE(ok);
@ -108,8 +108,19 @@ TEST(obj_exporter_utils, append_negative_frame_to_filename)
TEST(obj_exporter_utils, append_positive_frame_to_filename)
{
const char path_original[FILE_MAX] = SEP_STR "my_file.obj";
const char path_truth[FILE_MAX] = SEP_STR "my_file123.obj";
const int frame = 123;
const char path_truth[FILE_MAX] = SEP_STR "my_file0012.obj";
const int frame = 12;
char path_with_frame[FILE_MAX] = {0};
const bool ok = append_frame_to_filename(path_original, frame, path_with_frame);
EXPECT_TRUE(ok);
EXPECT_STREQ(path_with_frame, path_truth);
}
TEST(obj_exporter_utils, append_large_positive_frame_to_filename)
{
const char path_original[FILE_MAX] = SEP_STR "my_file.obj";
const char path_truth[FILE_MAX] = SEP_STR "my_file1234567.obj";
const int frame = 1234567;
char path_with_frame[FILE_MAX] = {0};
const bool ok = append_frame_to_filename(path_original, frame, path_with_frame);
EXPECT_TRUE(ok);