[Bf-blender-cvs] [25526821a4b] soc-2020-io-performance: Support importing vertex deform groups.
Ankit Meel
noreply at git.blender.org
Fri Jul 24 00:03:21 CEST 2020
Commit: 25526821a4b1ffb188068ad57ebee2061806bfd2
Author: Ankit Meel
Date: Fri Jul 24 03:15:21 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB25526821a4b1ffb188068ad57ebee2061806bfd2
Support importing vertex deform groups.
Remove unnecessary casting in exporter's deform group related code.
The fix in `BKE_object_deform.h` is temporary, until D8378
is committed to master.
===================================================================
M source/blender/blenkernel/BKE_object_deform.h
M source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.hh
===================================================================
diff --git a/source/blender/blenkernel/BKE_object_deform.h b/source/blender/blenkernel/BKE_object_deform.h
index e4813aa2288..2d2f8fb3389 100644
--- a/source/blender/blenkernel/BKE_object_deform.h
+++ b/source/blender/blenkernel/BKE_object_deform.h
@@ -59,7 +59,11 @@ void BKE_object_defgroup_index_map_apply(struct MDeformVert *dvert,
int map_len);
/* Select helpers */
-enum eVGroupSelect;
+enum eVGroupSelect
+#ifdef __cplusplus
+ : int
+#endif
+ ;
bool *BKE_object_defgroup_subset_from_select_type(struct Object *ob,
enum eVGroupSelect subset_type,
int *r_defgroup_tot,
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.cc
index 318a164e794..ed7fd1b3959 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.cc
@@ -417,8 +417,8 @@ const char *OBJMesh::get_poly_deform_group_name(const MPoly &mpoly, short &r_las
dvert = &dvert_orig[(mloop + loop_index)->v];
curr_weight = dvert->dw;
if (curr_weight) {
- bDeformGroup *vertex_group = (bDeformGroup *)BLI_findlink(
- (ListBase *)(&export_object_eval_->defbase), curr_weight->def_nr);
+ bDeformGroup *vertex_group = (bDeformGroup *)BLI_findlink((&export_object_eval_->defbase),
+ curr_weight->def_nr);
if (vertex_group) {
deform_group_members[curr_weight->def_nr] += 1;
found_group = true;
@@ -447,7 +447,7 @@ const char *OBJMesh::get_poly_deform_group_name(const MPoly &mpoly, short &r_las
r_last_vertex_group = max_idx;
const bDeformGroup &vertex_group = *(
- (bDeformGroup *)BLI_findlink((ListBase *)(&export_object_eval_->defbase), max_idx));
+ (bDeformGroup *)BLI_findlink(&export_object_eval_->defbase, max_idx));
return vertex_group.name;
}
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
index 53ee943b3de..af4e2d8c818 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
@@ -175,7 +175,8 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
/* Non owning raw pointer to the unique_ptr to a raw object.
* Needed to update object data in the same while loop. */
std::unique_ptr<OBJRawObject> *curr_ob = nullptr;
- /* State-setting variables: if set, they remain the same for the remaining elements. */
+ /* State-setting variables: if set, they remain the same for the remaining
+ * elements in the object. */
bool shaded_smooth = false;
string object_group{};
@@ -186,6 +187,8 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
if (line_key == "o") {
/* Update index offsets to keep track of objects which have claimed their vertices. */
update_index_offsets(curr_ob);
+ shaded_smooth = false;
+ object_group = {};
list_of_objects.append(std::make_unique<OBJRawObject>(s_line.str()));
curr_ob = &list_of_objects.last();
(*curr_ob)->object_type_ = OB_MESH;
@@ -262,6 +265,11 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
else if (line_key == "f") {
OBJFaceElem curr_face;
curr_face.shaded_smooth = shaded_smooth;
+ if (!object_group.empty()) {
+ curr_face.vertex_group = object_group;
+ /* Yes it repeats several times, but another if-check will not reduce steps either. */
+ (*curr_ob)->use_vertex_groups_ = true;
+ }
Vector<string> str_corners_split;
split_by_char(s_line.str(), ' ', str_corners_split);
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
index 41a07188488..6e1ce89ffea 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
@@ -22,8 +22,10 @@
*/
#include "BKE_customdata.h"
+#include "BKE_object_deform.h"
#include "BLI_array.hh"
+#include "BLI_map.hh"
#include "DNA_customdata_types.h"
#include "DNA_mesh_types.h"
@@ -81,6 +83,21 @@ void OBJMeshFromRaw::create_vertices(const OBJRawObject &curr_object,
void OBJMeshFromRaw::create_polys_loops(const OBJRawObject &curr_object, int64_t tot_face_elems)
{
+ /* May not be used conditionally. */
+ MDeformVert *deform_vert = mesh_from_raw_->dvert = nullptr;
+ float deform_weight = 0.0f;
+ if (curr_object.use_vertex_groups() && curr_object.tot_verts()) {
+ deform_vert = (MDeformVert *)CustomData_add_layer(
+ &mesh_from_raw_->vdata, CD_MDEFORMVERT, CD_CALLOC, nullptr, curr_object.tot_verts());
+ deform_vert->dw = (MDeformWeight *)MEM_callocN(curr_object.tot_verts() * sizeof(MDeformWeight),
+ "OBJImportDeformWeight");
+ deform_weight = 1.0f / curr_object.tot_verts();
+ }
+ else {
+ UNUSED_VARS(deform_vert, deform_weight);
+ }
+ Map<std::string, int> group_defnr;
+
int tot_loop_idx = 0;
for (int poly_idx = 0; poly_idx < tot_face_elems; ++poly_idx) {
const OBJFaceElem &curr_face = curr_object.face_elements()[poly_idx];
@@ -95,8 +112,24 @@ void OBJMeshFromRaw::create_polys_loops(const OBJRawObject &curr_object, int64_t
MLoop *mloop = &mesh_from_raw_->mloop[tot_loop_idx];
tot_loop_idx++;
mloop->v = curr_face.face_corners[loop_of_poly_idx].vert_index;
+ if (deform_vert && deform_vert[mloop->v].dw) {
+ /* Every vertex in a face is assigned the same deform group.
+ * Group names are the keys. If a new group is found, Map adds a new def_nr & mDeformWeight
+ * stores it. They're added to the Object in the same order of keys.
+ */
+ *(deform_vert[mloop->v].dw) = {static_cast<unsigned int>(group_defnr.lookup_or_add(
+ curr_face.vertex_group, group_defnr.size())),
+ deform_weight};
+ }
}
}
+ /* Add deform_vert listbase to the object. */
+ if (!curr_object.use_vertex_groups()) {
+ return;
+ }
+ for (const std::string &group : group_defnr.keys()) {
+ BKE_object_defgroup_add_name(mesh_object_.get(), group.c_str());
+ }
}
void OBJMeshFromRaw::create_edges(const OBJRawObject &curr_object, int64_t tot_edges)
@@ -117,11 +150,8 @@ void OBJMeshFromRaw::create_uv_verts(const OBJRawObject &curr_object,
const GlobalVertices &global_vertices)
{
if (curr_object.tot_uv_verts() > 0 && curr_object.tot_uv_vert_indices() > 0) {
- MLoopUV *mluv_dst = (MLoopUV *)CustomData_add_layer(&mesh_from_ob_->ldata,
- CD_MLOOPUV,
- CD_DUPLICATE,
- mesh_from_ob_->mloopuv,
- curr_object.tot_loops());
+ MLoopUV *mluv_dst = (MLoopUV *)CustomData_add_layer(
+ &mesh_from_raw_->ldata, CD_MLOOPUV, CD_CALLOC, nullptr, curr_object.tot_loops());
int tot_loop_idx = 0;
for (const OBJFaceElem &curr_face : curr_object.face_elements()) {
for (const OBJFaceCorner &curr_corner : curr_face.face_corners) {
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc
index 13ad04a3e8e..c2d9c705bc8 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc
@@ -66,6 +66,11 @@ const int64_t OBJRawObject::tot_face_elems() const
return face_elements_.size();
}
+const bool OBJRawObject::use_vertex_groups() const
+{
+ return use_vertex_groups_;
+}
+
Span<int> OBJRawObject::uv_vertex_indices() const
{
return uv_vertex_indices_;
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.hh
index 7e45233e60b..98d40a3662b 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.hh
@@ -104,6 +104,7 @@ class OBJRawObject {
/** Edges written in the file in addition to (or even without polygon) elements. */
Vector<MEdge> edges_{};
Vector<OBJFaceElem> face_elements_{};
+ bool use_vertex_groups_ = false;
OBJNurbsElem nurbs_element_;
int tot_loops_ = 0;
int tot_normals_ = 0;
@@ -119,6 +120,7 @@ class OBJRawObject {
const int64_t tot_verts() const;
Span<OBJFaceElem> face_elements() const;
const int64_t tot_face_elems() const;
+ const bool use_vertex_groups() const;
Span<int> uv_vertex_indices() const;
const int64_t tot_uv_vert_indices() const;
Span<MEdge> edges() const;
More information about the Bf-blender-cvs
mailing list