forked from bartvdbraak/blender
Added a VGroup input to the Armature modifier. This allows the user to specify
a vertex group which will modulate the influence of all bones in the armature. This commit also tidies up the height of the modifier panels; they should all have the same size margin now.
This commit is contained in:
parent
dd8c56e077
commit
12a732fc20
@ -59,7 +59,8 @@ void lattice_deform_verts(struct Object *laOb, struct Object *target,
|
||||
int numVerts, char *vgroup);
|
||||
void armature_deform_verts(struct Object *armOb, struct Object *target,
|
||||
struct DerivedMesh *dm, float (*vertexCos)[3],
|
||||
int numVerts, int deformflag);
|
||||
int numVerts, int deformflag,
|
||||
const char *defgrp_name);
|
||||
float (*lattice_getVertexCos(struct Object *ob, int *numVerts_r))[3];
|
||||
void lattice_applyVertexCos(struct Object *ob, float (*vertexCos)[3]);
|
||||
void lattice_calc_modifiers(struct Object *ob);
|
||||
|
@ -663,7 +663,8 @@ static void pchan_bone_deform(bPoseChannel *pchan, float weight, float *vec, flo
|
||||
}
|
||||
|
||||
void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm,
|
||||
float (*vertexCos)[3], int numVerts, int deformflag)
|
||||
float (*vertexCos)[3], int numVerts, int deformflag,
|
||||
const char *defgrp_name)
|
||||
{
|
||||
bPoseChannel *pchan, **defnrToPC = NULL;
|
||||
MDeformVert *dverts = NULL;
|
||||
@ -672,6 +673,8 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm,
|
||||
int numGroups = 0; /* safety for vertexgroup index overflow too */
|
||||
int i;
|
||||
int use_dverts = 0;
|
||||
int armature_def_nr = -1;
|
||||
bDeformGroup *dg;
|
||||
|
||||
if(armOb == G.obedit) return;
|
||||
|
||||
@ -690,11 +693,14 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm,
|
||||
pchan_b_bone_defmats(pchan);
|
||||
}
|
||||
|
||||
/* get the def_nr for the overall armature vertex group if present */
|
||||
for(i = 0, dg = target->defbase.first; dg; i++, dg = dg->next)
|
||||
if(defgrp_name && strcmp(defgrp_name, dg->name) == 0)
|
||||
armature_def_nr = i;
|
||||
|
||||
/* get a vertex-deform-index to posechannel array */
|
||||
if(deformflag & ARM_DEF_VGROUP) {
|
||||
if(target->type == OB_MESH){
|
||||
bDeformGroup *dg;
|
||||
|
||||
numGroups = BLI_countlist(&target->defbase);
|
||||
dverts = ((Mesh*)target->data)->dvert;
|
||||
|
||||
@ -727,19 +733,33 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm,
|
||||
float vec[3];
|
||||
float contrib = 0.0;
|
||||
int j;
|
||||
float armature_weight = 1; /* default to 1 if no overall def group */
|
||||
|
||||
vec[0] = vec[1] = vec[2] = 0;
|
||||
|
||||
/* Apply the object's matrix */
|
||||
Mat4MulVecfl(premat, co);
|
||||
|
||||
if(use_dverts) {
|
||||
if(use_dverts || armature_def_nr >= 0) {
|
||||
if(dm) dvert = dm->getVertData(dm, i, LAYERTYPE_MDEFORMVERT);
|
||||
else if(i < ((Mesh*)target->data)->totvert) dvert = dverts + i;
|
||||
} else
|
||||
dvert = NULL;
|
||||
|
||||
if(armature_def_nr >= 0 && dvert) {
|
||||
armature_weight = 0; /* a def group was given, so default to 0 */
|
||||
for(j = 0; j < dvert->totweight; j++) {
|
||||
if(dvert->dw[j].def_nr == armature_def_nr) {
|
||||
armature_weight = dvert->dw[j].weight;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* check if there's any point in calculating for this vert */
|
||||
if(armature_weight == 0) continue;
|
||||
|
||||
if(dvert && dvert->totweight) { // use weight groups ?
|
||||
if(use_dverts && dvert && dvert->totweight) { // use weight groups ?
|
||||
int deformed = 0;
|
||||
|
||||
for(j = 0; j < dvert->totweight; j++){
|
||||
@ -780,11 +800,8 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm,
|
||||
}
|
||||
}
|
||||
|
||||
if(contrib > 0.0){
|
||||
vec[0] /= contrib;
|
||||
vec[1] /= contrib;
|
||||
vec[2] /= contrib;
|
||||
}
|
||||
if(contrib > 0.0)
|
||||
VecMulf(vec, armature_weight / contrib);
|
||||
|
||||
VecAddf(co, vec, co);
|
||||
Mat4MulVecfl(postmat, co);
|
||||
|
@ -2976,7 +2976,7 @@ static void armatureModifier_deformVerts(
|
||||
ArmatureModifierData *amd = (ArmatureModifierData*) md;
|
||||
|
||||
armature_deform_verts(amd->object, ob, derivedData, vertexCos, numVerts,
|
||||
amd->deformflag);
|
||||
amd->deformflag, amd->defgrp_name);
|
||||
}
|
||||
|
||||
static void armatureModifier_deformVertsEM(
|
||||
@ -2989,7 +2989,7 @@ static void armatureModifier_deformVertsEM(
|
||||
if(!derivedData) dm = CDDM_from_editmesh(editData, ob->data);
|
||||
|
||||
armature_deform_verts(amd->object, ob, dm, vertexCos, numVerts,
|
||||
amd->deformflag);
|
||||
amd->deformflag, amd->defgrp_name);
|
||||
|
||||
if(!derivedData) dm->release(dm);
|
||||
}
|
||||
|
@ -226,6 +226,7 @@ typedef struct ArmatureModifierData {
|
||||
short deformflag, pad1; /* deformflag replaces armature->deformflag */
|
||||
int pad2;
|
||||
struct Object *object;
|
||||
char defgrp_name[32];
|
||||
} ArmatureModifierData;
|
||||
|
||||
typedef struct HookModifierData {
|
||||
|
@ -1310,29 +1310,29 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
|
||||
int lx = x + width - 60 - 15;
|
||||
|
||||
if (md->type==eModifierType_Subsurf) {
|
||||
height = 106;
|
||||
height = 105;
|
||||
} else if (md->type==eModifierType_Lattice) {
|
||||
height = 46;
|
||||
height = 48;
|
||||
} else if (md->type==eModifierType_Curve) {
|
||||
height = 46;
|
||||
height = 48;
|
||||
} else if (md->type==eModifierType_Build) {
|
||||
height = 86;
|
||||
} else if (md->type==eModifierType_Mirror) {
|
||||
height = 46;
|
||||
height = 48;
|
||||
} else if (md->type==eModifierType_EdgeSplit) {
|
||||
height = 46;
|
||||
height = 48;
|
||||
} else if (md->type==eModifierType_Displace) {
|
||||
DisplaceModifierData *dmd = (DisplaceModifierData *)md;
|
||||
height = 134;
|
||||
height = 124;
|
||||
if(dmd->texmapping == MOD_DISP_MAP_OBJECT) height += 19;
|
||||
} else if (md->type==eModifierType_UVProject) {
|
||||
height = 67 + ((UVProjectModifierData *)md)->num_projectors * 19;
|
||||
} else if (md->type==eModifierType_Decimate) {
|
||||
height = 46;
|
||||
height = 48;
|
||||
} else if (md->type==eModifierType_Wave) {
|
||||
height = 200;
|
||||
} else if (md->type==eModifierType_Armature) {
|
||||
height = 46;
|
||||
height = 67;
|
||||
} else if (md->type==eModifierType_Hook) {
|
||||
HookModifierData *hmd = (HookModifierData*) md;
|
||||
height = 86;
|
||||
@ -1343,9 +1343,9 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
|
||||
} else if (md->type==eModifierType_Softbody) {
|
||||
height = 26;
|
||||
} else if (md->type==eModifierType_Boolean) {
|
||||
height = 46;
|
||||
height = 48;
|
||||
} else if (md->type==eModifierType_Array) {
|
||||
height = 186;
|
||||
height = 182;
|
||||
}
|
||||
|
||||
/* roundbox 4 free variables: corner-rounding, nop, roundbox type, shade */
|
||||
@ -1512,6 +1512,8 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
|
||||
ArmatureModifierData *amd = (ArmatureModifierData*) md;
|
||||
uiDefIDPoinBut(block, modifier_testArmatureObj, ID_OB, B_CHANGEDEP, "Ob: ", lx, (cy-=19), buttonWidth,19, &amd->object, "Armature object to deform with");
|
||||
|
||||
but=uiDefBut(block, TEX, B_MODIFIER_RECALC, "VGroup: ", lx, (cy-=19), buttonWidth,19, &amd->defgrp_name, 0.0, 31.0, 0, 0, "Vertex Group name to control overall armature influence");
|
||||
uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ob);
|
||||
uiDefButBitS(block, TOG, ARM_DEF_VGROUP, B_ARM_RECALCDATA, "Vert.Groups", lx,cy-=19,buttonWidth/2,20, &amd->deformflag, 0, 0, 0, 0, "Enable VertexGroups defining deform");
|
||||
uiDefButBitS(block, TOG, ARM_DEF_ENVELOPE, B_ARM_RECALCDATA, "Envelopes", lx+buttonWidth/2,cy,(buttonWidth + 1)/2,20, &amd->deformflag, 0, 0, 0, 0, "Enable Bone Envelopes defining deform");
|
||||
|
||||
|
@ -175,7 +175,7 @@ void BL_SkinDeformer::Update(void)
|
||||
for (int v =0; v<m_bmesh->totvert; v++)
|
||||
VECCOPY(m_transverts[v], m_bmesh->mvert[v].co);
|
||||
|
||||
armature_deform_verts( par_arma, m_objMesh, NULL, m_transverts, m_bmesh->totvert, ARM_DEF_VGROUP );
|
||||
armature_deform_verts( par_arma, m_objMesh, NULL, m_transverts, m_bmesh->totvert, ARM_DEF_VGROUP, NULL );
|
||||
RecalcNormals();
|
||||
|
||||
/* Update the current frame */
|
||||
|
Loading…
Reference in New Issue
Block a user