Added a VGroup input to the Armature modifier. This allows the user to specify
authorBen Batt <benbatt@gmail.com>
Mon, 28 Aug 2006 21:56:58 +0000 (21:56 +0000)
committerBen Batt <benbatt@gmail.com>
Mon, 28 Aug 2006 21:56:58 +0000 (21:56 +0000)
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.

source/blender/blenkernel/BKE_lattice.h
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/modifier.c
source/blender/makesdna/DNA_modifier_types.h
source/blender/src/buttons_editing.c
source/gameengine/Converter/BL_SkinDeformer.cpp

index a7533a614eb8eb25e9b33cf0a76655a3563c4c6d..f422d00d857de90f0111d716eee4525a2c7003c2 100644 (file)
@@ -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);
index 545efdf10e6b377ae147cc1e031de58b70b90ad2..cab7bf3090887ceaf7c258c6c33f55bc8e626fc2 100644 (file)
@@ -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);
index 9e43e30fa7c55daf2052761a5010800c4d50d764..e2bf80402924da3dfdafffd2b8c6bb79607740ce 100644 (file)
@@ -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);
 }
index 522d25c9d90a60bf20489c15d669060a21b33043..dee183ec353962ae580b5b03c8a9cf9d899488f8 100644 (file)
@@ -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 {
index ad066544442481a922e32ee68041f040fb16da98..3c46dbda0ea7b2cee31e6b5f8389230e0790503e 100644 (file)
@@ -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");
                        
index b291331c378c5eaba03ee03e0828fbdd99d5e012..d8e5a255a7cddb2c9d8f0b40a21f4323448e09aa 100644 (file)
@@ -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 */