Fix #22331: mesh deform modifier not caculate all shape keys when using 'apply shape...
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 7 Jun 2010 14:38:59 +0000 (14:38 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 7 Jun 2010 14:38:59 +0000 (14:38 +0000)
This modifier used undeformed coordinates from emDM.
Added method getVertCos to emDM, so meshdeform now could use it
to get deformed coordinates form any derived mesh.

source/blender/blenkernel/intern/DerivedMesh.c
source/blender/modifiers/intern/MOD_meshdeform.c

index 9d649edd81ac76d32bb56cbdc4dea46c62ffb547..339326f75d59a5da36b5896b25a2f21d2879f8a3 100644 (file)
@@ -1077,6 +1077,21 @@ static int emDM_getNumFaces(DerivedMesh *dm)
        return BLI_countlist(&emdm->em->faces);
 }
 
+static void emDM_getVertCos(DerivedMesh *dm, float (*cos_r)[3])
+{
+       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditVert *eve;
+       int i;
+
+       for (i=0,eve= emdm->em->verts.first; eve; i++,eve=eve->next) {
+               if (emdm->vertexCos) {
+                       copy_v3_v3(cos_r[i], emdm->vertexCos[i]);
+               } else {
+                       copy_v3_v3(cos_r[i], eve->co);
+               }
+       }
+}
+
 static void emDM_getVert(DerivedMesh *dm, int index, MVert *vert_r)
 {
        EditVert *ev = ((EditMeshDerivedMesh *)dm)->em->verts.first;
@@ -1309,6 +1324,8 @@ static DerivedMesh *getEditMeshDerivedMesh(EditMesh *em, Object *ob,
        emdm->dm.getNumEdges = emDM_getNumEdges;
        emdm->dm.getNumFaces = emDM_getNumFaces;
 
+       emdm->dm.getVertCos = emDM_getVertCos;
+
        emdm->dm.getVert = emDM_getVert;
        emdm->dm.getEdge = emDM_getEdge;
        emdm->dm.getFace = emDM_getFace;
index 83fa544690b3c595f342a9df08ac07bade163b71..623f4a5ddeb9c891ce5cded6862097735f1c856c 100644 (file)
@@ -180,13 +180,13 @@ static void meshdeformModifier_do(
        DerivedMesh *tmpdm, *cagedm;
        MDeformVert *dvert = NULL;
        MDeformWeight *dw;
-       MVert *cagemvert;
        MDefInfluence *influences;
        int *offsets;
        float imat[4][4], cagemat[4][4], iobmat[4][4], icagemat[3][3], cmat[4][4];
        float weight, totweight, fac, co[3], (*dco)[3], (*bindcagecos)[3];
        int a, b, totvert, totcagevert, defgrp_index;
-       
+       float (*cagecos)[3];
+
        if(!mmd->object || (!mmd->bindcagecos && !mmd->bindfunc))
                return;
        
@@ -251,8 +251,10 @@ static void meshdeformModifier_do(
                return;
        }
 
+       cagecos= MEM_callocN(sizeof(*cagecos)*totcagevert, "meshdeformModifier vertCos");
+
        /* setup deformation data */
-       cagemvert= cagedm->getVertArray(cagedm);
+       cagedm->getVertCos(cagedm, cagecos);
        influences= mmd->bindinfluences;
        offsets= mmd->bindoffsets;
        bindcagecos= (float(*)[3])mmd->bindcagecos;
@@ -260,7 +262,7 @@ static void meshdeformModifier_do(
        dco= MEM_callocN(sizeof(*dco)*totcagevert, "MDefDco");
        for(a=0; a<totcagevert; a++) {
                /* get cage vertex in world space with binding transform */
-               copy_v3_v3(co, cagemvert[a].co);
+               copy_v3_v3(co, cagecos[a]);
 
                if(G.rt != 527) {
                        mul_m4_v3(mmd->bindmat, co);
@@ -331,6 +333,7 @@ static void meshdeformModifier_do(
 
        /* release cage derivedmesh */
        MEM_freeN(dco);
+       MEM_freeN(cagecos);
        cagedm->release(cagedm);
 }