[Bf-blender-cvs] [8768cd6a6a9] master: Curve Modifier add invert vgroup option

Cody Winchester noreply at git.blender.org
Thu Feb 6 11:51:07 CET 2020


Commit: 8768cd6a6a98a710ed2b6d8b257c43dd0e6e58ee
Author: Cody Winchester
Date:   Thu Feb 6 11:46:41 2020 +0100
Branches: master
https://developer.blender.org/rB8768cd6a6a98a710ed2b6d8b257c43dd0e6e58ee

Curve Modifier add invert vgroup option

Adds the invert vertex group option to the Curve modifier.

Adds a short flag and char pad to the Curve modifier DNA. Passes the flag into the curve_deform_verts function as the weight values are found there and not in the modifiers .c file.

Reviewed By: mont29

Differential Revision: https://developer.blender.org/D6746

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_lattice.h
M	source/blender/blenkernel/intern/lattice.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_curve.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 330f05205fc..a8b9de409c2 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -316,7 +316,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.prop(md, "object", text="")
         col = split.column()
         col.label(text="Vertex Group:")
-        col.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
+        row = col.row(align=True)
+        row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
+        row.prop(md, "invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
         layout.label(text="Deformation Axis:")
         layout.row().prop(md, "deform_axis", expand=True)
 
diff --git a/source/blender/blenkernel/BKE_lattice.h b/source/blender/blenkernel/BKE_lattice.h
index 6a55ffe7b9f..a426a449ae8 100644
--- a/source/blender/blenkernel/BKE_lattice.h
+++ b/source/blender/blenkernel/BKE_lattice.h
@@ -62,6 +62,7 @@ void curve_deform_verts(struct Object *cuOb,
                         int numVerts,
                         struct MDeformVert *dvert,
                         const int defgrp_index,
+                        short flag,
                         short defaxis);
 void curve_deform_vector(struct Object *cuOb,
                          struct Object *target,
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 17b705c55c2..243c63a8f03 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -749,12 +749,14 @@ void curve_deform_verts(Object *cuOb,
                         int numVerts,
                         MDeformVert *dvert,
                         const int defgrp_index,
+                        short flag,
                         short defaxis)
 {
   Curve *cu;
   int a;
   CurveDeform cd;
   const bool is_neg_axis = (defaxis > 2);
+  const bool invert_vgroup = (flag & MOD_CURVE_INVERT_VGROUP) != 0;
 
   if (cuOb->type != OB_CURVE) {
     return;
@@ -781,7 +783,8 @@ void curve_deform_verts(Object *cuOb,
 
     if (cu->flag & CU_DEFORM_BOUNDS_OFF) {
       for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) {
-        const float weight = defvert_find_weight(dvert_iter, defgrp_index);
+        const float weight = invert_vgroup? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) :
+                                             defvert_find_weight(dvert_iter, defgrp_index);
 
         if (weight > 0.0f) {
           mul_m4_v3(cd.curvespace, vert_coords[a]);
@@ -797,14 +800,17 @@ void curve_deform_verts(Object *cuOb,
       INIT_MINMAX(cd.dmin, cd.dmax);
 
       for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) {
-        if (defvert_find_weight(dvert_iter, defgrp_index) > 0.0f) {
+        const float weight = invert_vgroup? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) :
+                                             defvert_find_weight(dvert_iter, defgrp_index);
+        if (weight > 0.0f) {
           mul_m4_v3(cd.curvespace, vert_coords[a]);
           minmax_v3v3_v3(cd.dmin, cd.dmax, vert_coords[a]);
         }
       }
 
       for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) {
-        const float weight = defvert_find_weight(dvert_iter, defgrp_index);
+        const float weight = invert_vgroup? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) :
+                                             defvert_find_weight(dvert_iter, defgrp_index);
 
         if (weight > 0.0f) {
           /* already in 'cd.curvespace', prev for loop */
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 631a995c743..135ddd8f62f 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -199,9 +199,15 @@ typedef struct CurveModifierData {
   char name[64];
   /** Axis along which curve deforms. */
   short defaxis;
-  char _pad[6];
+  short flag;
+  char _pad[4];
 } CurveModifierData;
 
+/* Curve modifier flags */
+enum {
+  MOD_CURVE_INVERT_VGROUP = (1 << 0),
+};
+
 /* CurveModifierData->defaxis */
 enum {
   MOD_CURVE_POSX = 1,
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index aebee811428..5b7db50ca02 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -1985,6 +1985,11 @@ static void rna_def_modifier_curve(BlenderRNA *brna)
   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_CurveModifier_name_set");
   RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+  prop = RNA_def_property(srna, "invert_vertex_group", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_CURVE_INVERT_VGROUP);
+  RNA_def_property_ui_text(prop, "Invert", "Invert vertex group influence");
+  RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
   prop = RNA_def_property(srna, "deform_axis", PROP_ENUM, PROP_NONE);
   RNA_def_property_enum_sdna(prop, NULL, "defaxis");
   RNA_def_property_enum_items(prop, prop_deform_axis_items);
diff --git a/source/blender/modifiers/intern/MOD_curve.c b/source/blender/modifiers/intern/MOD_curve.c
index f9137572d6f..7bfe63e562a 100644
--- a/source/blender/modifiers/intern/MOD_curve.c
+++ b/source/blender/modifiers/intern/MOD_curve.c
@@ -120,7 +120,7 @@ static void deformVerts(ModifierData *md,
   /* silly that defaxis and curve_deform_verts are off by 1
    * but leave for now to save having to call do_versions */
   curve_deform_verts(
-      cmd->object, ctx->object, vertexCos, numVerts, dvert, defgrp_index, cmd->defaxis - 1);
+      cmd->object, ctx->object, vertexCos, numVerts, dvert, defgrp_index, cmd->flag, cmd->defaxis - 1);
 
   if (!ELEM(mesh_src, NULL, mesh)) {
     BKE_id_free(NULL, mesh_src);



More information about the Bf-blender-cvs mailing list