[Bf-blender-cvs] [83e0db031aa] soc-2020-io-performance: Simplify material group calculation.

Ankit Meel noreply at git.blender.org
Wed Sep 16 13:05:55 CEST 2020


Commit: 83e0db031aa5d604ee2a58f0083fe87c1f18f750
Author: Ankit Meel
Date:   Wed Sep 16 15:15:28 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB83e0db031aa5d604ee2a58f0083fe87c1f18f750

Simplify material group calculation.

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

M	source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc

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

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 8de62fa5e22..1605b62db14 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
@@ -243,19 +243,20 @@ void OBJWriter::write_poly_material(const OBJMesh &obj_mesh_data,
   if (!export_params_.export_materials || obj_mesh_data.tot_materials() <= 0) {
     return;
   }
-  const short mat_nr = obj_mesh_data.ith_poly_matnr(poly_index);
+  const short curr_mat_nr = obj_mesh_data.ith_poly_matnr(poly_index);
   /* Whenever a face with a new material is encountered, write its material and/or group, otherwise
    * pass. */
-  if (r_last_face_mat_nr != mat_nr) {
-    const char *mat_name = obj_mesh_data.get_object_material_name(mat_nr + 1);
-    if (export_params_.export_material_groups) {
-      const char *object_name = obj_mesh_data.get_object_name();
-      const char *object_mesh_name = obj_mesh_data.get_object_mesh_name();
-      fprintf(outfile_, "g %s_%s_%s\n", object_name, object_mesh_name, mat_name);
-    }
-    fprintf(outfile_, "usemtl %s\n", mat_name);
-    r_last_face_mat_nr = mat_nr;
+  if (r_last_face_mat_nr == curr_mat_nr) {
+    return;
   }
+  const char *mat_name = obj_mesh_data.get_object_material_name(curr_mat_nr);
+  if (export_params_.export_material_groups) {
+    const char *object_name = obj_mesh_data.get_object_name();
+    const char *object_mesh_name = obj_mesh_data.get_object_mesh_name();
+    fprintf(outfile_, "g %s_%s_%s\n", object_name, object_mesh_name, mat_name);
+  }
+  fprintf(outfile_, "usemtl %s\n", mat_name);
+  r_last_face_mat_nr = curr_mat_nr;
 }
 
 /**
@@ -289,9 +290,6 @@ void OBJWriter::write_vertex_group(const OBJMesh &obj_mesh_data,
 OBJWriter::func_vert_uv_normal_indices OBJWriter::get_poly_element_writer(
     const OBJMesh &obj_mesh_data)
 {
-  /* -1 has no significant value, it can be any negative number. */
-  short last_face_mat_nr = -1;
-
   if (export_params_.export_normals) {
     if (export_params_.export_uv && (obj_mesh_data.tot_uv_vertices() > 0)) {
       /* Write both normals and UV indices. */
@@ -317,6 +315,7 @@ void OBJWriter::write_poly_elements(const OBJMesh &obj_mesh_data)
 {
   int last_face_smooth_group = NEGATIVE_INIT;
   short last_face_vertex_group = NEGATIVE_INIT;
+  short last_face_mat_nr = NEGATIVE_INIT;
 
   Vector<uint> vertex_indices;
     const int totloop = obj_mesh_data.ith_poly_totloop(i);



More information about the Bf-blender-cvs mailing list