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