Fix for weight painting errors, as reported by Bassam.
authorTon Roosendaal <ton@blender.org>
Wed, 7 Sep 2005 18:07:24 +0000 (18:07 +0000)
committerTon Roosendaal <ton@blender.org>
Wed, 7 Sep 2005 18:07:24 +0000 (18:07 +0000)
- Undo/Redo didn't work
- Crash on using weightpaint with Armature-modifier (instead of parent).

Note: checking if an object is being deformed cannot be simply done with
checking for a parent anymore... for this a call in modifier.c has been
added; modifiers_isDeformedByArmature(Object *). It even returns the
Armature object pointer.

source/blender/blenkernel/BKE_modifier.h
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/modifier.c
source/blender/src/buttons_object.c
source/blender/src/editarmature.c
source/blender/src/editdeform.c
source/blender/src/vpaint.c

index e600c0752fb03ca11fe82b04efb9b5cda657ddcd..55a09fcd158cbfed900dc89ee7ff9bbd6ee2b22d 100644 (file)
@@ -201,7 +201,7 @@ void                        modifiers_clearErrors           (struct Object *ob);
 int                            modifiers_getCageIndex          (struct Object *ob, int *lastPossibleCageIndex_r);
 
 int                            modifiers_isSoftbodyEnabled     (struct Object *ob);
-int                            modifiers_isDeformedByArmature(struct Object *ob, struct Object *armOb);
+struct Object* modifiers_isDeformedByArmature(struct Object *ob);
 
 ModifierData*  modifiers_getVirtualModifierList        (struct Object *ob);
 
index 7c6f6a67be74321c1b8533e29d9020e4b9e141bf..fb36cfdf02000d02717fb5ced79f4c2d4eead022 100644 (file)
@@ -728,8 +728,10 @@ void armature_deform_verts(Object *armOb, Object *target, float (*vertexCos)[3],
                                pchan = defnrToPC[dvert->dw[j].def_nr];
                                if (pchan) {
                                        float weight= dvert->dw[j].weight;
-                                       if(pchan->bone->flag & BONE_MULT_VG_ENV) {
-                                               Bone *bone= pchan->bone;
+                                       Bone *bone= pchan->bone;
+                                       
+                                       if(bone && bone->flag & BONE_MULT_VG_ENV) {
+                                               
                                                weight*= distfactor_to_bone(co, bone->arm_head, bone->arm_tail, bone->rad_head, bone->rad_tail, bone->dist);
                                        }
                                        pchan_bone_deform(pchan, weight, vec, co, &contrib);
index cc24f4200981e4d60de52060deb9948bea4630c4..f5fe534c0b33bd1a427a935836d1a1b2d546df20 100644 (file)
@@ -1494,18 +1494,20 @@ ModifierData *modifiers_getVirtualModifierList(Object *ob)
        return ob->modifiers.first;
 }
 
-int modifiers_isDeformedByArmature(Object *ob, Object *armOb)
+Object *modifiers_isDeformedByArmature(Object *ob)
 {
        ModifierData *md = modifiers_getVirtualModifierList(ob);
 
        for (; md; md=md->next) {
                if (md->type==eModifierType_Armature) {
                        ArmatureModifierData *amd = (ArmatureModifierData*) md;
-
-                       if (amd->object==armOb)
-                               return 1;
+                       return amd->object;
                }
        }
+       
+       if(ob->parent && ob->parent->type==OB_ARMATURE)
+               if(ob->partype==PARSKEL)
+                       return ob->parent;
 
-       return 0;
+       return NULL;
 }
\ No newline at end of file
index 63916adc43197d0b50c14bb65f8148f403f82e44..d1455afc879514619625616f33bade94ff797ae9 100644 (file)
@@ -685,7 +685,7 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
                                        strcpy (data->subtarget, "");
                                uiBlockEndAlign(block);
 
-                               but=uiDefButBitI(block, TOG, 1, B_CONSTRAINT_TEST, "Sticky", *xco, *yco-24, 54, 18, &data->sticky, 0, 24, 0, 0, "Immobilize object while constrained");
+                               but=uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "Sticky", *xco, *yco-24, 54, 18, &data->sticky, 0, 24, 0, 0, "Immobilize object while constrained");
                                
                                uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Max/Min:", *xco-8, *yco-64, 54, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
 
index ec992db6531c7f5c696940e7e6e0247dd42fd126..8c7e386ba255945099a4f54f5f4730815e1b0d11 100644 (file)
@@ -2400,7 +2400,7 @@ static void constraint_bone_name_fix(Object *ob, ListBase *conlist, char *oldnam
 /* seems messy, but thats what you get with not using pointers but channel names :) */
 void armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
 {
-       Object *ob;
+       Object *ob, *modob;
        char newname[MAXBONENAME];
        char oldname[MAXBONENAME];
        
@@ -2481,13 +2481,15 @@ void armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
                                        if (!strcmp(ob->parsubstr, oldname))
                                                BLI_strncpy(ob->parsubstr, newname, MAXBONENAME);
                                }
-                               else if(ob->partype==PARSKEL) {
-                                       bDeformGroup *dg;
-                                       /* bone name in defgroup */
-                                       for (dg=ob->defbase.first; dg; dg=dg->next) {
-                                               if(!strcmp(dg->name, oldname))
-                                                  BLI_strncpy(dg->name, newname, MAXBONENAME);
-                                       }
+                       }
+                       /* or is there an armature deforming object */
+                       modob = modifiers_isDeformedByArmature(ob);
+                       if(modob) {
+                               bDeformGroup *dg;
+                               /* bone name in defgroup */
+                               for (dg=ob->defbase.first; dg; dg=dg->next) {
+                                       if(!strcmp(dg->name, oldname))
+                                          BLI_strncpy(dg->name, newname, MAXBONENAME);
                                }
                        }
                }
index 97988a5c47c0df9ec3d8b0fa237654aea45da3a9..36709948be9352da5e28b22046837601a5cacc43 100644 (file)
@@ -109,7 +109,7 @@ the specified defweight group */
        int     i;
        MDeformWeight *newdw;
 
-       if (!dv)
+       if (!dv || defgroup<0)
                return NULL;
 
        for (i=0; i<dv->totweight; i++){
index 8b9f2be186778c57307935085b94e89321a1d87d..77a839f08699384bc46bac6b9e54da42487ba01e 100644 (file)
@@ -55,6 +55,7 @@
 #include "DNA_armature_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
 #include "DNA_object_force.h"
 #include "DNA_screen_types.h"
@@ -68,6 +69,7 @@
 #include "BKE_displist.h"
 #include "BKE_global.h"
 #include "BKE_mesh.h"
+#include "BKE_modifier.h"
 #include "BKE_object.h"
 #include "BKE_utildefines.h"
 
@@ -734,7 +736,8 @@ void wpaint_undo (void)
        /* now free previous mesh dverts */
        free_dverts(swapbuf, me->totvert);
 
-       DAG_object_flush_update(G.scene, ob->parent, OB_RECALC_DATA);
+       DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
+       DAG_object_flush_update(G.scene, modifiers_isDeformedByArmature(ob), OB_RECALC_DATA);
        scrarea_do_windraw(curarea);
        
 }
@@ -911,11 +914,13 @@ void weight_paint(void)
        /* if nothing was added yet, we make dverts and a vertex deform group */
        if (!me->dvert)
                create_dverts(me);
+       
        /* this happens on a Bone select, when no vgroup existed yet */
        if(ob->actdef==0) {
-               if(ob->parent && (ob->parent->flag & OB_POSEMODE)) {
+               Object *modob;
+               if(modob = modifiers_isDeformedByArmature(ob)) {
                        bPoseChannel *pchan;
-                       for(pchan= ob->parent->pose->chanbase.first; pchan; pchan= pchan->next)
+                       for(pchan= modob->pose->chanbase.first; pchan; pchan= pchan->next)
                                if(pchan->bone->flag & SELECT)
                                        break;
                        if(pchan) {