Blender V4.3
abc_export_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "testing/testing.h"
6
7/* Keep first since utildefines defines AT which conflicts with STL */
9#include "intern/abc_util.h"
10
11#include "BKE_main.hh"
12#include "BLI_fileops.h"
13#include "BLI_string.h"
14#include "BLI_utildefines.h"
15#include "DNA_scene_types.h"
16
17#include "DEG_depsgraph.hh"
18
19namespace blender::io::alembic {
20
21class AlembicExportTest : public testing::Test {
22 protected:
24
27 Depsgraph *depsgraph;
29
30 void SetUp() override
31 {
32 abc_archive = nullptr;
33
34 /* Fake a 25 FPS scene with a nonzero base (because that's sometimes forgotten) */
35 scene.r.frs_sec = 50;
36 scene.r.frs_sec_base = 2;
37 STRNCPY(scene.id.name, "SCTestScene");
38
40
42
43 /* TODO(sergey): Pass scene layer somehow? */
44 ViewLayer *view_layer = (ViewLayer *)scene.view_layers.first;
45 depsgraph = DEG_graph_new(bmain, &scene, view_layer, DAG_EVAL_RENDER);
46 }
47
48 void TearDown() override
49 {
54 }
55
56 /* Call after setting up the parameters. */
58 {
59 if (abc_archive != nullptr) {
61 }
62 abc_archive = new ABCArchive(bmain, &scene, params, "somefile.abc");
63 }
64
66 {
67 delete abc_archive;
68 if (BLI_exists("somefile.abc")) {
69 BLI_delete("somefile.abc", false, false);
70 }
71 abc_archive = nullptr;
72 }
73};
74
75TEST_F(AlembicExportTest, TimeSamplesFullShutterUniform)
76{
77 /* Test 5 samples per frame, for 2 frames. */
78 params.shutter_open = 0.0;
79 params.shutter_close = 1.0;
80 params.frame_start = 31.0;
81 params.frame_end = 32.0;
82 params.frame_samples_xform = params.frame_samples_shape = 5;
83 createArchive();
84 std::vector<double> frames(abc_archive->frames_begin(), abc_archive->frames_end());
85 EXPECT_EQ(10, frames.size());
86 EXPECT_NEAR(31.0, frames[0], 1e-5);
87 EXPECT_NEAR(31.2, frames[1], 1e-5);
88 EXPECT_NEAR(31.4, frames[2], 1e-5);
89 EXPECT_NEAR(31.6, frames[3], 1e-5);
90 EXPECT_NEAR(31.8, frames[4], 1e-5);
91 EXPECT_NEAR(32.0, frames[5], 1e-5);
92 EXPECT_NEAR(32.2, frames[6], 1e-5);
93 EXPECT_NEAR(32.4, frames[7], 1e-5);
94 EXPECT_NEAR(32.6, frames[8], 1e-5);
95 EXPECT_NEAR(32.8, frames[9], 1e-5);
96
97 for (double frame : frames) {
98 EXPECT_TRUE(abc_archive->is_xform_frame(frame));
99 EXPECT_TRUE(abc_archive->is_shape_frame(frame));
100 }
101}
102
103TEST_F(AlembicExportTest, TimeSamplesFullShutterDifferent)
104{
105 /* Test 3 samples per frame for transforms, and 2 per frame for shapes, for 2 frames. */
106 params.shutter_open = 0.0;
107 params.shutter_close = 1.0;
108 params.frame_start = 31.0;
109 params.frame_end = 32.0;
110 params.frame_samples_xform = 3;
111 params.frame_samples_shape = 2;
112 createArchive();
113 std::vector<double> frames(abc_archive->frames_begin(), abc_archive->frames_end());
114 EXPECT_EQ(8, frames.size());
115 EXPECT_NEAR(31.0, frames[0], 1e-5); /* transform + shape */
116 EXPECT_TRUE(abc_archive->is_xform_frame(frames[0]));
117 EXPECT_TRUE(abc_archive->is_shape_frame(frames[0]));
118 EXPECT_NEAR(31.33333, frames[1], 1e-5); /* transform */
119 EXPECT_TRUE(abc_archive->is_xform_frame(frames[1]));
120 EXPECT_FALSE(abc_archive->is_shape_frame(frames[1]));
121 EXPECT_NEAR(31.5, frames[2], 1e-5); /* shape */
122 EXPECT_FALSE(abc_archive->is_xform_frame(frames[2]));
123 EXPECT_TRUE(abc_archive->is_shape_frame(frames[2]));
124 EXPECT_NEAR(31.66666, frames[3], 1e-5); /* transform */
125 EXPECT_TRUE(abc_archive->is_xform_frame(frames[3]));
126 EXPECT_FALSE(abc_archive->is_shape_frame(frames[3]));
127 EXPECT_NEAR(32.0, frames[4], 1e-5); /* transform + shape */
128 EXPECT_TRUE(abc_archive->is_xform_frame(frames[4]));
129 EXPECT_TRUE(abc_archive->is_shape_frame(frames[4]));
130 EXPECT_NEAR(32.33333, frames[5], 1e-5); /* transform */
131 EXPECT_TRUE(abc_archive->is_xform_frame(frames[5]));
132 EXPECT_FALSE(abc_archive->is_shape_frame(frames[5]));
133 EXPECT_NEAR(32.5, frames[6], 1e-5); /* shape */
134 EXPECT_FALSE(abc_archive->is_xform_frame(frames[6]));
135 EXPECT_TRUE(abc_archive->is_shape_frame(frames[6]));
136 EXPECT_NEAR(32.66666, frames[7], 1e-5); /* transform */
137 EXPECT_TRUE(abc_archive->is_xform_frame(frames[7]));
138 EXPECT_FALSE(abc_archive->is_shape_frame(frames[7]));
139}
140
141TEST_F(AlembicExportTest, TimeSamples180degShutter)
142{
143 /* Test 5 samples per frame, for 2 frames. */
144 params.shutter_open = -0.25;
145 params.shutter_close = 0.25;
146 params.frame_start = 31.0;
147 params.frame_end = 32.0;
148 params.frame_samples_xform = params.frame_samples_shape = 5;
149 createArchive();
150 std::vector<double> frames(abc_archive->frames_begin(), abc_archive->frames_end());
151 EXPECT_EQ(10, frames.size());
152 EXPECT_NEAR(31 - 0.25, frames[0], 1e-5);
153 EXPECT_NEAR(31 - 0.15, frames[1], 1e-5);
154 EXPECT_NEAR(31 - 0.05, frames[2], 1e-5);
155 EXPECT_NEAR(31 + 0.05, frames[3], 1e-5);
156 EXPECT_NEAR(31 + 0.15, frames[4], 1e-5);
157 EXPECT_NEAR(32 - 0.25, frames[5], 1e-5);
158 EXPECT_NEAR(32 - 0.15, frames[6], 1e-5);
159 EXPECT_NEAR(32 - 0.05, frames[7], 1e-5);
160 EXPECT_NEAR(32 + 0.05, frames[8], 1e-5);
161 EXPECT_NEAR(32 + 0.15, frames[9], 1e-5);
162}
163
164} // namespace blender::io::alembic
Main * BKE_main_new(void)
Definition main.cc:45
void BKE_main_free(Main *bmain)
Definition main.cc:175
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
File and directory operations.
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:350
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
#define STRNCPY(dst, src)
Definition BLI_string.h:593
void DEG_free_node_types()
@ DAG_EVAL_RENDER
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
Definition depsgraph.cc:273
void DEG_register_node_types()
void DEG_graph_free(Depsgraph *graph)
Definition depsgraph.cc:301
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
TEST_F(AlembicExportTest, TimeSamplesFullShutterUniform)