[Bf-blender-cvs] [fc171c1be9d] soc-2020-io-performance: Add more regression tests for new obj exporter.

Howard Trickey noreply at git.blender.org
Sun Oct 17 22:23:03 CEST 2021


Commit: fc171c1be9da36485e892339b86dc8d4251914af
Author: Howard Trickey
Date:   Sun Oct 17 16:17:45 2021 -0400
Branches: soc-2020-io-performance
https://developer.blender.org/rBfc171c1be9da36485e892339b86dc8d4251914af

Add more regression tests for new obj exporter.

This adds regression tests for exporting most of the blend files
in the io_tests/blend_geometry and io_tests/blend_scene tests.
A fix was necessary in the BlendfileLoadingBaseTest class to prevent
leakage of some global data generated when a loaded file has metaballs.
Also, had to fix the exporter to deal with empty curves.

===================================================================

M	source/blender/blenloader/CMakeLists.txt
M	source/blender/blenloader/tests/blendfile_loading_base_test.cc
M	source/blender/io/wavefront_obj/exporter/obj_exporter.cc
M	source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc

===================================================================

diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt
index 89631588ed0..ca4b7cc2a32 100644
--- a/source/blender/blenloader/CMakeLists.txt
+++ b/source/blender/blenloader/CMakeLists.txt
@@ -26,6 +26,7 @@ set(INC
   ../blentranslation
   ../depsgraph
   ../draw
+  ../editors/include
   ../imbuf
   ../makesdna
   ../makesrna
diff --git a/source/blender/blenloader/tests/blendfile_loading_base_test.cc b/source/blender/blenloader/tests/blendfile_loading_base_test.cc
index 8afa631ffc5..ebafab9cd93 100644
--- a/source/blender/blenloader/tests/blendfile_loading_base_test.cc
+++ b/source/blender/blenloader/tests/blendfile_loading_base_test.cc
@@ -26,9 +26,11 @@
 #include "BKE_idtype.h"
 #include "BKE_image.h"
 #include "BKE_main.h"
+#include "BKE_mball_tessellate.h"
 #include "BKE_modifier.h"
 #include "BKE_node.h"
 #include "BKE_scene.h"
+#include "BKE_vfont.h"
 
 #include "BLI_path_util.h"
 #include "BLI_threads.h"
@@ -43,6 +45,8 @@
 
 #include "IMB_imbuf.h"
 
+#include "ED_datafiles.h"
+
 #include "RNA_define.h"
 
 #include "WM_api.h"
@@ -70,6 +74,7 @@ void BlendfileLoadingBaseTest::SetUpTestCase()
   DEG_register_node_types();
   RNA_init();
   BKE_node_system_init();
+  BKE_vfont_builtin_register(datatoc_bfont_pfb, datatoc_bfont_pfb_size);
 
   G.background = true;
   G.factory_startup = true;
@@ -107,6 +112,7 @@ void BlendfileLoadingBaseTest::TearDownTestCase()
 
 void BlendfileLoadingBaseTest::TearDown()
 {
+  BKE_mball_cubeTable_free();
   depsgraph_free();
   blendfile_free();
 
diff --git a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
index 9bf75105d78..1c59bd43aab 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
@@ -112,6 +112,14 @@ filter_supported_objects(Depsgraph *depsgraph, const OBJExportParams &export_par
       case OB_CURVE: {
         Curve *curve = static_cast<Curve *>(object_in_layer->data);
         Nurb *nurb{static_cast<Nurb *>(curve->nurb.first)};
+        if (!nurb) {
+          /* An empty curve. Not yet supported to export these as meshes. */
+          if (export_params.export_curves_as_nurbs) {
+            r_exportable_nurbs.append(
+                std::make_unique<OBJCurve>(depsgraph, export_params, object_in_layer));
+          }
+          break;
+        }
         switch (nurb->type) {
           case CU_NURBS: {
             if (export_params.export_curves_as_nurbs) {
@@ -137,6 +145,7 @@ filter_supported_objects(Depsgraph *depsgraph, const OBJExportParams &export_par
             break;
           }
         }
+        break;
       }
       default: {
         /* Other object types are not supported. */
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 2b6efe8da3f..cec8fc6006f 100644
--- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
@@ -47,10 +47,8 @@ class obj_exporter_test : public BlendfileLoadingBaseTest {
   }
 };
 
-// https://developer.blender.org/F9260238
-const std::string all_objects_file = "io_tests/blend_scene/all_objects_2_92.blend";
-// https://developer.blender.org/F9278970
-const std::string all_curve_objects_file = "io_tests/blend_scene/all_curves_2_92.blend";
+const std::string all_objects_file = "io_tests/blend_scene/all_objects.blend";
+const std::string all_curve_objects_file = "io_tests/blend_scene/all_curves.blend";
 
 TEST_F(obj_exporter_test, filter_objects_curves_as_mesh)
 {
@@ -59,9 +57,8 @@ TEST_F(obj_exporter_test, filter_objects_curves_as_mesh)
     ADD_FAILURE();
     return;
   }
-
   auto [objmeshes, objcurves]{filter_supported_objects(depsgraph, _export.params)};
-  EXPECT_EQ(objmeshes.size(), 22);
+  EXPECT_EQ(objmeshes.size(), 17);
   EXPECT_EQ(objcurves.size(), 0);
 }
 
@@ -74,8 +71,8 @@ TEST_F(obj_exporter_test, filter_objects_curves_as_nurbs)
   }
   _export.params.export_curves_as_nurbs = true;
   auto [objmeshes, objcurves]{filter_supported_objects(depsgraph, _export.params)};
-  EXPECT_EQ(objmeshes.size(), 18);
-  EXPECT_EQ(objcurves.size(), 4);
+  EXPECT_EQ(objmeshes.size(), 16);
+  EXPECT_EQ(objcurves.size(), 2);
 }
 
 TEST_F(obj_exporter_test, filter_objects_selected)
@@ -88,8 +85,8 @@ TEST_F(obj_exporter_test, filter_objects_selected)
   _export.params.export_selected_objects = true;
   _export.params.export_curves_as_nurbs = true;
   auto [objmeshes, objcurves]{filter_supported_objects(depsgraph, _export.params)};
-  EXPECT_EQ(objmeshes.size(), 8);
-  EXPECT_EQ(objcurves.size(), 2);
+  EXPECT_EQ(objmeshes.size(), 1);
+  EXPECT_EQ(objcurves.size(), 0);
 }
 
 TEST(obj_exporter_utils, append_negative_frame_to_filename)
@@ -237,13 +234,32 @@ TEST(obj_exporter_writer, mtllib)
 /* Return true if string #a and string #b are equal after their first newline. */
 static bool strings_equal_after_first_lines(const std::string &a, const std::string &b)
 {
+  bool dbg_level = 0;
   size_t a_len = a.size();
   size_t b_len = b.size();
   size_t a_next = a.find_first_of('\n');
   size_t b_next = b.find_first_of('\n');
   if (a_next == std::string::npos || b_next == std::string::npos) {
+    if (dbg_level > 0) {
+      std::cout << "Couldn't find newline in one of args\n";
+    }
     return false;
   }
+  if (dbg_level > 0) {
+    if (a.compare(a_next, a_len - a_next, b, b_next, b_len - b_next) != 0) {
+      for (int i = 0; i < a_len - a_next && i < b_len - b_next; ++i) {
+        if (a[a_next + i] != b[b_next + i]) {
+          std::cout << "Difference found at pos " << a_next + i << " of a\n";
+          std::cout << "a: " << a.substr(a_next + i, 100) << " ...\n";
+          std::cout << "b: " << b.substr(b_next + i, 100) << " ... \n";
+          return false;
+        }
+      }
+    }
+    else {
+      return true;
+    }
+  }
   return a.compare(a_next, a_len - a_next, b, b_next, b_len - b_next) == 0;
 }
 
@@ -298,4 +314,103 @@ TEST_F(obj_exporter_regression_test, all_tris)
                                _export.params);
 }
 
+TEST_F(obj_exporter_regression_test, all_quads)
+{
+  OBJExportParamsDefault _export;
+  _export.params.scaling_factor = 2.0f;
+  _export.params.export_materials = false;
+  compare_obj_export_to_golden(
+      "io_tests/blend_geometry/all_quads.blend", "io_tests/obj/all_quads.obj", "", _export.params);
+}
+
+TEST_F(obj_exporter_regression_test, fgons)
+{
+  OBJExportParamsDefault _export;
+  _export.params.forward_axis = OBJ_AXIS_Y_FORWARD;
+  _export.params.up_axis = OBJ_AXIS_Z_UP;
+  _export.params.export_materials = false;
+  compare_obj_export_to_golden(
+      "io_tests/blend_geometry/fgons.blend", "io_tests/obj/fgons.obj", "", _export.params);
+}
+
+TEST_F(obj_exporter_regression_test, edges)
+{
+  OBJExportParamsDefault _export;
+  _export.params.forward_axis = OBJ_AXIS_Y_FORWARD;
+  _export.params.up_axis = OBJ_AXIS_Z_UP;
+  _export.params.export_materials = false;
+  compare_obj_export_to_golden(
+      "io_tests/blend_geometry/edges.blend", "io_tests/obj/edges.obj", "", _export.params);
+}
+
+TEST_F(obj_exporter_regression_test, vertices)
+{
+  OBJExportParamsDefault _export;
+  _export.params.forward_axis = OBJ_AXIS_Y_FORWARD;
+  _export.params.up_axis = OBJ_AXIS_Z_UP;
+  _export.params.export_materials = false;
+  compare_obj_export_to_golden(
+      "io_tests/blend_geometry/vertices.blend", "io_tests/obj/vertices.obj", "", _export.params);
+}
+
+TEST_F(obj_exporter_regression_test, nurbs_as_nurbs)
+{
+  OBJExportParamsDefault _export;
+  _export.params.forward_axis = OBJ_AXIS_Y_FORWARD;
+  _export.params.up_axis = OBJ_AXIS_Z_UP;
+  _export.params.export_materials = false;
+  _export.params.export_curves_as_nurbs = true;
+  compare_obj_export_to_golden(
+      "io_tests/blend_geometry/nurbs.blend", "io_tests/obj/nurbs.obj", "", _export.params);
+}
+
+TEST_F(obj_exporter_regression_test, nurbs_as_mesh)
+{
+  OBJExportParamsDefault _export;
+  _export.params.forward_axis = OBJ_AXIS_Y_FORWARD;
+  _export.params.up_axis = OBJ_AXIS_Z_UP;
+  _export.params.export_materials = false;
+  _export.params.export_curves_as_nurbs = false;
+  compare_obj_export_to_golden(
+      "io_tests/blend_geometry/nurbs.blend", "io_tests/obj/nurbs_mesh.obj", "", _export.params);
+}
+
+TEST_F(obj_exporter_regression_test, cube_all_data_triangulated)
+{
+  OBJExportParamsDefault _export;
+  _export.params.forward_axis = OBJ_AXIS_Y_FORWARD;
+  _export.params.up_axis = OBJ_AXIS_Z_UP;
+  _export.params.export_materials = false;
+  _export.params.export_triangulated_mesh = true;
+  compare_obj_export_to_golden("io_tests/blend_geometry/cube_all_data.blend",
+                               "io_tests/obj/cube_all_data_triangulated.obj",
+                               "",
+                               _export.params);
+}
+
+TEST_F(obj_exporter_regression_test, suzanne_all_data)
+{
+  OBJExportParamsDefault _export;
+  _export.params.forward_axis = OBJ_AXIS_Y_FORWARD;
+  _export.params.up_axis = OBJ_AXIS_Z_UP;
+  _export.params.export_materials = false;
+  _export.params.export_smooth_groups = true;
+  compare_obj_export_to_golden("io_tests/blend_geometry/suzanne_all_data.blend",
+                               "io_tests/obj/suzanne_all_data.obj",
+                               "",
+                               _export.params);
+}
+
+TEST_F(obj_exporter_regression_test, all_objects)
+{
+  OBJExportParamsDefault _export;
+  _export.params.forward_axis = OBJ_AXIS_Y_FORWARD;
+  _export.params.up_axis = OBJ_AXIS_Z_UP;
+  _export.params.export_smooth_groups = true;
+  compare_obj_export_to_golden("io_tests/blend_scene/all_objects.blend",
+                               "io_tests/obj/all_objects.obj",
+                               "io_tests/obj/all_objects.mtl",
+                               _export.params);
+}
+
 }  // namespace blender::io::obj



More information about the Bf-blender-cvs mailing list