[Bf-blender-cvs] [6c98925d5ad] soc-2020-io-performance: Refactor: create separate files for mesh & nurbs.

Ankit Meel noreply at git.blender.org
Fri Jun 26 10:38:56 CEST 2020


Commit: 6c98925d5ad82238c8cd28d20f3369aff0ed8919
Author: Ankit Meel
Date:   Thu Jun 25 21:33:56 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB6c98925d5ad82238c8cd28d20f3369aff0ed8919

Refactor: create separate files for mesh & nurbs.

`*exporter_nurbs.{cc/hh}` have been added for OBJNurbs.
`*exporter_mesh.{cc/hh}` have been added for OBJMesh.

Header file cleanup in other files.

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

M	source/blender/io/wavefront_obj/CMakeLists.txt
M	source/blender/io/wavefront_obj/intern/wavefront_obj.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj.hh
M	source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.hh
A	source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.cc
A	source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.hh
A	source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_nurbs.cc
A	source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_nurbs.hh
M	source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.hh

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

diff --git a/source/blender/io/wavefront_obj/CMakeLists.txt b/source/blender/io/wavefront_obj/CMakeLists.txt
index 87b954df0b5..1774cadc140 100644
--- a/source/blender/io/wavefront_obj/CMakeLists.txt
+++ b/source/blender/io/wavefront_obj/CMakeLists.txt
@@ -42,12 +42,16 @@ set(INC_SYS
 set(SRC
   intern/wavefront_obj.cc
   intern/wavefront_obj_exporter.cc
+  intern/wavefront_obj_exporter_mesh.cc
+  intern/wavefront_obj_exporter_nurbs.cc
   intern/wavefront_obj_file_handler.cc
   intern/wavefront_obj_importer.cc
 
   IO_wavefront_obj.h
   intern/wavefront_obj.hh
   intern/wavefront_obj_exporter.hh
+  intern/wavefront_obj_exporter_mesh.hh
+  intern/wavefront_obj_exporter_nurbs.hh
   intern/wavefront_obj_file_handler.hh
   intern/wavefront_obj_importer.hh
 )
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj.cc
index 6513efb3ade..5e147e9aa98 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj.cc
@@ -21,9 +21,12 @@
  * \ingroup obj
  */
 
-#include "IO_wavefront_obj.h"
+#include <iostream>
+
 #include "PIL_time.h"
 
+#include "IO_wavefront_obj.h"
+
 #include "wavefront_obj.hh"
 #include "wavefront_obj_exporter.hh"
 
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj.hh
index 799653e435c..2d045438fb9 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj.hh
@@ -21,167 +21,20 @@
 #ifndef __WAVEFRONT_OBJ_HH__
 #define __WAVEFRONT_OBJ_HH__
 
-#include "BKE_context.h"
-#include "BKE_curve.h"
-#include "BKE_lib_id.h"
-#include "BKE_mesh.h"
-#include "BKE_object.h"
-
-#include "BLI_vector.hh"
-
-#include "DNA_curve_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_object_types.h"
-
 #include "IO_wavefront_obj.h"
 
 namespace io {
 namespace obj {
 
-/* -Y */
-#define DEFAULT_AXIS_FORWARD 4
-/* Z */
-#define DEFAULT_AXIS_UP 2
-
-class OBJMesh {
- public:
-  OBJMesh(bContext *C, const OBJExportParams *export_params, Object *export_object)
-      : _C(C), _export_params(export_params), _export_object_eval(export_object)
-  {
-    init_export_mesh(export_object);
-  }
-
-  /** Free new meshes we allocate for triangulated meshes, and curves converted to meshes. */
-  void destruct()
-  {
-    if (_me_eval_needs_free) {
-      BKE_id_free(NULL, _export_mesh_eval);
-    }
-  }
-
-  uint tot_vertices()
-  {
-    return _tot_vertices;
-  }
-
-  uint tot_poly_normals()
-  {
-    return _tot_poly_normals;
-  }
-
-  uint tot_uv_vertices()
-  {
-    return _tot_uv_vertices;
-  }
-
-  uint tot_edges()
-  {
-    return _tot_edges;
-  }
-
-  Mesh *export_mesh_eval()
-  {
-    return _export_mesh_eval;
-  }
-
-  const MPoly &get_ith_poly(uint i)
-  {
-    return _export_mesh_eval->mpoly[i];
-  }
-
-  void get_object_name(const char **object_name);
-  /**
-   * Calculate coordinates of the vertex at given index.
-   */
-  void calc_vertex_coords(float coords[3], uint vert_index);
-  /**
-   * Calculate vertex indices of all vertices of a polygon.
-   */
-  void calc_poly_vertex_indices(blender::Vector<uint> &poly_vertex_indices, uint poly_index);
-  /**
-   * Store UV vertex coordinates as well as their indices.
-   */
-  void store_uv_coords_and_indices(blender::Vector<std::array<float, 2>> &uv_coords,
-                                   blender::Vector<blender::Vector<uint>> &uv_indices);
-  /**
-   * Calculate face normal of the polygon at given index.
-   */
-  void calc_poly_normal(float poly_normal[3], uint poly_index);
-  /**
-   * Calculate face normal indices of all polygons.
-   */
-  void calc_poly_normal_indices(blender::Vector<uint> &normal_indices, uint poly_indices);
-  /**
-   * Only for curve converted to meshes: calculate vertex indices of one edge.
-   */
-  void calc_edge_vert_indices(uint vert_indices[2], uint edge_index);
-
- private:
-  bContext *_C;
-  const OBJExportParams *_export_params;
-
-  Object *_export_object_eval;
-  Mesh *_export_mesh_eval;
-  /**
-   * Store evaluated object and mesh pointers depending on object type.
-   * New meshes are created for curves converted to meshes and triangulated meshes.
-   */
-  void init_export_mesh(Object *export_object);
-  /**
-   * Triangulate given mesh and update _export_mesh_eval.
-   * \note The new mesh created here needs to be freed.
-   */
-  void triangulate_mesh(Mesh *me_eval);
-  /**
-   * For curves which are converted to mesh, and triangulated meshes, a new mesh is allocated
-   * which needs to be freed later.
-   */
-  bool _me_eval_needs_free = false;
-
-  /**
-   * Store the product of export axes settings and an object's world transform matrix in
-   * world_and_axes_transform[4][4].
-   */
-  void store_world_axes_transform();
-  /** Final transform of an object obtained from export settings (up_axis, forward_axis) and world
-   * transform matrix.
-   */
-  float _world_and_axes_transform[4][4];
-
-  /** Total vertices in a mesh. */
-  uint _tot_vertices;
-  /** Total polygons (and thus normals) in a mesh. */
-  uint _tot_poly_normals;
-  /** Total UV vertices in a mesh's texture map. */
-  uint _tot_uv_vertices;
-  /** Only for curve converted to meshes: total edges in a mesh. */
-  uint _tot_edges;
-};
-
-class OBJNurbs {
- public:
-  OBJNurbs(bContext *C, Object *export_object) : _C(C), _export_object_eval(export_object)
-  {
-    init_nurbs_curve(export_object);
-  }
-  void get_curve_name(const char **r_object_name);
-  /** Getter for export curve. Used to obtain a curve's nurbs in OBJWriter class. */
-  const Curve *export_curve()
-  {
-    return _export_curve;
-  }
-  /** Get coordinates of a vertex at given point index. */
-  void calc_point_coords(float r_coords[3], uint point_index, Nurb *nurb);
-  /** Get nurbs' degree and number of "curv" points of a nurb. */
-  void get_curve_info(int *r_nurbs_degree, int *r_curv_num, Nurb *nurb);
-
- private:
-  bContext *_C;
-  Object *_export_object_eval;
-  Curve *_export_curve;
-  void init_nurbs_curve(Object *export_object);
-};
+/**
+ * Called from io_obj.c. Calls internal functions in IO:OBJ.
+ * When more preferences are there, will be used to set appropriate flags.
+ */
+void OBJ_export(bContext *C, const OBJExportParams *export_params);
+/**
+ * Called from io_obj.c. Currently not implemented.
+ */
+void OBJ_import(bContext *C, const OBJImportParams *import_params);
 
 }  // namespace obj
 }  // namespace io
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
index c90b90eef5b..8d4db05095d 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
@@ -21,295 +21,33 @@
  * \ingroup obj
  */
 
-#include "MEM_guardedalloc.h"
-
 #include <stdio.h>
 
-#include "BKE_curve.h"
-#include "BKE_customdata.h"
-#include "BKE_lib_id.h"
-#include "BKE_mesh.h"
-#include "BKE_mesh_mapping.h"
-#include "BKE_mesh_runtime.h"
 #include "BKE_scene.h"
 
-#include "BLI_math.h"
 #include "BLI_path_util.h"
 #include "BLI_vector.hh"
 
-#include "bmesh.h"
-#include "bmesh_tools.h"
-
-#include "DEG_depsgraph.h"
 #include "DEG_depsgraph_query.h"
 
-#include "DNA_curve_types.h"
-#include "DNA_layer_types.h"
-#include "DNA_modifier_types.h"
 #include "DNA_scene_types.h"
 
 #include "ED_object.h"
 
-#include "IO_wavefront_obj.h"
-
-#include "wavefront_obj.hh"
 #include "wavefront_obj_exporter.hh"
+#include "wavefront_obj_exporter_mesh.hh"
+#include "wavefront_obj_exporter_nurbs.hh"
 #include "wavefront_obj_file_handler.hh"
 
 namespace io {
 namespace obj {
 
-/**
- * Store evaluated object and mesh pointers depending on object type.
- * New meshes are created for curves converted to meshes and triangulated meshes.
- */
-void OBJMesh::init_export_mesh(Object *export_object)
-{
-  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(_C);
-  _export_object_eval = DEG_get_evaluated_object(depsgraph, export_object);
-  _export_mesh_eval = BKE_object_get_evaluated_mesh(_export_object_eval);
-  _me_eval_needs_free = false;
-
-  if (_export_mesh_eval && _export_mesh_eval->totpoly > 0) {
-    if (_export_params->export_triangulated_mesh) {
-      triangulate_mesh(_export_mesh_eval);
-      _me_eval_needs_free = true;
-    }
-    _tot_vertices = _export_mesh_eval->totvert;
-    _tot_poly_normals = _export_mesh_eval->totpoly;
-  }
-  /* Curves and nurbs surfaces need a new mesh when exported in the form of vertices and edges.
-   * For primitive circle, new mesh is redundant, but it behaves more like curves, so kept it here.
-   */
-  else {
-    _export_mesh_eval = BKE_mesh_new_from_object(depsgraph, _export_object_eval, true);
-    _me_eval_needs_free = true;
-    if (_export_object_eval->type == OB_CURVE || _export_mesh_eval->totpoly == 0) {
-      /* Don't export polygon normals when there are no polygons. */
-      _tot_poly_normals = 0;
-      _tot_vertices = _export_mesh_eval->totvert;
-      _tot_edges = _export_mesh_eval->totedge;
-    }
-    else if (_export_object_eval->type == OB_SURF) {
-      _tot_vertices = _export_mesh_eval->totvert;
-      _tot_poly_normals = _export_mesh_eval->totpoly;
-    }
-  }
-  store_world_axes_transform();
-}
-
-/**
- * Triangulate given mesh and update _export_mesh_eval.
- * \note The new mesh created here needs to be freed.
- */
-void OBJMesh::triangulate_mesh(Mesh *me_eval)
-{
-  struct BMeshCreateParams bm_create_params = {false};
-  /* If calc_face_normal is false, it triggers BLI_assert(BM_face_is_normal_valid(f)). */
-  struct BMeshFromMeshParams bm_convert_params = {true, 0, 0, 0};
-  /* Lower threshold where triangulation of a face starts, i.e. a quadrilateral will be
-   * triangulated here. */
-  int triangulate_min_verts = 4;
-
-  BMesh *bmesh = BKE_mesh_to_bmesh_ex(me_eval, &bm_create_params, &bm_convert_params);
-  BM_mesh_triangulate(bmesh,
-                      MOD_TRIANGULATE_NGON_BEAUTY,
-                      MOD_TRIANGULATE_QUAD_SHORTEDGE,
-                      triangulate_min_verts,
-         

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list