[Bf-blender-cvs] [90869897442] soc-2020-io-performance: Support for object groups: name of object and its mesh

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


Commit: 90869897442adea135859f7b28d1ec0248d91593
Author: Ankit Meel
Date:   Mon Jun 29 13:55:34 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB90869897442adea135859f7b28d1ec0248d91593

Support for object groups: name of object and its mesh

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

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_exporter_mesh.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.hh
M	source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.cc

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

diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index 0b730e06c19..cadb79aec29 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -114,6 +114,8 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op)
   export_params.export_triangulated_mesh = RNA_boolean_get(op->ptr, "export_triangulated_mesh");
   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");
+
   OBJ_export(C, &export_params);
 
   return OPERATOR_FINISHED;
@@ -177,6 +179,13 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr)
 
   row = uiLayoutRow(box, false);
   uiItemR(row, imfptr, "export_curves_as_nurbs", 0, NULL, ICON_NONE);
+
+  box = uiLayoutBox(layout);
+  row = uiLayoutRow(box, false);
+  uiItemL(row, IFACE_("Grouping Options"), ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_object_groups", 0, NULL, ICON_NONE);
 }
 
 static void wm_obj_export_draw(bContext *UNUSED(C), wmOperator *op)
@@ -311,6 +320,13 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
                   false,
                   "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 objects as groups",
+      "If checked, writes object name with its mesh 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 7e2e32a169d..93ba2b8af56 100644
--- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h
+++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
@@ -69,6 +69,9 @@ struct OBJExportParams {
   bool export_materials;
   bool export_triangulated_mesh;
   bool export_curves_as_nurbs;
+
+  /** Grouping options */
+  bool export_object_groups;
 };
 
 struct OBJImportParams {
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.cc
index 37a5ce84199..7d77215b122 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.cc
@@ -125,11 +125,16 @@ void OBJMesh::store_world_axes_transform()
   copy_v4_v4(_world_and_axes_transform[3], _export_object_eval->obmat[3]);
 }
 
-void OBJMesh::get_object_name(const char **r_object_name)
+void OBJMesh::set_object_name(const char **r_object_name)
 {
   *r_object_name = _export_object_eval->id.name + 2;
 }
 
+void OBJMesh::set_object_data_name(const char **r_object_data_name)
+{
+  *r_object_data_name = _export_mesh_eval->id.name + 2;
+}
+
 /**
  * Calculate coordinates of the vertex at given index.
  */
@@ -226,7 +231,7 @@ void OBJMesh::calc_poly_normal(float r_poly_normal[3], uint poly_index)
 /**
  * Set argument pointer to the name of an object's active material.
  */
-void OBJMesh::get_material_name(const char **r_mat_name)
+void OBJMesh::set_object_material_name(const char **r_mat_name)
 {
   Material *mat = BKE_object_material_get(_export_object_eval, _export_object_eval->actcol);
   *r_mat_name = mat->id.name + 2;
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.hh
index 580c213462d..6a1e31c6bfa 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.hh
@@ -93,12 +93,13 @@ class OBJMesh {
   {
     return BKE_object_material_get(_export_object_eval, _export_object_eval->actcol);
   }
+
   /**
-   * Set argument pointer to the name of an object's active material.
+   * Set argument pointer to an object's name, as it appears in outliner.
    */
-  void get_material_name(const char **r_mat_name);
-
-  void get_object_name(const char **object_name);
+  void set_object_name(const char **object_name);
+  void set_object_data_name(const char **r_object_data_name);
+  void set_object_material_name(const char **r_mat_name);
   /**
    * Calculate coordinates of the vertex at given index.
    */
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.cc
index 148de889c05..5be3a76790b 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.cc
@@ -160,7 +160,7 @@ void MTLWriter::append_material(OBJMesh &mesh_to_export)
   }
 
   const char *object_name;
-  mesh_to_export.get_object_name(&object_name);
+  mesh_to_export.set_object_name(&object_name);
   _export_mtl = mesh_to_export.export_object_material();
   if (!_export_mtl) {
     fprintf(stderr, "No active material for the object: %s.\n", object_name);
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 7746d427454..e2cf590c36e 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
@@ -126,8 +126,16 @@ void OBJWriter::write_mtllib(const char *obj_filepath)
 void OBJWriter::write_object_name(OBJMesh &obj_mesh_data)
 {
   const char *object_name;
-  obj_mesh_data.get_object_name(&object_name);
-  fprintf(_outfile, "o %s\n", object_name);
+  obj_mesh_data.set_object_name(&object_name);
+
+  if (_export_params->export_object_groups) {
+    const char *object_data_name;
+    obj_mesh_data.set_object_data_name(&object_data_name);
+    fprintf(_outfile, "g %s_%s\n", object_name, object_data_name);
+  }
+  else {
+    fprintf(_outfile, "o %s\n", object_name);
+  }
 }
 
 /** Write vertex coordinates for all vertices as v x y z */
@@ -172,7 +180,7 @@ void OBJWriter::write_poly_normals(OBJMesh &obj_mesh_data)
 void OBJWriter::write_usemtl(OBJMesh &obj_mesh_data)
 {
   const char *mat_name;
-  obj_mesh_data.get_material_name(&mat_name);
+  obj_mesh_data.set_object_material_name(&mat_name);
   fprintf(_outfile, "usemtl %s\n", mat_name);
 }



More information about the Bf-blender-cvs mailing list