[Bf-blender-cvs] [b034660643e] cloth-improvements: Implement combined vertex weight by group influeces (Weight Keys)

Luca Rood noreply at git.blender.org
Tue Mar 14 06:52:50 CET 2017


Commit: b034660643e693df00814b640c060b67ed9298a0
Author: Luca Rood
Date:   Fri Dec 9 14:34:46 2016 -0200
Branches: cloth-improvements
https://developer.blender.org/rBb034660643e693df00814b640c060b67ed9298a0

Implement combined vertex weight by group influeces (Weight Keys)

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

M	release/scripts/startup/bl_ui/properties_data_mesh.py
M	source/blender/blenkernel/BKE_deform.h
M	source/blender/blenkernel/intern/deform.c
M	source/blender/editors/include/ED_mesh.h
M	source/blender/editors/object/object_vgroup.c
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/makesrna/intern/rna_object.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index 59907692fe0..05b0962af4a 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -68,9 +68,14 @@ class MESH_UL_vgroups(UIList):
         # assert(isinstance(item, bpy.types.VertexGroup))
         vgroup = item
         if self.layout_type in {'DEFAULT', 'COMPACT'}:
-            layout.prop(vgroup, "name", text="", emboss=False, icon_value=icon)
+            split = layout.split(0.66, False)
+            split.prop(vgroup, "name", text="", emboss=False, icon_value=icon)
+
+            row = split.row(align=True)
+            row.prop(vgroup, "influence", text="", emboss=False)
+
             icon = 'LOCKED' if vgroup.lock_weight else 'UNLOCKED'
-            layout.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
+            row.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
         elif self.layout_type == 'GRID':
             layout.alignment = 'CENTER'
             layout.label(text="", icon_value=icon)
@@ -226,6 +231,10 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
 
             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
 
+        row = layout.row()
+        row.active = ob.mode != 'EDIT'
+        row.prop(group, "influence")
+
 
 class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
     bl_label = "Shape Keys"
diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h
index 8756f73df72..c2679a3d06c 100644
--- a/source/blender/blenkernel/BKE_deform.h
+++ b/source/blender/blenkernel/BKE_deform.h
@@ -125,4 +125,12 @@ void BKE_deform_split_prefix(const char string[MAX_VGROUP_NAME], char base[MAX_V
 void BKE_deform_flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_NAME],
                                const bool strip_number);
 
+float BKE_defvert_combined_weight(const Object *object, const struct MDeformVert *dvert, const int mode);
+
+/* combined weight mode */
+enum {
+	DVERT_COMBINED_MODE_ADD = 0,
+	DVERT_COMBINED_MODE_MIX = 1,
+};
+
 #endif  /* __BKE_DEFORM_H__ */
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index 7052e0a7d25..65c05c82134 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -70,6 +70,8 @@ bDeformGroup *BKE_defgroup_new(Object *ob, const char *name)
 
 	BLI_strncpy(defgroup->name, name, sizeof(defgroup->name));
 
+	defgroup->influence = 0.0f;
+
 	BLI_addtail(&ob->defbase, defgroup);
 	defgroup_unique_name(defgroup, ob);
 
@@ -1455,3 +1457,35 @@ bool data_transfer_layersmapping_vgroups(
 }
 
 /** \} */
+
+/**
+ * \return The interpolated weight of all vertex groups for a given vertex.
+ */
+float BKE_defvert_combined_weight(const Object *object, const MDeformVert *dvert, const int mode)
+{
+	bDeformGroup *dg;
+	float tot_weight = 0;
+	float tot_influence = 0;
+	int i = 0;
+
+	if (mode == DVERT_COMBINED_MODE_ADD) {
+		for (; i < dvert->totweight; i++) {
+			dg = BLI_findlink(&object->defbase, dvert->dw[i].def_nr);
+			tot_weight += dvert->dw[i].weight * dg->influence;
+		}
+
+		return min_ff(tot_weight, 1.0f);
+	}
+	else if (mode == DVERT_COMBINED_MODE_MIX) {
+		for (dg = object->defbase.first; dg; dg = dg->next, i++) {
+			if (dg->influence > 0) {
+				tot_weight += defvert_find_weight(dvert, i) * dg->influence;
+				tot_influence += dg->influence;
+			}
+		}
+
+		return tot_influence > 0 ? tot_weight / tot_influence : 0.0f;
+	}
+
+	return 0.0f;
+}
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index de798b1fce2..c3b92fc918a 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -257,6 +257,7 @@ void                 ED_vgroup_mirror(struct Object *ob,
 void                 ED_vgroup_vert_add(struct Object *ob, struct bDeformGroup *dg, int vertnum,  float weight, int assignmode);
 void                 ED_vgroup_vert_remove(struct Object *ob, struct bDeformGroup *dg, int vertnum);
 float                ED_vgroup_vert_weight(struct Object *ob, struct bDeformGroup *dg, int vertnum);
+float                ED_vgroup_combined_vert_weight(const struct Object *ob, const int vertnum, const int mode);
 void                 ED_vgroup_vert_active_mirror(struct Object *ob, int def_nr);
 
 
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c
index 56f59dca9a1..e471bbbf34a 100644
--- a/source/blender/editors/object/object_vgroup.c
+++ b/source/blender/editors/object/object_vgroup.c
@@ -937,6 +937,60 @@ float ED_vgroup_vert_weight(Object *ob, bDeformGroup *dg, int vertnum)
 	return get_vert_def_nr(ob, def_nr, vertnum);
 }
 
+float ED_vgroup_combined_vert_weight(const Object *ob, const int vertnum, const int mode)
+{
+	MDeformVert *dv = NULL;
+
+	/* get the deform vertices corresponding to the vertnum */
+	if (ob->type == OB_MESH) {
+		Mesh *me = ob->data;
+
+		if (me->edit_btmesh) {
+			BMEditMesh *em = me->edit_btmesh;
+			const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT);
+			/* warning, this lookup is _not_ fast */
+
+			if (cd_dvert_offset != -1 && vertnum < em->bm->totvert) {
+				BMVert *eve;
+				BM_mesh_elem_table_ensure(em->bm, BM_VERT);
+				eve = BM_vert_at_index(em->bm, vertnum);
+				dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset);
+			}
+			else {
+				return -1.0f;
+			}
+		}
+		else {
+			if (vertnum < me->totvert) {
+				if (me->dvert) {
+					dv = &me->dvert[vertnum];
+				}
+			}
+			else {
+				return -1.0f;
+			}
+		}
+	}
+	else if (ob->type == OB_LATTICE) {
+		Lattice *lt = vgroup_edit_lattice((Object *)ob);
+
+		if (vertnum < lt->pntsu * lt->pntsv * lt->pntsw) {
+			if (lt->dvert) {
+				dv = &lt->dvert[vertnum];
+			}
+		}
+		else {
+			return -1.0f;
+		}
+	}
+
+	if (dv) {
+		return BKE_defvert_combined_weight(ob, dv, mode);
+	}
+
+	return 0.0f;
+}
+
 void ED_vgroup_select_by_name(Object *ob, const char *name)
 {   /* note: ob->actdef==0 signals on painting to create a new one, if a bone in posemode is selected */
 	ob->actdef = defgroup_name_index(ob, name) + 1;
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index d24c7faa9f5..ac688a6574a 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -63,7 +63,8 @@ typedef struct bDeformGroup {
 	struct bDeformGroup *next, *prev;
 	char name[64];	/* MAX_VGROUP_NAME */
 	/* need this flag for locking weights */
-	char flag, pad[7];
+	char flag, pad[3];
+	float influence;
 } bDeformGroup;
 #define MAX_VGROUP_NAME 64
 
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 0e735350e05..34a1e5f7e3b 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -47,6 +47,7 @@
 #include "BKE_editmesh.h"
 #include "BKE_group.h" /* needed for BKE_group_object_exists() */
 #include "BKE_object_deform.h"
+#include "BKE_deform.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -953,6 +954,11 @@ static char *rna_MaterialSlot_path(PointerRNA *ptr)
 	return BLI_sprintfN("material_slots[%d]", index);
 }
 
+static char *rna_VertexGroup_path(PointerRNA *ptr)
+{
+	return BLI_sprintfN("vertex_groups[%d]", rna_VertexGroup_index_get(ptr));
+}
+
 /* why does this have to be so complicated?, can't all this crap be
  * moved to in BGE conversion function? - Campbell *
  *
@@ -1420,6 +1426,17 @@ static void rna_Object_vgroup_clear(Object *ob)
 	WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
 }
 
+static float rna_Object_combined_vgroup_weight(Object *ob, ReportList *reports, int index, int mode)
+{
+	float weight = ED_vgroup_combined_vert_weight(ob, index, mode);
+
+	if (weight < 0) {
+		BKE_report(reports, RPT_ERROR, "Vertex index not in range");
+	}
+
+	return weight;
+}
+
 static void rna_VertexGroup_vertex_add(ID *id, bDeformGroup *def, ReportList *reports, int index_len,
                                        int *index, float weight, int assignmode)
 {
@@ -1552,6 +1569,14 @@ static void rna_def_vertex_group(BlenderRNA *brna)
 	RNA_def_property_int_funcs(prop, "rna_VertexGroup_index_get", NULL, NULL);
 	RNA_def_property_ui_text(prop, "Index", "Index number of the vertex group");
 
+	prop = RNA_def_property(srna, "influence", PROP_FLOAT, PROP_FACTOR);
+	RNA_def_property_float_sdna(prop, NULL, "influence");
+	RNA_def_property_range(prop, 0.0f, 1.0f);
+	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 3);
+	RNA_def_property_ui_text(prop, "Influence", "Influence of the vertex group on the combined group");
+	RNA_def_property_update(prop, NC_GEOM | ND_DATA | NA_RENAME, "rna_Object_internal_update_data");
+	RNA_def_property_flag(prop, PROP_ANIMATABLE);
+
 	func = RNA_def_function(srna, "add", "rna_VertexGroup_vertex_add");
 	RNA_def_function_ui_description(func, "Add vertices to the group");
 	RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
@@ -1577,6 +1602,8 @@ static void rna_def_vertex_group(BlenderRNA *brna)
 	RNA_def_property_flag(prop, PROP_REQUIRED);
 	prop = RNA_def_float(func, "weight", 0, 0.0f, 1.0f, "", "Vertex weight", 0.0f, 1.0f);
 	RNA_def_function_return(func, prop);
+
+	RNA_def_struct_path_func(srna, "rna_VertexGroup_path");
 }
 
 static void rna_def_material_slot(BlenderRNA *brna)
@@ -2067,6 +2094,12 @@ static void rna_def_object_vertex_groups(BlenderRNA *brna, PropertyRNA *cprop)
 	FunctionRNA *func;
 	PropertyRNA *parm;
 
+	static EnumPropertyItem combined_vertex_group_mode[] = {
+		{DVERT_COMBINED_MODE_ADD, "ADD", 0, "Add", "Add"},
+		{DVERT_COMBINED_MODE_MIX, "MIX", 0, "Mix", "Mix"},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	RNA_def_property_srna(cprop, "VertexGroups");
 	srna = RNA_def_struct(brna, "VertexGroups", NULL);
 	RNA_def_struct_sdna(srna, "Object");
@@ -2104,6 +2137,15 @@ static void rna_def_object_vertex_groups(BlenderRNA *brna, PropertyRNA *cprop)
 
 	func = RNA_def_function(srna, "clear", "rna_Object_vgroup_clear");
 	RNA_def_

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list