Fix #21885: constraint with copy location/rotation from vertex group crashes.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 5 Apr 2010 11:11:15 +0000 (11:11 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 5 Apr 2010 11:11:15 +0000 (11:11 +0000)
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/makesdna/DNA_customdata_types.h

index 7994849a469944621fb0c4e262ae3ab65c63db5b..0441e9c9d00e91b6a2fa35e2945723709771645b 100644 (file)
@@ -427,8 +427,8 @@ static void contarget_get_mesh_mat (Scene *scene, Object *ob, char *substring, f
                 *      - check if the custom data masks for derivedFinal mean that we can just use that
                 *        (this is more effficient + sufficient for most cases)
                 */
-               if (ob->lastDataMask != CD_MASK_DERIVEDMESH) {
-                       dm = mesh_get_derived_final(scene, ob, CD_MASK_DERIVEDMESH);
+               if (!(ob->lastDataMask & CD_MASK_MDEFORMVERT)) {
+                       dm = mesh_get_derived_final(scene, ob, CD_MASK_MDEFORMVERT);
                        freeDM= 1;
                }
                else 
index 9078566f109d371238f8f51429097ae3bb0b5d5a..3972355d302686824b65253e085be2608ebca7bd 100644 (file)
@@ -577,6 +577,7 @@ static void ccgDM_getFinalVert(DerivedMesh *dm, int vertNum, MVert *mv)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
        CCGSubSurf *ss = ccgdm->ss;
+       DMGridData *vd;
        int i;
 
        memset(mv, 0, sizeof(*mv));
@@ -608,19 +609,25 @@ static void ccgDM_getFinalVert(DerivedMesh *dm, int vertNum, MVert *mv)
 
                offset = vertNum - ccgdm->faceMap[i].startVert;
                if(offset < 1) {
-                       copy_v3_v3(mv->co, ccgSubSurf_getFaceCenterData(f));
+                       vd = ccgSubSurf_getFaceCenterData(f);
+                       copy_v3_v3(mv->co, vd->co);
+                       normal_float_to_short_v3(mv->no, vd->no);
                } else if(offset < gridSideEnd) {
                        offset -= 1;
                        grid = offset / gridSideVerts;
                        x = offset % gridSideVerts + 1;
-                       copy_v3_v3(mv->co, ccgSubSurf_getFaceGridEdgeData(ss, f, grid, x));
+                       vd = ccgSubSurf_getFaceGridEdgeData(ss, f, grid, x);
+                       copy_v3_v3(mv->co, vd->co);
+                       normal_float_to_short_v3(mv->no, vd->no);
                } else if(offset < gridInternalEnd) {
                        offset -= gridSideEnd;
                        grid = offset / gridInternalVerts;
                        offset %= gridInternalVerts;
                        y = offset / gridSideVerts + 1;
                        x = offset % gridSideVerts + 1;
-                       copy_v3_v3(mv->co, ccgSubSurf_getFaceGridData(ss, f, grid, x, y));
+                       vd = ccgSubSurf_getFaceGridData(ss, f, grid, x, y);
+                       copy_v3_v3(mv->co, vd->co);
+                       normal_float_to_short_v3(mv->no, vd->no);
                }
        } else if((vertNum < ccgdm->vertMap[0].startVert) && (ccgSubSurf_getNumEdges(ss) > 0)) {
                /* this vert comes from edge data */
@@ -635,17 +642,37 @@ static void ccgDM_getFinalVert(DerivedMesh *dm, int vertNum, MVert *mv)
                e = ccgdm->edgeMap[i].edge;
 
                x = vertNum - ccgdm->edgeMap[i].startVert + 1;
-               copy_v3_v3(mv->co, ccgSubSurf_getEdgeData(ss, e, x));
+               vd = ccgSubSurf_getEdgeData(ss, e, x);
+               copy_v3_v3(mv->co, vd->co);
+               normal_float_to_short_v3(mv->no, vd->no);
        } else {
                /* this vert comes from vert data */
                CCGVert *v;
                i = vertNum - ccgdm->vertMap[0].startVert;
 
                v = ccgdm->vertMap[i].vert;
-               copy_v3_v3(mv->co, ccgSubSurf_getVertData(ss, v));
+               vd = ccgSubSurf_getVertData(ss, v);
+               copy_v3_v3(mv->co, vd->co);
+               normal_float_to_short_v3(mv->no, vd->no);
        }
 }
 
+static void ccgDM_getFinalVertCo(DerivedMesh *dm, int vertNum, float co_r[3])
+{
+       MVert mvert;
+
+       ccgDM_getFinalVert(dm, vertNum, &mvert);
+       VECCOPY(co_r, mvert.co);
+}
+
+static void ccgDM_getFinalVertNo(DerivedMesh *dm, int vertNum, float no_r[3])
+{
+       MVert mvert;
+
+       ccgDM_getFinalVert(dm, vertNum, &mvert);
+       normal_short_to_float_v3(no_r, mvert.no);
+}
+
 static void ccgDM_getFinalEdge(DerivedMesh *dm, int edgeNum, MEdge *med)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
@@ -2277,6 +2304,8 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
        ccgdm->dm.getVert = ccgDM_getFinalVert;
        ccgdm->dm.getEdge = ccgDM_getFinalEdge;
        ccgdm->dm.getFace = ccgDM_getFinalFace;
+       ccgdm->dm.getVertCo = ccgDM_getFinalVertCo;
+       ccgdm->dm.getVertNo = ccgDM_getFinalVertNo;
        ccgdm->dm.copyVertArray = ccgDM_copyFinalVertArray;
        ccgdm->dm.copyEdgeArray = ccgDM_copyFinalEdgeArray;
        ccgdm->dm.copyFaceArray = ccgDM_copyFinalFaceArray;
index dc07b0f368ab419cd6bf5098067f526a60a10450..8908143946a6da07c3e45f6271b52cb6a2d58928 100644 (file)
@@ -110,9 +110,6 @@ typedef struct CustomData {
 #define CD_MASK_WEIGHT_MCOL    (1 << CD_WEIGHT_MCOL)
 #define CD_MASK_CLOTH_ORCO     (1 << CD_CLOTH_ORCO)
 
-/* derivedmesh wants CustomDataMask for weightpaint too, is not customdata though */
-#define CD_MASK_WEIGHTPAINT    (1 << CD_WEIGHTPAINT)
-
 /* CustomData.flag */
 
 /* indicates layer should not be copied by CustomData_from_template or