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: 238fab2f8725b27d52e90d30a7a86c29d04d1ce5 (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
#include "testing/testing.h"

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

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

#include "DEG_depsgraph.h"

class TestableAbcExporter : public AbcExporter {
 public:
  TestableAbcExporter(Main *bmain, const char *filename, ExportSettings &settings)
      : AbcExporter(bmain, filename, settings)
  {
  }

  void getShutterSamples(unsigned int nr_of_samples,
                         bool time_relative,
                         std::vector<double> &samples)
  {
    AbcExporter::getShutterSamples(nr_of_samples, time_relative, samples);
  }

  void getFrameSet(unsigned int nr_of_samples, std::set<double> &frames)
  {
    AbcExporter::getFrameSet(nr_of_samples, frames);
  }
};

class AlembicExportTest : public testing::Test {
 protected:
  ExportSettings settings;
  Scene scene;
  Depsgraph *depsgraph;
  TestableAbcExporter *exporter;
  Main *bmain;

  virtual void SetUp()
  {
    settings.frame_start = 31.0;
    settings.frame_end = 223.0;

    /* 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;

    bmain = BKE_main_new();

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

    settings.scene = &scene;
    settings.view_layer = view_layer;

    exporter = NULL;
  }

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

  // Call after setting up the settings.
  void createExporter()
  {
    exporter = new TestableAbcExporter(bmain, "somefile.abc", settings);
  }
};

TEST_F(AlembicExportTest, TimeSamplesFullShutter)
{
  settings.shutter_open = 0.0;
  settings.shutter_close = 1.0;

  createExporter();
  std::vector<double> samples;

  /* test 5 samples per frame */
  exporter->getShutterSamples(5, true, samples);
  EXPECT_EQ(5, samples.size());
  EXPECT_NEAR(1.240, samples[0], 1e-5f);
  EXPECT_NEAR(1.248, samples[1], 1e-5f);
  EXPECT_NEAR(1.256, samples[2], 1e-5f);
  EXPECT_NEAR(1.264, samples[3], 1e-5f);
  EXPECT_NEAR(1.272, samples[4], 1e-5f);

  /* test same, but using frame number offset instead of time */
  exporter->getShutterSamples(5, false, samples);
  EXPECT_EQ(5, samples.size());
  EXPECT_NEAR(0.0, samples[0], 1e-5f);
  EXPECT_NEAR(0.2, samples[1], 1e-5f);
  EXPECT_NEAR(0.4, samples[2], 1e-5f);
  EXPECT_NEAR(0.6, samples[3], 1e-5f);
  EXPECT_NEAR(0.8, samples[4], 1e-5f);

  /* use the same setup to test getFrameSet() */
  std::set<double> frames;
  exporter->getFrameSet(5, frames);
  EXPECT_EQ(965, frames.size());
  EXPECT_EQ(1, frames.count(31.0));
  EXPECT_EQ(1, frames.count(31.2));
  EXPECT_EQ(1, frames.count(31.4));
  EXPECT_EQ(1, frames.count(31.6));
  EXPECT_EQ(1, frames.count(31.8));
}

TEST_F(AlembicExportTest, TimeSamples180degShutter)
{
  settings.shutter_open = -0.25;
  settings.shutter_close = 0.25;

  createExporter();
  std::vector<double> samples;

  /* test 5 samples per frame */
  exporter->getShutterSamples(5, true, samples);
  EXPECT_EQ(5, samples.size());
  EXPECT_NEAR(1.230, samples[0], 1e-5f);
  EXPECT_NEAR(1.234, samples[1], 1e-5f);
  EXPECT_NEAR(1.238, samples[2], 1e-5f);
  EXPECT_NEAR(1.242, samples[3], 1e-5f);
  EXPECT_NEAR(1.246, samples[4], 1e-5f);

  /* test same, but using frame number offset instead of time */
  exporter->getShutterSamples(5, false, samples);
  EXPECT_EQ(5, samples.size());
  EXPECT_NEAR(-0.25, samples[0], 1e-5f);
  EXPECT_NEAR(-0.15, samples[1], 1e-5f);
  EXPECT_NEAR(-0.05, samples[2], 1e-5f);
  EXPECT_NEAR(0.05, samples[3], 1e-5f);
  EXPECT_NEAR(0.15, samples[4], 1e-5f);

  /* Use the same setup to test getFrameSet().
   * Here only a few numbers are tested, due to rounding issues. */
  std::set<double> frames;
  exporter->getFrameSet(5, frames);
  EXPECT_EQ(965, frames.size());
  EXPECT_EQ(1, frames.count(30.75));
  EXPECT_EQ(1, frames.count(30.95));
  EXPECT_EQ(1, frames.count(31.15));
}