[Bf-blender-cvs] [f9289bb5eae] soc-2020-io-performance: Review update: Renaming, comments, minor refactor

Ankit Meel noreply at git.blender.org
Mon Jun 22 21:03:36 CEST 2020


Commit: f9289bb5eae01e6903615bf509feaea4f44d90c3
Author: Ankit Meel
Date:   Fri Jun 19 11:59:02 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBf9289bb5eae01e6903615bf509feaea4f44d90c3

Review update: Renaming, comments, minor refactor

Review update for comments in D7959. No new feature has been added.
Changes here:

Use PIL_time.h instead of chrono. Use BLI_path_util.h instead of stdio.

Remove redundant `_to_export` suffix from some variables.

Clarify that `object_to_export` is `ob_mesh` to distinguish it from
curves objects later on.

Edited comments.

Change in face normal calculation in one loop instead of three for the
three axes components.

Add const where required.

Not hardcode Blender version but use `BKE_blender_version_string()`.

Add filenames to error messages in file opening.

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

M	source/blender/editors/io/io_obj.c
M	source/blender/io/wavefront_obj/IO_wavefront_obj.h
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
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/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index bf915f64ce1..0ebcea9c235 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -109,7 +109,7 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op)
 
   export_params.export_uv = RNA_boolean_get(op->ptr, "export_uv");
   export_params.export_normals = RNA_boolean_get(op->ptr, "export_normals");
-  export_params.export_triangulated = RNA_boolean_get(op->ptr, "export_triangulated_mesh");
+  export_params.export_triangulated_mesh = RNA_boolean_get(op->ptr, "export_triangulated_mesh");
 
   OBJ_export(C, &export_params);
 
diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
index 1e068d69204..7ae947c1cd8 100644
--- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h
+++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
@@ -22,7 +22,7 @@
 #define __IO_WAVEFRONT_OBJ_H__
 
 #include "BKE_context.h"
-#include <stdio.h> /* For FILENAME_MAX. */
+#include "BLI_path_util.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -48,7 +48,7 @@ typedef enum {
 
 struct OBJExportParams {
   /** Full path to the destination OBJ file to export. */
-  char filepath[FILENAME_MAX];
+  char filepath[FILE_MAX];
 
   /** Whether mutiple frames are to be exported or not. */
   bool export_animation;
@@ -65,12 +65,12 @@ struct OBJExportParams {
   /** File Write Options */
   bool export_uv;
   bool export_normals;
-  bool export_triangulated;
+  bool export_triangulated_mesh;
 };
 
 struct OBJImportParams {
   /** Full path to the source OBJ file to import. */
-  char filepath[FILENAME_MAX];
+  char filepath[FILE_MAX];
 };
 
 void OBJ_import(bContext *C, const struct OBJImportParams *import_params);
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj.cc
index 4fc4abca46d..6513efb3ade 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj.cc
@@ -22,7 +22,7 @@
  */
 
 #include "IO_wavefront_obj.h"
-#include <chrono>
+#include "PIL_time.h"
 
 #include "wavefront_obj.hh"
 #include "wavefront_obj_exporter.hh"
@@ -33,12 +33,10 @@
  */
 void OBJ_export(bContext *C, const OBJExportParams *export_params)
 {
-  std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
+  double start_time = PIL_check_seconds_timer();
   io::obj::exporter_main(C, export_params);
-  std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
-  std::cout << "--------\nExport Time = "
-            << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << "[ms]"
-            << std::endl;
+  double end_time = PIL_check_seconds_timer();
+  std::cout << "\nOBJ export time: " << (end_time - start_time) * 1000 << " milliseconds\n";
 }
 /**
  * Called from io_obj.c. Currently not implemented.
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj.hh
index a1d7993809e..bda3b4e6782 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj.hh
@@ -50,7 +50,6 @@ struct Polygon {
   uint total_vertices_per_poly;
   /**
    * Vertex indices of this polygon. v1, v2 .. above.
-   * The index corresponds to the pre-defined vertex list.
    */
   std::vector<uint> vertex_index;
   /**
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 5d66fb19b57..85349e9b612 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
@@ -58,80 +58,77 @@ namespace io {
 namespace obj {
 
 /**
- * Store the mesh vertex coordinates in obmesh_to_export, in world coordinates.
+ * Store the mesh vertex coordinates in obmesh, in world coordinates.
  */
-static void get_transformed_mesh_vertices(Mesh *me_eval,
-                                          Object *ob_eval,
-                                          OBJ_obmesh_to_export &obmesh_to_export)
+static void store_transformed_mesh_vertices(const Mesh *me_eval,
+                                            const Object *ob_eval,
+                                            OBJ_obmesh_to_export &ob_mesh)
 {
-  uint num_verts = obmesh_to_export.tot_vertices = me_eval->totvert;
-  obmesh_to_export.mvert = (MVert *)MEM_callocN(num_verts * sizeof(MVert),
-                                                "OBJ mesh object vertex coordinates & normals");
+  uint num_verts = ob_mesh.tot_vertices = me_eval->totvert;
   float axes_transform[3][3];
   unit_m3(axes_transform);
   mat3_from_axis_conversion(DEFAULT_AXIS_FORWARD,
                             DEFAULT_AXIS_UP,
-                            obmesh_to_export.forward_axis,
-                            obmesh_to_export.up_axis,
+                            ob_mesh.forward_axis,
+                            ob_mesh.up_axis,
                             axes_transform);
 
   float world_transform[4][4];
   copy_m4_m4(world_transform, ob_eval->obmat);
   mul_m4_m3m4(world_transform, axes_transform, world_transform);
   for (uint i = 0; i < num_verts; i++) {
-    copy_v3_v3(obmesh_to_export.mvert[i].co, me_eval->mvert[i].co);
-    mul_m4_v3(world_transform, obmesh_to_export.mvert[i].co);
-    mul_v3_fl(obmesh_to_export.mvert[i].co, obmesh_to_export.scaling_factor);
+    copy_v3_v3(ob_mesh.mvert[i].co, me_eval->mvert[i].co);
+    mul_m4_v3(world_transform, ob_mesh.mvert[i].co);
+    mul_v3_fl(ob_mesh.mvert[i].co, ob_mesh.scaling_factor);
   }
 }
 
 /**
- * Store the mesh vertex normals in obmesh_to_export, in world coordinates.
- * Memory for obmesh_to_export.mvert pre-allocated in get_transformed_mesh_vertices.
+ * Store the mesh's per-face per-vertex normals in ob_mesh, in world coordinates.
  */
-static void get_transformed_vertex_normals(Mesh *me_eval,
-                                           Object *ob_eval,
-                                           OBJ_obmesh_to_export &obmesh_to_export)
+static void store_transformed_vertex_normals(Mesh *me_eval,
+                                             const Object *ob_eval,
+                                             OBJ_obmesh_to_export &ob_mesh)
 {
   BKE_mesh_ensure_normals(me_eval);
   float transformed_normal[3];
   for (uint i = 0; i < me_eval->totvert; i++) {
     normal_short_to_float_v3(transformed_normal, me_eval->mvert[i].no);
     mul_mat3_m4_v3(ob_eval->obmat, transformed_normal);
-    normal_float_to_short_v3(obmesh_to_export.mvert[i].no, transformed_normal);
+    normal_float_to_short_v3(ob_mesh.mvert[i].no, transformed_normal);
   }
 }
 
 /**
- * Store a polygon's vertex indices, indexing into the pre-defined
- * vertex coordinates list.
+ * Store the vertex indices of all loops in all polygons of a mesh.
  */
-static void get_polygon_vert_indices(Mesh *me_eval, OBJ_obmesh_to_export &obmesh_to_export)
+static void store_polygon_vert_indices(const Mesh *me_eval, OBJ_obmesh_to_export &ob_mesh)
 {
   const MLoop *mloop;
   const MPoly *mpoly = me_eval->mpoly;
 
-  obmesh_to_export.tot_poly = me_eval->totpoly;
-  obmesh_to_export.polygon_list.resize(me_eval->totpoly);
+  ob_mesh.tot_poly = me_eval->totpoly;
+  ob_mesh.polygon_list.resize(me_eval->totpoly);
 
-  for (uint i = 0; i < me_eval->totpoly; i++, mpoly++) {
+  for (uint poly_index = 0; poly_index < me_eval->totpoly; poly_index++, mpoly++) {
     mloop = &me_eval->mloop[mpoly->loopstart];
-    obmesh_to_export.polygon_list[i].total_vertices_per_poly = mpoly->totloop;
+    Polygon &poly = ob_mesh.polygon_list[poly_index];
 
-    obmesh_to_export.polygon_list[i].vertex_index.resize(mpoly->totloop);
+    poly.total_vertices_per_poly = mpoly->totloop;
+    poly.vertex_index.resize(mpoly->totloop);
 
-    for (int j = 0; j < mpoly->totloop; j++) {
+    for (int loop_index = 0; loop_index < mpoly->totloop; loop_index++) {
       /* mloop->v is 0-based index. Indices in OBJ start from 1. */
-      obmesh_to_export.polygon_list[i].vertex_index[j] = (mloop + j)->v + 1;
+      poly.vertex_index[loop_index] = (mloop + loop_index)->v + 1;
     }
   }
 }
 
 /**
- * Store UV vertex coordinates in obmesh_to_export.uv_coords as well as their indices, in
+ * Store UV vertex coordinates in ob_mesh.uv_coords as well as their indices, in
  * a polygon[i].uv_vertex_index.
  */
-static void get_uv_coordinates(Mesh *me_eval, OBJ_obmesh_to_export &obmesh_to_export)
+static void store_uv_coordinates(Mesh *me_eval, OBJ_obmesh_to_export &ob_mesh)
 {
   const CustomData *ldata = &me_eval->ldata;
 
@@ -149,87 +146,95 @@ static void get_uv_coordinates(Mesh *me_eval, OBJ_obmesh_to_export &obmesh_to_ex
     UvVertMap *uv_vert_map = BKE_mesh_uv_vert_map_create(
         mpoly, mloop, mloopuv, me_eval->totpoly, me_eval->totvert, limit, false, false);
 
-    obmesh_to_export.tot_uv_vertices = -1;
+    ob_mesh.tot_uv_vertices = -1;
     for (int vertex_index = 0; vertex_index < me_eval->totvert; vertex_index++) {
       const UvMapVert *uv_vert = BKE_mesh_uv_vert_map_get_vert(uv_vert_map, vertex_index);
       while (uv_vert != NULL) {
         if (uv_vert->separate) {
-          obmesh_to_export.tot_uv_vertices++;
+          ob_mesh.tot_uv_vertices++;
         }
-        Polygon &polygon_of_uv_vert = obmesh_to_export.polygon_list[uv_vert->poly_index];
+        Polygon &polygon_of_uv_vert = ob_mesh.polygon_list[uv_vert->poly_index];
         const uint vertices_in_poly = polygon_of_uv_vert.total_vertices_per_poly;
         /* Resize UV vertices index list. */
         polygon_of_uv_vert.uv_vertex_index.resize(vertices_in_poly);
 
         /* Fill up UV vertex index for current polygon's one vertex. */
         polygon_of_uv_vert.uv_vertex_index[uv_vert->loop_of_poly_index] =
-            obmesh_to_export.tot_uv_vertices;
+            ob_mesh.tot_uv_vertices;
 
         /* Fill up UV vertices' coordinates. We don't know how many unique vertices are there, so
          * need to push back everytime. */
-        obmesh_to_export.uv_coords.push_back(st

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list