[Bf-blender-cvs] [012175f8437] soc-2020-io-performance: Support vertex group to which a face element belongs.
Ankit Meel
noreply at git.blender.org
Wed Jul 1 18:04:36 CEST 2020
Commit: 012175f843778916d0f0ff26c90810e2076729ce
Author: Ankit Meel
Date: Wed Jul 1 14:02:53 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB012175f843778916d0f0ff26c90810e2076729ce
Support vertex group to which a face element belongs.
Differential Revision: https://developer.blender.org/D8170
===================================================================
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
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 948d261e22b..0380cea3739 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -116,6 +116,7 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op)
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");
+ export_params.export_vertex_groups = RNA_boolean_get(op->ptr, "export_vertex_groups");
OBJ_export(C, &export_params);
@@ -190,6 +191,9 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr)
row = uiLayoutRow(box, false);
uiItemR(row, imfptr, "export_material_groups", 0, NULL, ICON_NONE);
+
+ row = uiLayoutRow(box, false);
+ uiItemR(row, imfptr, "export_vertex_groups", 0, NULL, ICON_NONE);
}
static void wm_obj_export_draw(bContext *UNUSED(C), wmOperator *op)
@@ -336,6 +340,12 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
false,
"Export material groups",
"If checked, writes object name with its mesh and material name too, separated by a '_'");
+ RNA_def_boolean(
+ ot->srna,
+ "export_vertex_groups",
+ false,
+ "Export vertex groups",
+ "If checked, writes the name of the vertex group to which a face's maximum vertices belong");
}
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 e63d3db341c..0fe056b5347 100644
--- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h
+++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
@@ -73,6 +73,7 @@ struct OBJExportParams {
/** Grouping options. */
bool export_object_groups;
bool export_material_groups;
+ bool export_vertex_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 9953328803d..e932f8e0806 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
@@ -22,9 +22,12 @@
*/
#include "BKE_customdata.h"
+#include "BKE_deform.h"
#include "BKE_mesh_mapping.h"
#include "BKE_object.h"
+#include "BLI_listbase.h"
+#include "BLI_map.hh"
#include "BLI_math.h"
#include "bmesh.h"
@@ -148,7 +151,7 @@ void OBJMesh::ensure_normals()
}
/** Return mat_nr-th material of the object. */
-Material *OBJMesh::get_export_object_material(short mat_nr)
+Material *OBJMesh::get_object_material(short mat_nr)
{
return BKE_object_material_get(_export_object_eval, mat_nr);
}
@@ -261,6 +264,39 @@ void OBJMesh::calc_poly_normal_indices(Vector<uint> &r_normal_indices, uint poly
}
}
+/**
+ * Find the name of the group to which maximum number of vertices of a poly belong.
+ * If no vertex belongs to any group, name is "off".
+ * If there's a tie between two or more vertices, group name depends on the implementation
+ * of max_element.
+ */
+const char *OBJMesh::get_object_deform_vert(const MPoly &mpoly)
+{
+ const MLoop *mloop = &_export_mesh_eval->mloop[mpoly.loopstart];
+ Vector<int> deform_group_indices;
+ deform_group_indices.resize(mpoly.totloop, 0);
+ bool has_group = false;
+ for (uint loop_index = 0; loop_index < mpoly.totloop; loop_index++) {
+ const MDeformVert dvert = _export_mesh_eval->dvert[(mloop + loop_index)->v];
+ const MDeformWeight *curr_weight = dvert.dw;
+ if (curr_weight) {
+ bDeformGroup *vertex_group = (bDeformGroup *)BLI_findlink(
+ (ListBase *)(&_export_object_eval->defbase), curr_weight->def_nr);
+ if (vertex_group) {
+ deform_group_indices[curr_weight->def_nr] += 1;
+ has_group = true;
+ }
+ }
+ }
+ if (!has_group) {
+ return "off";
+ }
+ int max_idx = *std::max_element(deform_group_indices.begin(), deform_group_indices.end());
+ bDeformGroup *vertex_group = (bDeformGroup *)BLI_findlink(
+ (ListBase *)(&_export_object_eval->defbase), deform_group_indices[max_idx]);
+ return vertex_group->name;
+}
+
/**
* Only for curve converted to meshes and primitive circle: calculate vertex indices of one edge.
*/
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 48d9c4c96ba..a7c99c846f4 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
@@ -87,7 +87,14 @@ class OBJMesh : NonMovable, NonCopyable {
void ensure_normals();
/** Return mat_nr-th material of the object. */
- Material *get_export_object_material(short mat_nr);
+ Material *get_object_material(short mat_nr);
+ /**
+ * Find the name of the group to which maximum number of vertices of a poly belong.
+ * If no vertex belongs to any group, name is "off".
+ * If there's a tie between two or more vertices, group name depends on the implementation
+ * of max_element.
+ */
+ const char *get_object_deform_vert(const MPoly &mpoly);
/* Names as they appear in the outliner. */
const char *get_object_name();
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 980ab59674f..067d6880594 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
@@ -311,7 +311,7 @@ void MTLWriter::append_materials(OBJMesh &mesh_to_export)
const char *object_name;
object_name = mesh_to_export.get_object_name();
for (int curr_mat = 0; curr_mat < mesh_to_export.tot_col(); curr_mat++) {
- _export_mtl = mesh_to_export.get_export_object_material(curr_mat + 1);
+ _export_mtl = mesh_to_export.get_object_material(curr_mat + 1);
write_curr_material(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 250ac8904a6..de385631944 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
@@ -204,6 +204,18 @@ void OBJWriter::write_poly_material(short &last_face_mat_nr, OBJMesh &obj_mesh_d
}
}
+/**
+ * Write the deform vertex group name to which maximum number of vertices of a face belong.
+ */
+void OBJWriter::write_vertex_group(OBJMesh &obj_mesh_data, const MPoly &mpoly)
+{
+ if (!_export_params->export_vertex_groups) {
+ return;
+ }
+ const char *def_group_name = obj_mesh_data.get_object_deform_vert(mpoly);
+ fprintf(_outfile, "g %s\n", def_group_name);
+}
+
/**
* Define and write a face with at least vertex indices, and conditionally with UV vertex indices
* and face normal indices.
@@ -224,6 +236,7 @@ void OBJWriter::write_poly_indices(OBJMesh &obj_mesh_data, Span<Vector<uint>> uv
obj_mesh_data.calc_poly_normal_indices(normal_indices, i);
const MPoly &poly_to_write = obj_mesh_data.get_ith_poly(i);
+ write_vertex_group(obj_mesh_data, poly_to_write);
write_poly_material(last_face_mat_nr, obj_mesh_data, poly_to_write.mat_nr);
write_vert_uv_normal_indices(vertex_indices, uv_indices[i], normal_indices, poly_to_write);
}
@@ -235,6 +248,7 @@ void OBJWriter::write_poly_indices(OBJMesh &obj_mesh_data, Span<Vector<uint>> uv
obj_mesh_data.calc_poly_normal_indices(normal_indices, i);
const MPoly &poly_to_write = obj_mesh_data.get_ith_poly(i);
+ write_vertex_group(obj_mesh_data, poly_to_write);
write_poly_material(last_face_mat_nr, obj_mesh_data, poly_to_write.mat_nr);
write_vert_normal_indices(vertex_indices, normal_indices, poly_to_write);
}
@@ -247,6 +261,7 @@ void OBJWriter::write_poly_indices(OBJMesh &obj_mesh_data, Span<Vector<uint>> uv
obj_mesh_data.calc_poly_vertex_indices(vertex_indices, i);
const MPoly &poly_to_write = obj_mesh_data.get_ith_poly(i);
+ write_vertex_group(obj_mesh_data, poly_to_write);
write_poly_material(last_face_mat_nr, obj_mesh_data, poly_to_write.mat_nr);
write_vert_uv_indices(vertex_indices, uv_indices[i], poly_to_write);
}
@@ -257,6 +272,7 @@ void OBJWriter::write_poly_indices(OBJMesh &obj_mesh_data, Span<Vector<uint>> uv
obj_mesh_data.calc_poly_vertex_indices(vertex_indices, i);
const MPoly &poly_to_write = obj_mesh_data.get_ith_poly(i);
+ write_vertex_group(obj_mesh_data, poly_to_write);
write_poly_material(last_face_mat_nr, obj_mesh_data, poly_to_write.mat_nr);
write_vert_indices(vertex_indices, poly_to_write);
}
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 f111b0f01a6..e1978aca433 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
@@ -75,6 +75,10 @@ class OBJWriter {
* \note It doesn't write to the material library, MTL file.
*/
void write_poly_material(short &last_face_mat_nr, OBJMesh &obj_mesh_data, short mat_nr);
+ /**
+ * Write the deform vertex group name to which maximum number of vertices of a face belong.
+ */
+ void write_vertex_group(OBJMesh &obj_mesh_data, const MPoly &mpoly);
/** Define and write a face with at least vertex indices, and conditionally with UV vertex
* indices and face normal indices. \note UV indices are stored while writing UV vertices.
*/
More information about the Bf-blender-cvs
mailing list