-> Vertex Group/Weight support in removedoublesflag()
authorGeoffrey Bantle <hairbat@yahoo.com>
Wed, 1 Mar 2006 03:33:45 +0000 (03:33 +0000)
committerGeoffrey Bantle <hairbat@yahoo.com>
Wed, 1 Mar 2006 03:33:45 +0000 (03:33 +0000)
Remove doubles didn't previously deal with vertex groups/weights properly. Now it averages the weights of vertices when they are doubles and share the same group. Verts that get merged but don't belong to all the same groups are dealt with as well.

source/blender/src/editmesh_tools.c

index c5c3a1e14e11c5d7e94e9f43df6070f1ef9c747f..c751443471d276cf38b6fe1bd63bcf75985ebf90 100644 (file)
@@ -212,7 +212,8 @@ int removedoublesflag(short flag, float limit)              /* return amount */
        xvertsort *sortblock, *sb, *sb1;
        struct facesort *vlsortblock, *vsb, *vsb1;
        float dist;
-       int a, b, test, amount;
+       int a, b, test, amount, currweight, doubweight, targetweight;
+       MDeformWeight *newdw;
 
        /* flag 128 is cleared, count */
        eve= em->verts.first;
@@ -271,6 +272,51 @@ int removedoublesflag(short flag, float limit)             /* return amount */
        }
        MEM_freeN(sortblock);
 
+       
+       for(eve = em->verts.first; eve; eve=eve->next){
+               
+               if(eve->f & flag) {
+                       if(eve->f & 128) {
+                       
+                               v1 = eve->tmp.v;
+                               
+                               if(v1->dw && eve->dw){
+                               
+                                       for(doubweight=0; doubweight < eve->totweight; doubweight++){
+                                               targetweight = -1;
+                                               for(currweight = 0; currweight < v1->totweight; currweight++){
+                                                       if(v1->dw[currweight].def_nr == eve->dw[doubweight].def_nr){
+                                                               targetweight = currweight;
+                                                               break;
+                                                       }
+                                               }
+                                               
+                                               if(targetweight != -1){         /*average*/
+                                                       v1->dw[targetweight].weight = (v1->dw[targetweight].weight + eve->dw[doubweight].weight) / 2;
+                                               }
+                                               else{   /*append*/
+                                                       newdw = MEM_callocN(sizeof(MDeformWeight)*(v1->totweight+1), "MDeformWeight Append");
+                                                       memcpy(newdw, v1->dw, sizeof(MDeformVert)*v1->totweight);
+                                                       MEM_freeN(v1->dw);
+                                                       
+                                                       v1->dw= newdw;
+                                                       v1->dw[v1->totweight].weight = eve->dw[doubweight].weight;
+                                                       v1->dw[v1->totweight].def_nr = eve->dw[doubweight].def_nr;
+                                                       v1->totweight++;
+                                               }       
+                                       }
+                               }
+                               else if(eve->dw){       /*just straight copy vert weights*/
+                                       
+                                       newdw = MEM_mallocN(sizeof(MDeformWeight) * (eve->totweight), "MDeformWeight Copy");
+                                       memcpy(newdw, eve->dw, sizeof(MDeformWeight)*eve->totweight);
+                                       v1->dw= newdw;
+                                       
+                               }
+                       }
+               }
+       }
+
        /* test edges and insert again */
        eed= em->edges.first;
        while(eed) {