[Bf-blender-cvs] [c857405c0d2] blender-v3.2-release: Fix T100017: OBJ: new importer does not import vertices that aren't part of any face

Aras Pranckevicius noreply at git.blender.org
Thu Jul 28 16:20:47 CEST 2022


Commit: c857405c0d28a187889ce8890bd09e7391bc0218
Author: Aras Pranckevicius
Date:   Thu Jul 28 16:39:42 2022 +0300
Branches: blender-v3.2-release
https://developer.blender.org/rBc857405c0d28a187889ce8890bd09e7391bc0218

Fix T100017: OBJ: new importer does not import vertices that aren't part of any face

The Python based importer had a special case handling of "no faces in
the whole file at all", where it ended up treating the whole file
as essentially a point-cloud-like object (just loose vertices, no
faces or edges). The new importer code was missing this special case.

Fixes T100017. Added gtest coverage that was failing without the fix.

# Conflicts:
#	source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc

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

M	source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
M	source/blender/io/wavefront_obj/tests/obj_importer_tests.cc

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

diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
index 6dd696d0c21..2a8ffd44d63 100644
--- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
@@ -13,6 +13,8 @@
 
 #include "obj_import_file_reader.hh"
 
+#include <algorithm>
+
 namespace blender::io::obj {
 
 using std::string;
@@ -322,6 +324,23 @@ static bool parse_keyword(StringRef &line, StringRef keyword)
   return true;
 }
 
+/* Special case: if there were no faces/edges in any geometries,
+ * treat all the vertices as a point cloud. */
+static void use_all_vertices_if_no_faces(Geometry *geom,
+                                         const Vector<std::unique_ptr<Geometry>> &all_geometries,
+                                         const GlobalVertices &global_vertices)
+{
+  if (!global_vertices.vertices.is_empty() && geom && geom->geom_type_ == GEOM_MESH) {
+    if (std::all_of(
+            all_geometries.begin(), all_geometries.end(), [](const std::unique_ptr<Geometry> &g) {
+              return g->get_vertex_count() == 0;
+            })) {
+      geom->track_vertex_index(0);
+      geom->track_vertex_index(global_vertices.vertices.size() - 1);
+    }
+  }
+}
+
 void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
                       GlobalVertices &r_global_vertices)
 {
@@ -493,6 +512,7 @@ void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
     buffer_offset = left_size;
   }
 
+  use_all_vertices_if_no_faces(curr_geom, r_all_geometries, r_global_vertices);
   add_default_mtl_library();
 }
 
diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
index 4c7e06e5a00..5d425d91fe6 100644
--- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
@@ -522,4 +522,14 @@ TEST_F(obj_importer_test, import_all_objects)
   import_and_check("all_objects.obj", expect, std::size(expect), 7);
 }
 
+TEST_F(obj_importer_test, import_vertices)
+{
+  Expectation expect[] = {
+      {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)},
+      /* Loose vertices without faces or edges. */
+      {"OBCube.001", OB_MESH, 8, 0, 0, 0, float3(1, 1, -1), float3(-1, 1, 1)},
+  };
+  import_and_check("vertices.obj", expect, std::size(expect), 0);
+}
+
 }  // namespace blender::io::obj



More information about the Bf-blender-cvs mailing list