[Bf-blender-cvs] [2bb56c83faa] soc-2020-io-performance: Move Object creation code in Mesh creation class.

Ankit Meel noreply at git.blender.org
Thu Jul 23 18:05:22 CEST 2020


Commit: 2bb56c83faac15af82a14e9f1ffc4f489022dfda
Author: Ankit Meel
Date:   Thu Jul 23 21:35:16 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB2bb56c83faac15af82a14e9f1ffc4f489022dfda

Move Object creation code in Mesh creation class.

This is required for setting deform groups which are a part of `Object` struct.

Also rename NurbsElem > OBJNurbsElem.

Remove forward declarations from *nurbs.hh & *mesh.hh files
since the cyclic dependency with *object.hh is removed.

Remove auto.

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

M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
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_nurbs.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_nurbs.hh
M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc
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/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 ecac65176c1..7d7fa44ee24 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
@@ -265,7 +265,7 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
 
       Vector<string> str_corners_split;
       split_by_char(s_line.str(), ' ', str_corners_split);
-      for (auto &str_corner : str_corners_split) {
+      for (const string &str_corner : str_corners_split) {
         OBJFaceCorner corner;
         size_t n_slash = std::count(str_corner.begin(), str_corner.end(), '/');
         if (n_slash == 0) {
@@ -332,7 +332,7 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
       str_curv_split.remove(0);
       (*curr_ob)->nurbs_element_.curv_indices.resize(str_curv_split.size());
       copy_string_to_int(str_curv_split, (*curr_ob)->nurbs_element_.curv_indices);
-      for (auto &curv_point : (*curr_ob)->nurbs_element_.curv_indices) {
+      for (const int &curv_point : (*curr_ob)->nurbs_element_.curv_indices) {
         curv_point -= curv_point > 0 ? 1 : -(global_vertices.vertices.size());
       }
     }
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 730e9e1d49c..41a07188488 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
@@ -34,24 +34,38 @@
 
 namespace blender::io::obj {
 /**
- * Make a Blender Mesh block from a raw object of OB_MESH type.
+ * Make a Blender Mesh Object from a raw object of OB_MESH type.
  * Use the mover function to own the mesh.
  */
-OBJMeshFromRaw::OBJMeshFromRaw(const OBJRawObject &curr_object,
+OBJMeshFromRaw::OBJMeshFromRaw(Main *bmain,
+                               const OBJRawObject &curr_object,
                                const GlobalVertices global_vertices)
 {
+  std::string ob_name = curr_object.object_name();
+  if (ob_name.empty()) {
+    ob_name = "Untitled";
+  }
   const int64_t tot_verts_object{curr_object.tot_verts()};
   const int64_t tot_edges{curr_object.tot_edges()};
   const int64_t tot_face_elems{curr_object.tot_face_elems()};
-  mesh_from_ob_.reset(BKE_mesh_new_nomain(
+
+  mesh_from_raw_.reset(BKE_mesh_new_nomain(
       tot_verts_object, tot_edges, 0, curr_object.tot_loops(), tot_face_elems));
+  mesh_object_.reset(BKE_object_add_only_object(bmain, OB_MESH, ob_name.c_str()));
+  mesh_object_->data = BKE_object_obdata_add_from_type(bmain, OB_MESH, ob_name.c_str());
 
   create_vertices(curr_object, global_vertices, tot_verts_object);
-  create_loops(curr_object, tot_face_elems);
+  create_polys_loops(curr_object, tot_face_elems);
   create_edges(curr_object, tot_edges);
   create_uv_verts(curr_object, global_vertices);
 
-  BKE_mesh_validate(mesh_from_ob_.get(), false, true);
+  BKE_mesh_validate(mesh_from_raw_.get(), false, true);
+
+  BKE_mesh_nomain_to_mesh(mesh_from_raw_.release(),
+                          (Mesh *)mesh_object_->data,
+                          mesh_object_.get(),
+                          &CD_MASK_EVERYTHING,
+                          true);
 }
 
 void OBJMeshFromRaw::create_vertices(const OBJRawObject &curr_object,
@@ -59,18 +73,18 @@ void OBJMeshFromRaw::create_vertices(const OBJRawObject &curr_object,
                                      int64_t tot_verts_object)
 {
   for (int i = 0; i < tot_verts_object; ++i) {
-    /* Current object's vertex indices index into global list of vertex coordinates. */
-    copy_v3_v3(mesh_from_ob_->mvert[i].co,
+    /* Current object's vertex indices index into the global list of vertex coordinates. */
+    copy_v3_v3(mesh_from_raw_->mvert[i].co,
                global_vertices.vertices[curr_object.vertex_indices()[i]]);
   }
 }
 
-void OBJMeshFromRaw::create_loops(const OBJRawObject &curr_object, int64_t tot_face_elems)
+void OBJMeshFromRaw::create_polys_loops(const OBJRawObject &curr_object, int64_t tot_face_elems)
 {
   int tot_loop_idx = 0;
   for (int poly_idx = 0; poly_idx < tot_face_elems; ++poly_idx) {
     const OBJFaceElem &curr_face = curr_object.face_elements()[poly_idx];
-    MPoly &mpoly = mesh_from_ob_->mpoly[poly_idx];
+    MPoly &mpoly = mesh_from_raw_->mpoly[poly_idx];
     mpoly.totloop = curr_face.face_corners.size();
     mpoly.loopstart = tot_loop_idx;
     if (curr_face.shaded_smooth) {
@@ -78,7 +92,7 @@ void OBJMeshFromRaw::create_loops(const OBJRawObject &curr_object, int64_t tot_f
     }
 
     for (int loop_of_poly_idx = 0; loop_of_poly_idx < mpoly.totloop; ++loop_of_poly_idx) {
-      MLoop *mloop = &mesh_from_ob_->mloop[tot_loop_idx];
+      MLoop *mloop = &mesh_from_raw_->mloop[tot_loop_idx];
       tot_loop_idx++;
       mloop->v = curr_face.face_corners[loop_of_poly_idx].vert_index;
     }
@@ -88,15 +102,15 @@ void OBJMeshFromRaw::create_loops(const OBJRawObject &curr_object, int64_t tot_f
 void OBJMeshFromRaw::create_edges(const OBJRawObject &curr_object, int64_t tot_edges)
 {
   for (int i = 0; i < tot_edges; ++i) {
-    const auto &curr_edge = curr_object.edges()[i];
-    mesh_from_ob_->medge[i].v1 = curr_edge.v1;
-    mesh_from_ob_->medge[i].v2 = curr_edge.v2;
+    const MEdge &curr_edge = curr_object.edges()[i];
+    mesh_from_raw_->medge[i].v1 = curr_edge.v1;
+    mesh_from_raw_->medge[i].v2 = curr_edge.v2;
   }
 
   /* Set argument `update` to true so that existing explicitly imported edges can be merged
    * with the new ones created from polygons. */
-  BKE_mesh_calc_edges(mesh_from_ob_.get(), true, false);
-  BKE_mesh_calc_edges_loose(mesh_from_ob_.get());
+  BKE_mesh_calc_edges(mesh_from_raw_.get(), true, false);
+  BKE_mesh_calc_edges_loose(mesh_from_raw_.get());
 }
 
 void OBJMeshFromRaw::create_uv_verts(const OBJRawObject &curr_object,
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.hh
index 164179adc07..35535b42c26 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.hh
@@ -32,9 +32,9 @@
 
 #include "bmesh.h"
 
+#include "wavefront_obj_im_objects.hh"
+
 namespace blender::io::obj {
-class OBJRawObject;
-struct GlobalVertices;
 /**
  * An custom unique_ptr deleter for a Mesh object.
  */
@@ -52,21 +52,30 @@ using unique_mesh_ptr = std::unique_ptr<Mesh, UniqueMeshDeleter>;
 
 class OBJMeshFromRaw : NonMovable, NonCopyable {
  private:
-  unique_mesh_ptr mesh_from_ob_;
+  /**
+   * Mesh datablock made from OBJ data.
+   */
+  unique_mesh_ptr mesh_from_raw_;
+  /**
+   * An Object of type OB_MESH. Use the mover function to own it.
+   */
+  unique_object_ptr mesh_object_;
 
  public:
-  OBJMeshFromRaw(const OBJRawObject &curr_object, const GlobalVertices global_vertices);
+  OBJMeshFromRaw(Main *bmain,
+                 const OBJRawObject &curr_object,
+                 const GlobalVertices global_vertices);
 
-  unique_mesh_ptr mover()
+  unique_object_ptr mover()
   {
-    return std::move(mesh_from_ob_);
+    return std::move(mesh_object_);
   }
 
  private:
   void create_vertices(const OBJRawObject &curr_object,
                        const GlobalVertices &global_vertices,
                        int64_t tot_verts_object);
-  void create_loops(const OBJRawObject &curr_object, int64_t tot_face_elems);
+  void create_polys_loops(const OBJRawObject &curr_object, int64_t tot_face_elems);
   void create_edges(const OBJRawObject &curr_object, int64_t tot_edges);
   void create_uv_verts(const OBJRawObject &curr_object, const GlobalVertices &global_vertices);
 };
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_nurbs.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_nurbs.cc
index 773edd1faa2..3423f7c793d 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_nurbs.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_nurbs.cc
@@ -34,8 +34,8 @@ void OBJCurveFromRaw::create_nurbs(const OBJRawObject &curr_object,
                                    const GlobalVertices &global_vertices)
 {
   const int64_t tot_vert{curr_object.nurbs_elem().curv_indices.size()};
-  const NurbsElem &raw_nurbs = curr_object.nurbs_elem();
-  Nurb *nurb = (Nurb *)curve_from_ob_->nurb.first;
+  const OBJNurbsElem &raw_nurbs = curr_object.nurbs_elem();
+  Nurb *nurb = (Nurb *)curve_from_raw_->nurb.first;
 
   nurb->type = CU_NURBS;
   nurb->next = nurb->prev = nullptr;
@@ -86,17 +86,25 @@ OBJCurveFromRaw::OBJCurveFromRaw(Main *bmain,
                                  const OBJRawObject &curr_object,
                                  const GlobalVertices global_vertices)
 {
-  /* Set curve specific settings. */
-  curve_from_ob_.reset(BKE_curve_add(bmain, curr_object.object_name().c_str(), OB_CURVE));
-  curve_from_ob_->flag = CU_3D;
-  curve_from_ob_->resolu = curve_from_ob_->resolv = 12;
+  std::string ob_name = curr_object.object_name();
+  if (ob_name.empty() && !curr_object.group().empty()) {
+    ob_name = curr_object.group();
+  }
+  else {
+    ob_name = "Untitled";
+  }
+  curve_from_raw_.reset(BKE_curve_add(bmain, curr_object.object_name().c_str(), OB_CURVE));
+  curve_object_.reset(BKE_object_add_only_object(bmain, OB_CURVE, ob_name.c_str()));
+
+  curve_from_raw_->flag = CU_3D;
+  curve_from_raw_->resolu = curve_from_raw_->resolv = 12;
   /* Only one NURBS exists. */
-  curve_from_ob_->actnu = 0;
+  curve_from_raw_->actnu = 0;
 
   Nurb *nurb = (Nurb *)MEM_callocN(sizeof(Nurb), "OBJ import NURBS curve");
-  BLI_addtail(BKE_curve_nurbs_get(curve_from_ob_.get()), nurb);
-
-  /* Set NURBS specific settings. */
+  BLI_addtail(BKE_curve_nurbs_get(curve_from_raw_.get()), nurb);
   create_nurbs(curr_object, global_vertices);
+
+  curve_object_->data = curve_from_raw_.release();
 }
 }  // namespace blender::io::obj
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_nurbs.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_nurbs.h

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list