[Bf-blender-cvs] [be046b01d15] soc-2020-io-performance: Remove export_params_ from OBJNurbs.

Ankit Meel noreply at git.blender.org
Tue Sep 1 10:39:16 CEST 2020


Commit: be046b01d1560efeaeb9e92b4e672726f0f093ff
Author: Ankit Meel
Date:   Tue Sep 1 04:39:45 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBbe046b01d1560efeaeb9e92b4e672726f0f093ff

Remove export_params_ from OBJNurbs.

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

M	source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
M	source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
M	source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc
M	source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh

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

diff --git a/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc b/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
index 87a903012bb..2c29f98f333 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
@@ -188,7 +188,7 @@ void OBJWriter::write_uv_coords(OBJMesh &obj_mesh_data, Vector<Vector<uint>> &uv
 }
 
 /**
- * Write all face normals or all vertex normals as vn x y z .
+ * Write vertex normals for smooth-shaded polygons, and face normals otherwise, as vn x y z .
  */
 void OBJWriter::write_poly_normals(OBJMesh &obj_mesh_data) const
 {
@@ -330,15 +330,15 @@ void OBJWriter::write_poly_elements(const OBJMesh &obj_mesh_data, Span<Vector<ui
   /* Reset for every object. */
   tot_normals_ = 0;
   for (uint i = 0; i < obj_mesh_data.tot_polygons(); i++) {
-    obj_mesh_data.calc_poly_vertex_indices(i, vertex_indices);
-
     const int totloop = obj_mesh_data.ith_poly_totloop(i);
     normal_indices.resize(totloop);
+    vertex_indices.resize(totloop);
+    obj_mesh_data.calc_poly_vertex_indices(i, vertex_indices);
 
     if (obj_mesh_data.is_ith_poly_smooth(i)) {
       for (int j = 0; j < totloop; j++) {
         /* This is guaranteed because normals are written
-         * by going over mloops in the same order. */
+         * by going over `MLoop`s in the same order. */
         normal_indices[j] = tot_normals_ + j + 1;
       }
       tot_normals_ += totloop;
@@ -385,14 +385,15 @@ void OBJWriter::write_nurbs_curve(const OBJNurbs &obj_nurbs_data) const
     /* Total control points in a nurbs. */
     int tot_points = nurb->pntsv * nurb->pntsu;
     for (int point_idx = 0; point_idx < tot_points; point_idx++) {
-      float3 point_coord = obj_nurbs_data.calc_point_coords(nurb, point_idx);
+      float3 point_coord = obj_nurbs_data.calc_point_coords(
+          *nurb, point_idx, export_params_.scaling_factor);
       fprintf(outfile_, "v %f %f %f\n", point_coord[0], point_coord[1], point_coord[2]);
     }
 
     const char *nurbs_name = obj_nurbs_data.get_curve_name();
-    int nurbs_degree = obj_nurbs_data.get_curve_degree(nurb);
+    int nurbs_degree = obj_nurbs_data.get_curve_degree(*nurb);
     /* Number of vertices in the curve + degree of the curve if it is cyclic. */
-    int curv_num = obj_nurbs_data.get_curve_num(nurb);
+    int curv_num = obj_nurbs_data.get_curve_num(*nurb);
 
     fprintf(outfile_, "g %s\ncstype bspline\ndeg %d\n", nurbs_name, nurbs_degree);
     /**
@@ -428,6 +429,7 @@ void OBJWriter::update_index_offsets(const OBJMesh &obj_mesh_data)
   index_offset_[VERTEX_OFF] += obj_mesh_data.tot_vertices();
   index_offset_[UV_VERTEX_OFF] += obj_mesh_data.tot_uv_vertices();
   index_offset_[NORMAL_OFF] = tot_normals_;
+  tot_normals_ = 0;
 }
 
 /**
@@ -447,9 +449,7 @@ MTLWriter::MTLWriter(const char *obj_filepath)
 
 MTLWriter::~MTLWriter()
 {
-  if (mtl_outfile_) {
-    fclose(mtl_outfile_);
-  }
+  fclose(mtl_outfile_);
 }
 
 void MTLWriter::append_materials(const OBJMesh &mesh_to_export)
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc b/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
index 17411efcdd1..41faeff75e6 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
@@ -294,7 +294,6 @@ void OBJMesh::calc_poly_vertex_indices(const uint poly_index,
 {
   const MPoly &mpoly = export_mesh_eval_->mpoly[poly_index];
   const MLoop *mloop = &export_mesh_eval_->mloop[mpoly.loopstart];
-  r_poly_vertex_indices.resize(mpoly.totloop);
   for (uint loop_index = 0; loop_index < mpoly.totloop; loop_index++) {
     r_poly_vertex_indices[loop_index] = mloop[loop_index].v + 1;
   }
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc b/source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc
index 37cb5494e31..3c70ddfdf54 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc
@@ -37,26 +37,24 @@ namespace blender::io::obj {
 OBJNurbs::OBJNurbs(Depsgraph *depsgraph,
                    const OBJExportParams &export_params,
                    Object *export_object)
-    : depsgraph_(depsgraph), export_params_(export_params), export_object_eval_(export_object)
+    : depsgraph_(depsgraph), export_object_eval_(export_object)
 {
   export_object_eval_ = DEG_get_evaluated_object(depsgraph_, export_object);
   export_curve_ = static_cast<Curve *>(export_object_eval_->data);
-  store_world_axes_transform();
+  store_world_axes_transform(export_params.forward_axis, export_params.up_axis);
 }
 
 /**
  * Store the product of export axes settings and an object's world transform matrix.
  */
-void OBJNurbs::store_world_axes_transform()
+void OBJNurbs::store_world_axes_transform(const eTransformAxisForward forward,
+                                          const eTransformAxisUp up)
 {
   float axes_transform[3][3];
   unit_m3(axes_transform);
   /* -Y-forward and +Z-up are the default Blender axis settings. */
-  mat3_from_axis_conversion(OBJ_AXIS_NEGATIVE_Y_FORWARD,
-                            OBJ_AXIS_Z_UP,
-                            export_params_.forward_axis,
-                            export_params_.up_axis,
-                            axes_transform);
+  mat3_from_axis_conversion(
+      OBJ_AXIS_NEGATIVE_Y_FORWARD, OBJ_AXIS_Z_UP, forward, up, axes_transform);
   mul_m4_m3m4(world_axes_transform_, axes_transform, export_object_eval_->obmat);
   /* mul_m4_m3m4 does not copy last row of obmat, i.e. location data. */
   copy_v4_v4(world_axes_transform_[3], export_object_eval_->obmat[3]);
@@ -75,27 +73,29 @@ const ListBase *OBJNurbs::curve_nurbs() const
 /**
  * Get coordinates of a vertex at given point index.
  */
-float3 OBJNurbs::calc_point_coords(const Nurb *nurb, const int vert_index) const
+float3 OBJNurbs::calc_point_coords(const Nurb &nurb,
+                                   const int vert_index,
+                                   const float scaling_factor) const
 {
   float3 r_coord;
-  BPoint *bpoint = nurb->bp;
+  BPoint *bpoint = nurb.bp;
   bpoint += vert_index;
   copy_v3_v3(r_coord, bpoint->vec);
   mul_m4_v3(world_axes_transform_, r_coord);
-  mul_v3_fl(r_coord, export_params_.scaling_factor);
+  mul_v3_fl(r_coord, scaling_factor);
   return r_coord;
 }
 
 /**
  * Get number of "curv" points of a nurb.
  */
-int OBJNurbs::get_curve_num(const Nurb *nurb) const
+int OBJNurbs::get_curve_num(const Nurb &nurb) const
 {
-  const int r_nurbs_degree = nurb->orderu - 1;
+  const int r_nurbs_degree = nurb.orderu - 1;
   /* "curv_num" is the number of control points in a nurbs.
    * If it is cyclic, degree also adds up. */
-  int r_curv_num = nurb->pntsv * nurb->pntsu;
-  if (nurb->flagu & CU_NURB_CYCLIC) {
+  int r_curv_num = nurb.pntsv * nurb.pntsu;
+  if (nurb.flagu & CU_NURB_CYCLIC) {
     r_curv_num += r_nurbs_degree;
   }
   return r_curv_num;
@@ -104,9 +104,9 @@ int OBJNurbs::get_curve_num(const Nurb *nurb) const
 /**
  * Get Nurb's degree.
  */
-int OBJNurbs::get_curve_degree(const Nurb *nurb) const
+int OBJNurbs::get_curve_degree(const Nurb &nurb) const
 {
-  return nurb->orderu - 1;
+  return nurb.orderu - 1;
 }
 
 }  // namespace blender::io::obj
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh b/source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh
index 85842c70214..5ae8f14990a 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh
+++ b/source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh
@@ -31,7 +31,6 @@ namespace blender::io::obj {
 class OBJNurbs : NonMovable, NonCopyable {
  private:
   const Depsgraph *depsgraph_;
-  const OBJExportParams &export_params_;
   const Object *export_object_eval_;
   const Curve *export_curve_;
   float world_axes_transform_[4][4];
@@ -41,12 +40,14 @@ class OBJNurbs : NonMovable, NonCopyable {
 
   const char *get_curve_name() const;
   const ListBase *curve_nurbs() const;
-  float3 calc_point_coords(const Nurb *nurb, int vert_index) const;
-  int get_curve_num(const Nurb *nurb) const;
-  int get_curve_degree(const Nurb *nurb) const;
+  float3 calc_point_coords(const Nurb &nurb,
+                           const int vert_index,
+                           const float scaling_factor) const;
+  int get_curve_num(const Nurb &nurb) const;
+  int get_curve_degree(const Nurb &nurb) const;
 
  private:
-  void store_world_axes_transform();
+  void store_world_axes_transform(const eTransformAxisForward forward, const eTransformAxisUp up);
 };
 
 }  // namespace blender::io::obj



More information about the Bf-blender-cvs mailing list