[Bf-blender-cvs] [bab0fce9141] soc-2020-io-performance: Support material groups: writing material name with object name

Ankit Meel noreply at git.blender.org
Mon Jun 29 10:35:03 CEST 2020


Commit: bab0fce9141b7d7f9a99755cd01e91274277ecab
Author: Ankit Meel
Date:   Mon Jun 29 14:04:51 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBbab0fce9141b7d7f9a99755cd01e91274277ecab

Support material groups: writing material name with object name

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

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_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 cadb79aec29..948d261e22b 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -115,6 +115,7 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op)
   export_params.export_curves_as_nurbs = RNA_boolean_get(op->ptr, "export_curves_as_nurbs");
 
   export_params.export_object_groups = RNA_boolean_get(op->ptr, "export_object_groups");
+  export_params.export_material_groups = RNA_boolean_get(op->ptr, "export_material_groups");
 
   OBJ_export(C, &export_params);
 
@@ -186,6 +187,9 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr)
 
   row = uiLayoutRow(box, false);
   uiItemR(row, imfptr, "export_object_groups", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_material_groups", 0, NULL, ICON_NONE);
 }
 
 static void wm_obj_export_draw(bContext *UNUSED(C), wmOperator *op)
@@ -321,12 +325,17 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
                   "Export curves as NURBS",
                   "If false, writes the curve as a mesh withouth modifying the scene");
 
+  RNA_def_boolean(ot->srna,
+                  "export_object_groups",
+                  false,
+                  "Export object groups",
+                  "If checked, writes object name with its mesh name too, separated by a '_' ");
   RNA_def_boolean(
       ot->srna,
-      "export_object_groups",
+      "export_material_groups",
       false,
-      "Export objects as groups",
-      "If checked, writes object name with its mesh name too, separated by a '_' ");
+      "Export material groups",
+      "If checked, writes object name with its mesh and material name too, separated by a '_'");
 }
 
 static int wm_obj_import_invoke(bContext *C, wmOperator *op, const wmEvent *event)
diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
index 93ba2b8af56..bb5f34c0a91 100644
--- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h
+++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
@@ -72,6 +72,7 @@ struct OBJExportParams {
 
   /** Grouping options */
   bool export_object_groups;
+  bool export_material_groups;
 };
 
 struct OBJImportParams {
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.cc
index e2cf590c36e..ab7843b1bbc 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.cc
@@ -174,13 +174,20 @@ void OBJWriter::write_poly_normals(OBJMesh &obj_mesh_data)
 }
 
 /**
- * Write material name of an object in the OBJ file.
+ * Write material name and material group of an object in the OBJ file.
  * \note It doesn't write to the material library.
  */
 void OBJWriter::write_usemtl(OBJMesh &obj_mesh_data)
 {
   const char *mat_name;
   obj_mesh_data.set_object_material_name(&mat_name);
+  if (_export_params->export_material_groups) {
+    const char *object_name;
+    const char *object_data_name;
+    obj_mesh_data.set_object_name(&object_name);
+    obj_mesh_data.set_object_data_name(&object_data_name);
+    fprintf(_outfile, "g %s_%s_%s\n", object_name, object_data_name, mat_name);
+  }
   fprintf(_outfile, "usemtl %s\n", mat_name);
 }
 
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.hh
index 26dc1ea2790..eb0dd0af635 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.hh
@@ -71,7 +71,7 @@ class OBJWriter {
   void write_uv_coords(OBJMesh &obj_mesh_data, Vector<Vector<uint>> &uv_indices);
   /** Write face normals for all polygons as vn x y z */
   void write_poly_normals(OBJMesh &obj_mesh_data);
-  /** Write name of an object's active material in the OBJ file.
+  /** Write material name and material group of an object in the OBJ file.
    * \note It doesn't write to the material library, MTL file.
    */
   void write_usemtl(OBJMesh &obj_mesh_data);



More information about the Bf-blender-cvs mailing list