[Bf-blender-cvs] [36904f01a69] soc-2020-io-performance: Exporter: add OBJCurves tests.
Ankit Meel
noreply at git.blender.org
Mon Nov 16 11:15:53 CET 2020
Commit: 36904f01a699384cda67751f2119817ee1e6edf6
Author: Ankit Meel
Date: Sat Nov 14 04:07:49 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB36904f01a699384cda67751f2119817ee1e6edf6
Exporter: add OBJCurves tests.
Corresponds to file https://developer.blender.org/F9278970 which
should be dropped at `io_tests/blend_scene/all_curves_2_92.blend`.
===================================================================
M source/blender/io/wavefront_obj/CMakeLists.txt
M source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
A source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
===================================================================
diff --git a/source/blender/io/wavefront_obj/CMakeLists.txt b/source/blender/io/wavefront_obj/CMakeLists.txt
index d0cf610a111..412aa5bc7c5 100644
--- a/source/blender/io/wavefront_obj/CMakeLists.txt
+++ b/source/blender/io/wavefront_obj/CMakeLists.txt
@@ -80,6 +80,7 @@ blender_add_lib(bf_wavefront_obj "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
if(WITH_GTESTS)
set(TEST_SRC
tests/obj_exporter_tests.cc
+ tests/obj_exporter_tests.hh
)
set(TEST_INC
diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
index 973d5edd5f1..1cc5953842f 100644
--- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
@@ -2,11 +2,12 @@
#include <gtest/gtest.h>
#include <ios>
+#include <memory>
#include "testing/testing.h"
#include "tests/blendfile_loading_base_test.h"
-#include "BLI_float3.hh"
+#include "BLI_index_range.hh"
#include "BLI_string_utf8.h"
#include "BLI_vector.hh"
@@ -17,6 +18,8 @@
#include "obj_export_nurbs.hh"
#include "obj_exporter.hh"
+#include "obj_exporter_tests.hh"
+
namespace blender::io::obj {
class Export_OBJ : public BlendfileLoadingBaseTest {
@@ -65,6 +68,7 @@ struct OBJExportParamsDefault {
};
const std::string all_objects_file = "io_tests/blend_scene/all_objects_2_92.blend";
+const std::string all_curve_objects_file = "io_tests/blend_scene/all_curves_2_92.blend";
TEST_F(Export_OBJ, filter_objects_as_mesh)
{
@@ -124,4 +128,42 @@ TEST(Export_OBJ_utils, append_positive_frame_to_filename)
EXPECT_TRUE(ok);
EXPECT_EQ_ARRAY(path_with_frame, path_expected, BLI_strlen_utf8(path_expected));
}
+
+TEST_F(Export_OBJ, OBJCurve)
+{
+ if (!load_file_and_depsgraph(all_curve_objects_file)) {
+ return;
+ }
+ const std::map<std::string, std::unique_ptr<NurbsObject>> all_nurbs_truth = []() {
+ std::map<std::string, std::unique_ptr<NurbsObject>> t;
+ t.emplace("NurbsCurve", std::make_unique<NurbsObject>("NurbsCurve", coordinates_NurbsCurve));
+ t.emplace("NurbsCircle",
+ std::make_unique<NurbsObject>("NurbsCircle", coordinates_NurbsCircle));
+ t.emplace("NurbsPath", std::make_unique<NurbsObject>("NurbsPath", coordinates_NurbsPath));
+ return t;
+ }();
+
+ OBJExportParamsDefault _export;
+ _export.params.export_curves_as_nurbs = true;
+ auto [objmeshes_unused, objcurves]{filter_supported_objects(depsgraph, _export.params)};
+
+ for (StealUniquePtr<OBJCurve> objcurve : objcurves) {
+ if (all_nurbs_truth.count(objcurve->get_curve_name()) != 1) {
+ ADD_FAILURE();
+ return;
+ }
+ const NurbsObject *const nurbs_truth = all_nurbs_truth.at(objcurve->get_curve_name()).get();
+ EXPECT_EQ(objcurve->total_splines(), nurbs_truth->total_splines());
+ for (int spline_index : IndexRange(objcurve->total_splines())) {
+ EXPECT_EQ(objcurve->total_nurbs_points(spline_index),
+ nurbs_truth->total_nurbs_points(spline_index));
+ for (int vertex : IndexRange(objcurve->total_nurbs_points(spline_index))) {
+ EXPECT_V3_NEAR(
+ objcurve->get_nurbs_point_coords(spline_index, vertex, _export.params.scaling_factor),
+ nurbs_truth->get_nurbs_point_coords(spline_index, vertex),
+ 0.000001f);
+ }
+ }
+ }
+}
} // namespace blender::io::obj
diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
new file mode 100644
index 00000000000..720ee873a30
--- /dev/null
+++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
@@ -0,0 +1,75 @@
+/* Apache License, Version 2.0 */
+
+/**
+ * This file contains default values for several items like
+ * vertex coordinates, export parameters, MTL values etc.
+ */
+
+#pragma once
+
+#include <array>
+#include <gtest/gtest.h>
+#include <string>
+#include <vector>
+
+namespace blender::io::obj {
+
+using arr_float_3 = std::array<float, 3>;
+
+class NurbsObject {
+ private:
+ std::string nurbs_name_;
+ std::vector<std::vector<arr_float_3>> coordinates_;
+
+ public:
+ NurbsObject(const std::string nurbs_name,
+ const std::vector<std::vector<arr_float_3>> coordinates)
+ : nurbs_name_(nurbs_name), coordinates_(coordinates)
+ {
+ }
+
+ int total_splines() const
+ {
+ return coordinates_.size();
+ }
+
+ int total_nurbs_points(const int spline_index) const
+ {
+ if (spline_index >= coordinates_.size()) {
+ ADD_FAILURE();
+ return 0;
+ }
+ return coordinates_[spline_index].size();
+ }
+
+ const float *get_nurbs_point_coords(const int spline_index, const int vertex_index) const
+ {
+ return coordinates_[spline_index][vertex_index].data();
+ }
+};
+
+const std::vector<std::vector<arr_float_3>> coordinates_NurbsCurve{
+ {{9.947419, 0.000000, 0.000000},
+ {9.447419, 0.000000, 1.000000},
+ {7.447419, 0.000000, 1.000000},
+ {6.947419, 0.000000, 0.000000}}};
+const std::vector<std::vector<arr_float_3>> coordinates_NurbsCircle{
+ {{11.463165, 0.000000, -1.000000},
+ {12.463165, 0.000000, -1.000000},
+ {12.463165, 0.000000, 0.000000},
+ {12.463165, 0.000000, 1.000000},
+ {11.463165, 0.000000, 1.000000},
+ {10.463165, 0.000000, 1.000000},
+ {10.463165, 0.000000, 0.000000},
+ {10.463165, 0.000000, -1.000000}}};
+const std::vector<std::vector<arr_float_3>> coordinates_NurbsPath{
+ {{17.690557, 0.000000, 0.000000},
+ {16.690557, 0.000000, 0.000000},
+ {15.690557, 0.000000, 0.000000},
+ {14.690557, 0.000000, 0.000000},
+ {13.690557, 0.000000, 0.000000}},
+ {{17.188307, 0.000000, 0.000000},
+ {16.688307, 0.000000, 1.000000},
+ {14.688307, 0.000000, 1.000000},
+ {14.188307, 0.000000, 0.000000}}};
+} // namespace blender::io::obj
More information about the Bf-blender-cvs
mailing list