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