Commit: 0aeb338d1952725cfb8153e0f03653086e37e413
Author: Ankit Meel
Date:   Fri Aug 28 16:52:33 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB0aeb338d1952725cfb8153e0f03653086e37e413

Use unique_ptr for MTLMaterials Map.

Also, early return in `tessellate_polygons`. Turn off tessellation
for a while till valid/invalid options are added in parsing.

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

M       release/scripts/addons
M       source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
M       source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.hh
M       source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
M       source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.hh
M       source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.hh
M       source/blender/io/wavefront_obj/intern/wavefront_obj_importer.cc

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

diff --git a/release/scripts/addons b/release/scripts/addons
index 82ed41ec632..8dfa2220aae 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 82ed41ec632483fa9260d90dae7afdf3192c509b
+Subproject commit 8dfa2220aae1d44f14100b18dcccf3c54f6c9e4a
diff --git 
a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc 
b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
index eac242299c3..468573b274d 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
@@ -37,6 +37,7 @@ using std::string;
 
 /**
  * Store multiple lines separated by an escaped newline character: `\\n`.
+ * Use this before doing any parse operations on the read string.
  */
 static void read_next_line(std::ifstream &file, string &r_line)
 {
@@ -282,8 +283,7 @@ void 
OBJParser::parse_and_store(Vector<std::unique_ptr<Geometry>> &r_all_geometr
   string line;
   /* Store vertex coordinates that belong to other Geometry instances.  */
   VertexIndexOffset offset;
-  /* Non owning raw pointer to a Geometry.
-   * Needed to update object data in the same while loop. */
+  /* Non owning raw pointer to a Geometry. To be updated while creating a new 
Geometry. */
   Geometry *current_geometry = create_geometry(
       nullptr, GEOM_MESH, "", r_global_vertices, r_all_geometries, offset);
 
@@ -502,7 +502,7 @@ static StringRef skip_unsupported_options(StringRef line)
   /* Remove upto start of the last option + size of the last option + space 
after it. */
   line = line.drop_prefix(last_option_pos + last_option.size() + 1);
   for (int i = 0; i < map_options.number_of_args(last_option); i++) {
-    int64_t pos_space{line.find_first_of(' ')};
+    const int64_t pos_space{line.find_first_of(' ')};
     if (pos_space != StringRef::not_found) {
       BLI_assert(pos_space + 1 < line.size());
       line = line.drop_prefix(pos_space + 1);
@@ -538,7 +538,7 @@ MTLParser::MTLParser(StringRef mtl_library, StringRefNull 
obj_filepath)
 /**
  * Read MTL file(s) and add MTLMaterial instances to the given Map reference.
  */
-void MTLParser::parse_and_store(Map<string, MTLMaterial> &r_mtl_materials)
+void MTLParser::parse_and_store(Map<string, std::unique_ptr<MTLMaterial>> 
&r_mtl_materials)
 {
   if (!mtl_file_.good()) {
     return;
@@ -556,9 +556,11 @@ void MTLParser::parse_and_store(Map<string, MTLMaterial> 
&r_mtl_materials)
 
     if (line_key == "newmtl") {
       if (r_mtl_materials.remove_as(rest_line)) {
-        std::cerr << "Duplicate material found:'" << rest_line << "'." << 
std::endl;
+        std::cerr << "Duplicate material found:'" << rest_line
+                  << "', using the last encountered Material definition." << 
std::endl;
       }
-      current_mtlmaterial = 
&r_mtl_materials.lookup_or_add_default_as(string(rest_line));
+      current_mtlmaterial =
+          r_mtl_materials.lookup_or_add(string(rest_line), 
std::make_unique<MTLMaterial>()).get();
     }
     else if (line_key == "Ns") {
       copy_string_to_float(rest_line, 324.0f, current_mtlmaterial->Ns);
diff --git 
a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.hh 
b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.hh
index 206c227acc6..21faf1830da 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.hh
@@ -96,6 +96,6 @@ class MTLParser {
  public:
   MTLParser(StringRef mtl_library_, StringRefNull obj_filepath);
 
-  void parse_and_store(Map<std::string, MTLMaterial> &r_mtl_materials);
+  void parse_and_store(Map<std::string, std::unique_ptr<MTLMaterial>> 
&r_mtl_materials);
 };
 }  // namespace blender::io::obj
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc 
b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
index eb111208b58..6867cc302f2 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
@@ -57,7 +57,8 @@ MeshFromGeometry::~MeshFromGeometry()
   }
 }
 
-void MeshFromGeometry::create_mesh(Main *bmain, const Map<std::string, 
MTLMaterial> &materials)
+void MeshFromGeometry::create_mesh(Main *bmain,
+                                   const Map<std::string, 
std::unique_ptr<MTLMaterial>> &materials)
 {
   std::string ob_name{mesh_geometry_.get_geometry_name()};
   if (ob_name.empty()) {
@@ -113,52 +114,53 @@ std::pair<int64_t, int64_t> 
MeshFromGeometry::tessellate_polygons(
   int64_t removed_faces = 0;
   int64_t removed_loops = 0;
   for (const FaceElement &curr_face : mesh_geometry_.face_elements()) {
-    if (curr_face.shaded_smooth || true) {  // should be valid/invalid
-      Vector<int> face_vert_indices;
-      Vector<int> face_uv_indices;
-      Vector<int> face_normal_indices;
-      face_vert_indices.reserve(curr_face.face_corners.size());
-      face_uv_indices.reserve(curr_face.face_corners.size());
-      face_normal_indices.reserve(curr_face.face_corners.size());
-      for (const FaceCorner &corner : curr_face.face_corners) {
-        face_vert_indices.append(corner.vert_index);
-        face_normal_indices.append(corner.vertex_normal_index);
-        face_uv_indices.append(corner.uv_vert_index);
-        removed_loops++;
-      }
+    if (curr_face.shaded_smooth && true) {  // should be valid/invalid
+      return {removed_faces, removed_loops};
+    }
+    Vector<int> face_vert_indices;
+    Vector<int> face_uv_indices;
+    Vector<int> face_normal_indices;
+    face_vert_indices.reserve(curr_face.face_corners.size());
+    face_uv_indices.reserve(curr_face.face_corners.size());
+    face_normal_indices.reserve(curr_face.face_corners.size());
+    for (const FaceCorner &corner : curr_face.face_corners) {
+      face_vert_indices.append(corner.vert_index);
+      face_normal_indices.append(corner.vertex_normal_index);
+      face_uv_indices.append(corner.uv_vert_index);
+      removed_loops++;
+    }
 
-      Vector<Vector<int>> new_polygon_indices = 
ngon_tessellate(global_vertices_.vertices,
-                                                                
face_vert_indices);
+    Vector<Vector<int>> new_polygon_indices = 
ngon_tessellate(global_vertices_.vertices,
+                                                              
face_vert_indices);
+    for (Span<int> triangle : new_polygon_indices) {
+      r_new_faces.append({curr_face.vertex_group,
+                          curr_face.shaded_smooth,
+                          {{face_vert_indices[triangle[0]],
+                            face_uv_indices[triangle[0]],
+                            face_normal_indices[triangle[0]]},
+                           {face_vert_indices[triangle[1]],
+                            face_uv_indices[triangle[1]],
+                            face_normal_indices[triangle[1]]},
+                           {face_vert_indices[triangle[2]],
+                            face_uv_indices[triangle[2]],
+                            face_normal_indices[triangle[2]]}}});
+    }
+    if (new_polygon_indices.size() > 1) {
+      Set<std::pair<int, int>> edge_users;
       for (Span<int> triangle : new_polygon_indices) {
-        r_new_faces.append({curr_face.vertex_group,
-                            curr_face.shaded_smooth,
-                            {{face_vert_indices[triangle[0]],
-                              face_uv_indices[triangle[0]],
-                              face_normal_indices[triangle[0]]},
-                             {face_vert_indices[triangle[1]],
-                              face_uv_indices[triangle[1]],
-                              face_normal_indices[triangle[1]]},
-                             {face_vert_indices[triangle[2]],
-                              face_uv_indices[triangle[2]],
-                              face_normal_indices[triangle[2]]}}});
-      }
-      if (new_polygon_indices.size() > 1) {
-        Set<std::pair<int, int>> edge_users;
-        for (Span<int> triangle : new_polygon_indices) {
-          int prev_vidx = face_vert_indices[triangle.last()];
-          for (const int ngidx : triangle) {
-            int vidx = face_vert_indices[ngidx];
-            if (vidx == prev_vidx) {
-              continue;
-            }
-            std::pair<int, int> edge_key = {min_ii(prev_vidx, vidx), 
max_ii(prev_vidx, vidx)};
-            prev_vidx = vidx;
-            if (edge_users.contains(edge_key)) {
-              fgon_edges.add(edge_key);
-            }
-            else {
-              edge_users.add(edge_key);
-            }
+        int prev_vidx = face_vert_indices[triangle.last()];
+        for (const int ngidx : triangle) {
+          int vidx = face_vert_indices[ngidx];
+          if (vidx == prev_vidx) {
+            continue;
+          }
+          std::pair<int, int> edge_key = {min_ii(prev_vidx, vidx), 
max_ii(prev_vidx, vidx)};
+          prev_vidx = vidx;
+          if (edge_users.contains(edge_key)) {
+            fgon_edges.add(edge_key);
+          }
+          else {
+            edge_users.add(edge_key);
           }
         }
       }
@@ -166,7 +168,7 @@ std::pair<int64_t, int64_t> 
MeshFromGeometry::tessellate_polygons(
     removed_faces++;
   }
 
-  return std::make_pair(removed_faces, removed_loops);
+  return {removed_faces, removed_loops};
 }
 
 void MeshFromGeometry::dissolve_edges(const Set<std::pair<int, int>> 
&fgon_edges)
@@ -353,8 +355,8 @@ void MeshFromGeometry::create_uv_verts()
 /**
  * Add materials and the nodetree to the Mesh Object.
  */
-void MeshFromGeometry::create_materials(Main *bmain,
-                                        const Map<std::string, MTLMaterial> 
&materials)
+void MeshFromGeometry::create_materials(
+    Main *bmain, const Map<std::string, std::unique_ptr<MTLMaterial>> 
&materials)
 {
   for (StringRef material_name : mesh_geometry_.material_names()) {
     if (!materials.contains_as(material_name)) {
@@ -362,7 +364,7 @@ void MeshFromGeometry::create_materials(Main *bmain,
                 << std::endl;
       continue;
     }
-    const MTLMaterial &curr_mat = materials.lookup_a

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to