Fix #23071: making vertex parent not correct with subsurf modifier, now it
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 28 Jul 2010 16:47:12 +0000 (16:47 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 28 Jul 2010 16:47:12 +0000 (16:47 +0000)
also uses the final derivedmesh for the coordinates in edit mode.

source/blender/blenkernel/intern/object.c

index 81799a5409d3c13d47514187cf631a36c76fe67d..39e02ee584d7fb67f3adbbae3218daa743006a5a 100644 (file)
@@ -1837,47 +1837,38 @@ static void give_parvert(Object *par, int nr, float *vec)
        
        if(par->type==OB_MESH) {
                Mesh *me= par->data;
-               em = BKE_mesh_get_editmesh(me);
+               DerivedMesh *dm;
 
-               if(em) {
-                       EditVert *eve;
+               em = BKE_mesh_get_editmesh(me);
+               dm = (em)? em->derivedFinal: par->derivedFinal;
                        
-                       for(eve= em->verts.first; eve; eve= eve->next) {
-                               if(eve->keyindex==nr) {
-                                       memcpy(vec, eve->co, sizeof(float)*3);
-                                       break;
+               if(dm) {
+                       MVert *mvert= dm->getVertArray(dm);
+                       int *index = (int *)dm->getVertDataArray(dm, CD_ORIGINDEX);
+                       int i, count = 0, vindex, numVerts = dm->getNumVerts(dm);
+
+                       /* get the average of all verts with (original index == nr) */
+                       for(i = 0; i < numVerts; i++) {
+                               vindex= (index)? index[i]: i;
+
+                               if(vindex == nr) {
+                                       add_v3_v3(vec, mvert[i].co);
+                                       count++;
                                }
                        }
-                       BKE_mesh_end_editmesh(me, em);
-               }
-               else {
-                       DerivedMesh *dm = par->derivedFinal;
-                       
-                       if(dm) {
-                               MVert *mvert= dm->getVertArray(dm);
-                               int *index = (int *)dm->getVertDataArray(dm, CD_ORIGINDEX);
-                               int i, count = 0, vindex, numVerts = dm->getNumVerts(dm);
-
-                               /* get the average of all verts with (original index == nr) */
-                               for(i = 0; i < numVerts; i++) {
-                                       vindex= (index)? index[i]: i;
-
-                                       if(vindex == nr) {
-                                               add_v3_v3(vec, mvert[i].co);
-                                               count++;
-                                       }
-                               }
 
-                               if (count==0) {
-                                       /* keep as 0,0,0 */
-                               } else if(count > 0) {
-                                       mul_v3_fl(vec, 1.0f / count);
-                               } else {
-                                       /* use first index if its out of range */
-                                       dm->getVertCo(dm, 0, vec);
-                               }
+                       if (count==0) {
+                               /* keep as 0,0,0 */
+                       } else if(count > 0) {
+                               mul_v3_fl(vec, 1.0f / count);
+                       } else {
+                               /* use first index if its out of range */
+                               dm->getVertCo(dm, 0, vec);
                        }
                }
+
+               if(em)
+                       BKE_mesh_end_editmesh(me, em);
        }
        else if (ELEM(par->type, OB_CURVE, OB_SURF)) {
                Nurb *nu;