Welcome to mirror list, hosted at ThFree Co, Russian Federation.

abc_export_test.cc « alembic « gtests « tests - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cdc981785505d9afc2eb9051badf68828832db2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "testing/testing.h"

// Keep first since utildefines defines AT which conflicts with STL
#include "exporter/abc_archive.h"
#include "intern/abc_util.h"

extern "C" {
#include "BKE_main.h"
#include "BLI_fileops.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "DNA_scene_types.h"
}

#include "DEG_depsgraph.h"

namespace blender {
namespace io {
namespace alembic {

class AlembicExportTest : public testing::Test {
 protected:
  ABCArchive *abc_archive;

  AlembicExportParams params;
  Scene scene;
  Depsgraph *depsgraph;
  Main *bmain;

  virtual void SetUp()
  {
    abc_archive = nullptr;

    /* Fake a 25 FPS scene with a nonzero base (because that's sometimes forgotten) */
    scene.r.frs_sec = 50;
    scene.r.frs_sec_base = 2;
    strcpy(scene.id.name, "SCTestScene");

    bmain = BKE_main_new();

    /* TODO(sergey): Pass scene layer somehow? */
    ViewLayer *view_layer = (ViewLayer *)scene.view_layers.first;
    depsgraph = DEG_graph_new(bmain, &scene, view_layer, DAG_EVAL_RENDER);
  }

  virtual void TearDown()
  {
    BKE_main_free(bmain);
    DEG_graph_free(depsgraph);
    deleteArchive();
  }

  // Call after setting up the parameters.
  void createArchive()
  {
    if (abc_archive != nullptr) {
      deleteArchive();
    }
    abc_archive = new ABCArchive(bmain, &scene, params, "somefile.abc");
  }

  void deleteArchive()
  {
    delete abc_archive;
    if (BLI_exists("somefile.abc")) {
      BLI_delete("somefile.abc", false, false);
    }
    abc_archive = nullptr;
  }
};

TEST_F(AlembicExportTest, TimeSamplesFullShutterUniform)
{
  /* Test 5 samples per frame, for 2 frames. */
  params.shutter_open = 0.0;
  params.shutter_close = 1.0;
  params.frame_start = 31.0;
  params.frame_end = 32.0;
  params.frame_samples_xform = params.frame_samples_shape = 5;
  createArchive();
  std::vector<double> frames(abc_archive->frames_begin(), abc_archive->frames_end());
  EXPECT_EQ(10, frames.size());
  EXPECT_NEAR(31.0, frames[0], 1e-5);
  EXPECT_NEAR(31.2, frames[1], 1e-5);
  EXPECT_NEAR(31.4, frames[2], 1e-5);
  EXPECT_NEAR(31.6, frames[3], 1e-5);
  EXPECT_NEAR(31.8, frames[4], 1e-5);
  EXPECT_NEAR(32.0, frames[5], 1e-5);
  EXPECT_NEAR(32.2, frames[6], 1e-5);
  EXPECT_NEAR(32.4, frames[7], 1e-5);
  EXPECT_NEAR(32.6, frames[8], 1e-5);
  EXPECT_NEAR(32.8, frames[9], 1e-5);

  for (double frame : frames) {
    EXPECT_TRUE(abc_archive->is_xform_frame(frame));
    EXPECT_TRUE(abc_archive->is_shape_frame(frame));
  }
}

TEST_F(AlembicExportTest, TimeSamplesFullShutterDifferent)
{
  /* Test 3 samples per frame for transforms, and 2 per frame for shapes, for 2 frames. */
  params.shutter_open = 0.0;
  params.shutter_close = 1.0;
  params.frame_start = 31.0;
  params.frame_end = 32.0;
  params.frame_samples_xform = 3;
  params.frame_samples_shape = 2;
  createArchive();
  std::vector<double> frames(abc_archive->frames_begin(), abc_archive->frames_end());
  EXPECT_EQ(8, frames.size());
  EXPECT_NEAR(31.0, frames[0], 1e-5);  // transform + shape
  EXPECT_TRUE(abc_archive->is_xform_frame(frames[0]));
  EXPECT_TRUE(abc_archive->is_shape_frame(frames[0]));
  EXPECT_NEAR(31.33333, frames[1], 1e-5);  // transform
  EXPECT_TRUE(abc_archive->is_xform_frame(frames[1]));
  EXPECT_FALSE(abc_archive->is_shape_frame(frames[1]));
  EXPECT_NEAR(31.5, frames[2], 1e-5);  // shape
  EXPECT_FALSE(abc_archive->is_xform_frame(frames[2]));
  EXPECT_TRUE(abc_archive->is_shape_frame(frames[2]));
  EXPECT_NEAR(31.66666, frames[3], 1e-5);  // transform
  EXPECT_TRUE(abc_archive->is_xform_frame(frames[3]));
  EXPECT_FALSE(abc_archive->is_shape_frame(frames[3]));
  EXPECT_NEAR(32.0, frames[4], 1e-5);  // transform + shape
  EXPECT_TRUE(abc_archive->is_xform_frame(frames[4]));
  EXPECT_TRUE(abc_archive->is_shape_frame(frames[4]));
  EXPECT_NEAR(32.33333, frames[5], 1e-5);  // transform
  EXPECT_TRUE(abc_archive->is_xform_frame(frames[5]));
  EXPECT_FALSE(abc_archive->is_shape_frame(frames[5]));
  EXPECT_NEAR(32.5, frames[6], 1e-5);  // shape
  EXPECT_FALSE(abc_archive->is_xform_frame(frames[6]));
  EXPECT_TRUE(abc_archive->is_shape_frame(frames[6]));
  EXPECT_NEAR(32.66666, frames[7], 1e-5);  // transform
  EXPECT_TRUE(abc_archive->is_xform_frame(frames[7]));
  EXPECT_FALSE(abc_archive->is_shape_frame(frames[7]));
}

TEST_F(AlembicExportTest, TimeSamples180degShutter)
{
  /* Test 5 samples per frame, for 2 frames. */
  params.shutter_open = -0.25;
  params.shutter_close = 0.25;
  params.frame_start = 31.0;
  params.frame_end = 32.0;
  params.frame_samples_xform = params.frame_samples_shape = 5;
  createArchive();
  std::vector<double> frames(abc_archive->frames_begin(), abc_archive->frames_end());
  EXPECT_EQ(10, frames.size());
  EXPECT_NEAR(31 - 0.25, frames[0], 1e-5);
  EXPECT_NEAR(31 - 0.15, frames[1], 1e-5);
  EXPECT_NEAR(31 - 0.05, frames[2], 1e-5);
  EXPECT_NEAR(31 + 0.05, frames[3], 1e-5);
  EXPECT_NEAR(31 + 0.15, frames[4], 1e-5);
  EXPECT_NEAR(32 - 0.25, frames[5], 1e-5);
  EXPECT_NEAR(32 - 0.15, frames[6], 1e-5);
  EXPECT_NEAR(32 - 0.05, frames[7], 1e-5);
  EXPECT_NEAR(32 + 0.05, frames[8], 1e-5);
  EXPECT_NEAR(32 + 0.15, frames[9], 1e-5);
}

}  // namespace alembic
}  // namespace io
}  // namespace blender