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
This commit is contained in:
Cody Winchester 2020-02-06 11:46:41 +01:00 committed by Bastien Montagne
parent 2abe733771
commit 8768cd6a6a
6 changed files with 26 additions and 6 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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 */

View File

@ -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,

View File

@ -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);

View File

@ -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);