Lattice Modifier add invert vgroup option
Adds the invert vertex group option to the Lattice modifier. Adds a short flag and modifies the existing char padding for the correct amount. Adds a .invert_vgroup to the LatticeDeformUserdata. Passes the flag into the lattice_deform_verts function where the weights around found and used. For the other calls of lattice_deform_verts function they pass in NULL for the flag in the same way they pass NULL for the vgroup name. Reviewed By: mont29 Differential Revision: https://developer.blender.org/D6747
This commit is contained in:
@@ -532,7 +532,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
|
|||||||
|
|
||||||
col = split.column()
|
col = split.column()
|
||||||
col.label(text="Vertex Group:")
|
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.separator()
|
layout.separator()
|
||||||
layout.prop(md, "strength", slider=True)
|
layout.prop(md, "strength", slider=True)
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ void lattice_deform_verts(struct Object *laOb,
|
|||||||
struct Mesh *mesh,
|
struct Mesh *mesh,
|
||||||
float (*vert_coords)[3],
|
float (*vert_coords)[3],
|
||||||
int numVerts,
|
int numVerts,
|
||||||
|
short flag,
|
||||||
const char *vgroup,
|
const char *vgroup,
|
||||||
float influence);
|
float influence);
|
||||||
void armature_deform_verts(struct Object *armOb,
|
void armature_deform_verts(struct Object *armOb,
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb)
|
|||||||
|
|
||||||
copy_m4_m4(mat, ltOb->obmat);
|
copy_m4_m4(mat, ltOb->obmat);
|
||||||
unit_m4(ltOb->obmat);
|
unit_m4(ltOb->obmat);
|
||||||
lattice_deform_verts(ltOb, NULL, NULL, vert_coords, uNew * vNew * wNew, NULL, 1.0f);
|
lattice_deform_verts(ltOb, NULL, NULL, vert_coords, uNew * vNew * wNew, 0, NULL, 1.0f);
|
||||||
copy_m4_m4(ltOb->obmat, mat);
|
copy_m4_m4(ltOb->obmat, mat);
|
||||||
|
|
||||||
lt->typeu = typeu;
|
lt->typeu = typeu;
|
||||||
@@ -883,6 +883,7 @@ typedef struct LatticeDeformUserdata {
|
|||||||
MDeformVert *dvert;
|
MDeformVert *dvert;
|
||||||
int defgrp_index;
|
int defgrp_index;
|
||||||
float fac;
|
float fac;
|
||||||
|
bool invert_vgroup;
|
||||||
} LatticeDeformUserdata;
|
} LatticeDeformUserdata;
|
||||||
|
|
||||||
static void lattice_deform_vert_task(void *__restrict userdata,
|
static void lattice_deform_vert_task(void *__restrict userdata,
|
||||||
@@ -892,7 +893,8 @@ static void lattice_deform_vert_task(void *__restrict userdata,
|
|||||||
const LatticeDeformUserdata *data = userdata;
|
const LatticeDeformUserdata *data = userdata;
|
||||||
|
|
||||||
if (data->dvert != NULL) {
|
if (data->dvert != NULL) {
|
||||||
const float weight = defvert_find_weight(data->dvert + index, data->defgrp_index);
|
const float weight = data->invert_vgroup? 1.0f - defvert_find_weight(data->dvert + index, data->defgrp_index) :
|
||||||
|
defvert_find_weight(data->dvert + index, data->defgrp_index);
|
||||||
if (weight > 0.0f) {
|
if (weight > 0.0f) {
|
||||||
calc_latt_deform(data->lattice_deform_data, data->vert_coords[index], weight * data->fac);
|
calc_latt_deform(data->lattice_deform_data, data->vert_coords[index], weight * data->fac);
|
||||||
}
|
}
|
||||||
@@ -907,6 +909,7 @@ void lattice_deform_verts(Object *laOb,
|
|||||||
Mesh *mesh,
|
Mesh *mesh,
|
||||||
float (*vert_coords)[3],
|
float (*vert_coords)[3],
|
||||||
int numVerts,
|
int numVerts,
|
||||||
|
short flag,
|
||||||
const char *vgroup,
|
const char *vgroup,
|
||||||
float fac)
|
float fac)
|
||||||
{
|
{
|
||||||
@@ -946,6 +949,7 @@ void lattice_deform_verts(Object *laOb,
|
|||||||
.dvert = dvert,
|
.dvert = dvert,
|
||||||
.defgrp_index = defgrp_index,
|
.defgrp_index = defgrp_index,
|
||||||
.fac = fac,
|
.fac = fac,
|
||||||
|
.invert_vgroup = (flag & MOD_LATTICE_INVERT_VGROUP) != 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
TaskParallelSettings settings;
|
TaskParallelSettings settings;
|
||||||
@@ -962,7 +966,7 @@ bool object_deform_mball(Object *ob, ListBase *dispbase)
|
|||||||
DispList *dl;
|
DispList *dl;
|
||||||
|
|
||||||
for (dl = dispbase->first; dl; dl = dl->next) {
|
for (dl = dispbase->first; dl; dl = dl->next) {
|
||||||
lattice_deform_verts(ob->parent, ob, NULL, (float(*)[3])dl->verts, dl->nr, NULL, 1.0f);
|
lattice_deform_verts(ob->parent, ob, NULL, (float(*)[3])dl->verts, dl->nr, 0, NULL, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -182,9 +182,15 @@ typedef struct LatticeModifierData {
|
|||||||
/** Optional vertexgroup name, MAX_VGROUP_NAME. */
|
/** Optional vertexgroup name, MAX_VGROUP_NAME. */
|
||||||
char name[64];
|
char name[64];
|
||||||
float strength;
|
float strength;
|
||||||
char _pad[4];
|
short flag;
|
||||||
|
char _pad[2];
|
||||||
} LatticeModifierData;
|
} LatticeModifierData;
|
||||||
|
|
||||||
|
/*Lattice modifier flags */
|
||||||
|
enum {
|
||||||
|
MOD_LATTICE_INVERT_VGROUP = (1 << 0),
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct CurveModifierData {
|
typedef struct CurveModifierData {
|
||||||
ModifierData modifier;
|
ModifierData modifier;
|
||||||
|
|
||||||
|
|||||||
@@ -1936,6 +1936,11 @@ static void rna_def_modifier_lattice(BlenderRNA *brna)
|
|||||||
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_LatticeModifier_name_set");
|
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_LatticeModifier_name_set");
|
||||||
RNA_def_property_update(prop, 0, "rna_Modifier_update");
|
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_LATTICE_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, "strength", PROP_FLOAT, PROP_NONE);
|
prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
|
||||||
RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
|
RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
|
||||||
RNA_def_property_ui_range(prop, 0, 1, 10, 2);
|
RNA_def_property_ui_range(prop, 0, 1, 10, 2);
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ static void deformVerts(ModifierData *md,
|
|||||||
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
|
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
|
||||||
|
|
||||||
lattice_deform_verts(
|
lattice_deform_verts(
|
||||||
lmd->object, ctx->object, mesh_src, vertexCos, numVerts, lmd->name, lmd->strength);
|
lmd->object, ctx->object, mesh_src, vertexCos, numVerts, lmd->flag, lmd->name, lmd->strength);
|
||||||
|
|
||||||
if (!ELEM(mesh_src, NULL, mesh)) {
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
||||||
BKE_id_free(NULL, mesh_src);
|
BKE_id_free(NULL, mesh_src);
|
||||||
|
|||||||
Reference in New Issue
Block a user