Fix #35347: constraints with vertex group targets were not using the vertex group
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 14 May 2013 16:22:53 +0000 (16:22 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 14 May 2013 16:22:53 +0000 (16:22 +0000)
weights, it assumed all weights were 1. This gave very different results with the
new bevel modifier due to slightly different vertex group interpolation.

source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/customdata.c

index af5a20e97b46aa1b3a29cb7dc850726debf67da3..cee796c4cab0ee10e0add26547f9e6cc71b21e07 100644 (file)
@@ -380,29 +380,31 @@ static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[
        if (dm) {
                MDeformVert *dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
                int numVerts = dm->getNumVerts(dm);
-               int i, count = 0;
+               int i;
                float co[3], nor[3];
                
                /* check that dvert is a valid pointers (just in case) */
                if (dvert) {
                        MDeformVert *dv = dvert;
+                       float weightsum = 0.0f;
+
                        /* get the average of all verts with that are in the vertex-group */
                        for (i = 0; i < numVerts; i++, dv++) {
                                MDeformWeight *dw = defvert_find_index(dv, defgroup);
-                               if (dw && dw->weight != 0.0f) {
+
+                               if (dw && dw->weight > 0.0f) {
                                        dm->getVertCo(dm, i, co);
                                        dm->getVertNo(dm, i, nor);
-                                       add_v3_v3(vec, co);
-                                       add_v3_v3(normal, nor);
-                                       count++;
-                                       
+                                       madd_v3_v3fl(vec, co, dw->weight);
+                                       madd_v3_v3fl(normal, nor, dw->weight);
+                                       weightsum += dw->weight;
                                }
                        }
 
                        /* calculate averages of normal and coordinates */
-                       if (count > 0) {
-                               mul_v3_fl(vec, 1.0f / count);
-                               mul_v3_fl(normal, 1.0f / count);
+                       if (weightsum > 0) {
+                               mul_v3_fl(vec, 1.0f / weightsum);
+                               mul_v3_fl(normal, 1.0f / weightsum);
                        }
                        
                        
index 879d1895513f79e361970a68fbf712f97d90a95f..75000ec440b16cfcbf0fb057504b4922a75c2f92 100644 (file)
@@ -239,12 +239,16 @@ static void layerInterp_mdeformvert(void **sources, const float *weights,
 
                for (j = 0; j < source->totweight; ++j) {
                        MDeformWeight *dw = &source->dw[j];
+                       float weight = dw->weight * interp_weight;
+
+                       if (weight == 0.0f)
+                               continue;
 
                        for (node = dest_dw; node; node = node->next) {
                                MDeformWeight *tmp_dw = (MDeformWeight *)node->link;
 
                                if (tmp_dw->def_nr == dw->def_nr) {
-                                       tmp_dw->weight += dw->weight * interp_weight;
+                                       tmp_dw->weight += weight;
                                        break;
                                }
                        }
@@ -254,7 +258,7 @@ static void layerInterp_mdeformvert(void **sources, const float *weights,
                                MDeformWeight *tmp_dw = MEM_callocN(sizeof(*tmp_dw),
                                                                    "layerInterp_mdeformvert tmp_dw");
                                tmp_dw->def_nr = dw->def_nr;
-                               tmp_dw->weight = dw->weight * interp_weight;
+                               tmp_dw->weight = weight;
                                BLI_linklist_prepend(&dest_dw, tmp_dw);
                                totweight++;
                        }