=bmesh= modifiers can now be applied with shapekeys
authorJoseph Eagar <joeedh@gmail.com>
Fri, 15 Apr 2011 05:20:18 +0000 (05:20 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Fri, 15 Apr 2011 05:20:18 +0000 (05:20 +0000)
19 files changed:
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/customdata.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/object.c
source/blender/bmesh/intern/bmesh_mods.c
source/blender/editors/mesh/editface.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_modifier.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/space_view3d/view3d_snap.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/util/crazyspace.c
source/blender/makesrna/intern/rna_modifier.c
source/blender/makesrna/intern/rna_object_api.c
source/blender/modifiers/intern/MOD_boolean_util.c
source/blender/modifiers/intern/MOD_mirror.c

index ecf62d49da6c68f0e6382be62ef78477bc68a2fd..3bf7306bf12aacff2004017c6ec51469275abf51 100644 (file)
@@ -446,7 +446,7 @@ int DM_release(DerivedMesh *dm);
 
 /* utility function to convert a DerivedMesh to a Mesh
  */
-void DM_to_mesh(DerivedMesh *dm, struct Mesh *me);
+void DM_to_mesh(DerivedMesh *dm, struct Mesh *me, struct Object *ob);
 
 /* utility function to convert a DerivedMesh to a shape key block 
  */
@@ -585,7 +585,8 @@ DerivedMesh *mesh_get_derived_final(struct Scene *scene, struct Object *ob,
 DerivedMesh *mesh_get_derived_deform(struct Scene *scene, struct Object *ob,
                                                                         CustomDataMask dataMask);
 
-DerivedMesh *mesh_create_derived_for_modifier(struct Scene *scene, struct Object *ob, struct ModifierData *md);
+DerivedMesh *mesh_create_derived_for_modifier(struct Scene *scene, struct Object *ob,
+                                                                                         struct ModifierData *md, int build_shapekey_layers);
 
 DerivedMesh *mesh_create_derived_render(struct Scene *scene, struct Object *ob,
                                                                                CustomDataMask dataMask);
@@ -620,7 +621,8 @@ DerivedMesh *editbmesh_get_derived_cage_and_final(struct Scene *scene, struct Ob
                                                                                                 CustomDataMask dataMask);
 float (*editbmesh_get_vertex_cos(struct BMEditMesh *em, int *numVerts_r))[3];
 int editbmesh_modifier_is_enabled(struct Scene *scene, struct ModifierData *md, DerivedMesh *dm);
-void makeDerivedMesh(struct Scene *scene, struct Object *ob, struct BMEditMesh *em, CustomDataMask dataMask);
+void makeDerivedMesh(struct Scene *scene, struct Object *ob, struct BMEditMesh *em, 
+       CustomDataMask dataMask, int build_shapekey_layers);
 
 /* returns an array of deform matrices for crazyspace correction, and the
    number of modifiers left */
index 6a6a56baff6c98a590ad102502b4a47839b4c2b2..285f089a871ed6597f6f667f333bc93b57327422 100644 (file)
@@ -33,7 +33,7 @@
 
 
 #include <string.h>
-
+#include "limits.h"
 
 #include "MEM_guardedalloc.h"
 
 
 #include "ED_sculpt.h" /* for ED_sculpt_modifiers_changed */
 
-///////////////////////////////////
+static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *ob);
+static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid);
+
+               ///////////////////////////////////
 ///////////////////////////////////
 
 static MVert *dm_getVertArray(DerivedMesh *dm)
@@ -364,13 +367,14 @@ void DM_DupPolys(DerivedMesh *source, DerivedMesh *target)
        target->numPolyData = source->getNumFaces(source);
 }
 
-void DM_to_mesh(DerivedMesh *dm, Mesh *me)
+void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob)
 {
        /* dm might depend on me, so we need to do everything with a local copy */
        Mesh tmp = *me;
        DMFaceIter *iter;
        int totvert, totedge, totface, totloop, totpoly;
-
+       int did_shapekeys=0;
+       
        memset(&tmp.vdata, 0, sizeof(tmp.vdata));
        memset(&tmp.edata, 0, sizeof(tmp.edata));
        memset(&tmp.fdata, 0, sizeof(tmp.fdata));
@@ -396,6 +400,31 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me)
        CustomData_copy(&dm->loopData, &tmp.ldata, CD_MASK_MESH, CD_DUPLICATE, totloop);
        CustomData_copy(&dm->polyData, &tmp.pdata, CD_MASK_MESH, CD_DUPLICATE, totpoly);
 
+       if (CustomData_has_layer(&dm->vertData, CD_SHAPEKEY)) {
+               KeyBlock *kb;
+               int i=0;
+               
+               if (ob) {
+                       for (kb=me->key->block.first; kb; kb=kb->next, i++) {
+                               if (i == ob->shapenr-1) {
+                                       i = kb->uid;
+                                       break;
+                               }
+                       }
+                       
+                       if (!kb) {
+                               printf("error in DM_to_mesh: could not find active shapekey! eek!!\n");
+                               i = INT_MAX;
+                       }
+               } else {
+                       /*if no object, set to INT_MAX so we don't mess up any shapekey layers*/
+                       i = INT_MAX;
+               }
+               
+               shapekey_layers_to_keyblocks(dm, me, i);
+               did_shapekeys = 1;
+       }
+       
        /* not all DerivedMeshes store their verts/edges/faces in CustomData, so
           we set them here in case they are missing */
        if(!CustomData_has_layer(&tmp.vdata, CD_MVERT))
@@ -409,10 +438,10 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me)
 
        /* object had got displacement layer, should copy this layer to save sculpted data */
        /* NOTE: maybe some other layers should be copied? nazgul */
-       if(CustomData_has_layer(&me->fdata, CD_MDISPS)) {
-               if (totface == me->totface) {
-                       MDisps *mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS);
-                       CustomData_add_layer(&tmp.fdata, CD_MDISPS, CD_DUPLICATE, mdisps, totface);
+       if(CustomData_has_layer(&me->ldata, CD_MDISPS)) {
+               if (totloop == me->totloop) {
+                       MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
+                       CustomData_add_layer(&tmp.ldata, CD_MDISPS, CD_DUPLICATE, mdisps, totloop);
                }
        }
 
@@ -424,10 +453,10 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me)
        CustomData_free(&me->ldata, me->totloop);
        CustomData_free(&me->pdata, me->totpoly);
 
-       /* BMESH_TODO/XXX: ok, this should use new CD shapekey data,
-                          which shouuld be fed through the modifier 
-                                          stack*/
-       if(tmp.totvert != me->totvert) {
+       /*  ok, this should now use new CD shapekey data,
+           which shouuld be fed through the modifier 
+               stack*/
+       if(tmp.totvert != me->totvert && !did_shapekeys) {
                printf("YEEK! this should be recoded! Shape key loss!!!\n");
                if(tmp.key) tmp.key->id.us--;
                tmp.key = NULL;
@@ -672,7 +701,8 @@ DerivedMesh *mesh_create_derived(Mesh *me, Object *ob, float (*vertCos)[3])
 
 /***/
 
-DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, ModifierData *md)
+DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, 
+       ModifierData *md, int build_shapekey_layers)
 {
        Mesh *me = ob->data;
        ModifierTypeInfo *mti = modifierType_getInfo(md->type);
@@ -682,7 +712,11 @@ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, Modifier
        
        if (!(md->mode&eModifierMode_Realtime)) return NULL;
        if (mti->isDisabled && mti->isDisabled(md, 0)) return NULL;
-
+       
+       if (build_shapekey_layers && me->key && ob->shapenr <= BLI_countlist(&me->key->block)) {
+               key_to_mesh(BLI_findlink(&me->key->block, ob->shapenr-1), me);
+       }
+       
        if (mti->type==eModifierTypeType_OnlyDeform) {
                int numVerts;
                float (*deformedVerts)[3] = mesh_getVertexCos(me, &numVerts);
@@ -690,9 +724,16 @@ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, Modifier
                mti->deformVerts(md, ob, NULL, deformedVerts, numVerts, 0, 0);
                dm = mesh_create_derived(me, ob, deformedVerts);
 
+               if (build_shapekey_layers)
+                       add_shapekey_layers(dm, me, ob);
+               
                MEM_freeN(deformedVerts);
        } else {
                DerivedMesh *tdm = mesh_create_derived(me, ob, NULL);
+
+               if (build_shapekey_layers)
+                       add_shapekey_layers(tdm, me, ob);
+               
                dm = mti->applyModifier(md, ob, tdm, 0, 0);
 
                if(tdm != dm) tdm->release(tdm);
@@ -924,6 +965,92 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm)
        dfiter->free(dfiter);
 }
 
+
+static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid)
+{
+       KeyBlock *kb;
+       int i, j, tot;
+       
+       if (!me->key)
+               return; 
+       
+       tot = CustomData_number_of_layers(&dm->vertData, CD_SHAPEKEY);
+       for (i=0; i<tot; i++) {
+               CustomDataLayer *layer = &dm->vertData.layers[CustomData_get_layer_index_n(&dm->vertData, CD_SHAPEKEY, i)];
+               float (*cos)[3], (*kbcos)[3];
+               
+               for (kb=me->key->block.first; kb; kb=kb->next) {
+                       if (kb->uid == layer->uid)
+                               break;
+               }
+               
+               if (!kb) {
+                       kb = add_keyblock(me->key, layer->name);
+                       kb->uid = layer->uid;
+               }
+               
+               if (kb->data)
+                       MEM_freeN(kb->data);
+               
+               cos = CustomData_get_layer_n(&dm->vertData, CD_SHAPEKEY, i);
+               kb->totelem = dm->numVertData;
+
+               kb->data = kbcos = MEM_mallocN(sizeof(float)*3*kb->totelem, "kbcos DerivedMesh.c");
+               if (kb->uid == actshape_uid) {
+                       MVert *mvert = dm->getVertArray(dm);
+                       
+                       for (j=0; j<dm->numVertData; j++, kbcos++, mvert++) {
+                               copy_v3_v3(*kbcos, mvert->co);
+                       }
+               } else {
+                       for (j=0; j<kb->totelem; j++, cos++, kbcos++) {
+                               copy_v3_v3(*kbcos, *cos);
+                       }
+               }
+       }
+       
+       for (kb=me->key->block.first; kb; kb=kb->next) {
+               if (kb->totelem != dm->numVertData) {
+                       if (kb->data)
+                               MEM_freeN(kb->data);
+                       
+                       kb->totelem = dm->numVertData;
+                       kb->data = MEM_callocN(sizeof(float)*3*kb->totelem, "kb->data derivedmesh.c");
+                       printf("eek! lost a shapekey layer!\n");
+               }
+       }
+}
+
+static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *ob)
+{
+       KeyBlock *kb;
+       Key *key = me->key;
+       int a, b;
+       
+       if (!me->key)
+               return;
+       
+       if (dm->numVertData != me->totvert) {
+               printf("error in add_shapekey_layers: dm isn't the same size as me\n");
+               return;
+       }
+               
+       for (a=0, kb=key->block.first; kb; kb=kb->next, a++) {
+               float (*cos)[3] = CustomData_add_layer_named(&dm->vertData, CD_SHAPEKEY, CD_CALLOC, NULL, dm->numVertData, kb->name);
+               int ci = CustomData_get_layer_index_n(&dm->vertData, CD_SHAPEKEY, a);
+               
+               dm->vertData.layers[ci].uid = kb->uid;
+               if (kb->totelem != dm->numVertData) {
+                       printf("error in add_shapekey_layers: totelem and totvert don't match");
+                       continue;
+               }
+               
+               for (b=0; b<kb->totelem; b++, cos++) {
+                       copy_v3_v3(cos, ((float*)kb->data)+b*3);
+               }
+       }
+}
+
 /* new value for useDeform -1  (hack for the gameengine):
  * - apply only the modifier stack of the object, skipping the virtual modifiers,
  * - don't apply the key
@@ -932,7 +1059,8 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm)
 static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos)[3],
                                                                DerivedMesh **deform_r, DerivedMesh **final_r,
                                                                int useRenderParams, int useDeform,
-                                                               int needMapping, CustomDataMask dataMask, int index, int useCache)
+                                                               int needMapping, CustomDataMask dataMask, 
+                                                               int index, int useCache, int build_shapekey_layers)
 {
        Mesh *me = ob->data;
        ModifierData *firstmd, *md;
@@ -1007,7 +1135,10 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
                 */
                if (deform_r) {
                        *deform_r = CDDM_from_mesh(me, ob);
-
+                       
+                       if (build_shapekey_layers)
+                               add_shapekey_layers(dm, me, ob);
+                       
                        if(deformedVerts) {
                                CDDM_apply_vert_coords(*deform_r, deformedVerts);
                                CDDM_calc_normals(*deform_r);
@@ -1081,7 +1212,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
 
                        /* if this is not the last modifier in the stack then recalculate the normals
                         * to avoid giving bogus normals to the next modifier see: [#23673] */
-                       if(isPrevDeform &&  mti->dependsOnNormals && mti->dependsOnNormals(md)) {
+                       if(dm && isPrevDeform &&  mti->dependsOnNormals && mti->dependsOnNormals(md)) {
                                /* XXX, this covers bug #23673, but we may need normal calc for other types */
                                if(dm->type == DM_TYPE_CDDM) {
                                        CDDM_apply_vert_coords(dm, deformedVerts);
@@ -1112,6 +1243,9 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
                        } else {
                                dm = CDDM_from_mesh(me, ob);
 
+                               if (build_shapekey_layers)
+                                       add_shapekey_layers(dm, me, ob);
+
                                if(deformedVerts) {
                                        CDDM_apply_vert_coords(dm, deformedVerts);
                                        CDDM_calc_normals(dm);
@@ -1239,14 +1373,19 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
                finaldm = dm;
        } else {
                finaldm = CDDM_from_mesh(me, ob);
-
+               
+               if (build_shapekey_layers)
+                       add_shapekey_layers(finaldm, me, ob);
+               
                if(deformedVerts) {
                        CDDM_apply_vert_coords(finaldm, deformedVerts);
-                       CDDM_calc_normals(finaldm);
                }
 
+               CDDM_calc_normals(finaldm);
+               
                if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT))
                        add_weight_mcol_dm(ob, finaldm);
+               
        }
 
        /* add an orco layer if needed */
@@ -1519,7 +1658,8 @@ static void clear_mesh_caches(Object *ob)
        }
 }
 
-static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask)
+static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask,
+       int build_shapekey_layers)
 {
        Object *obact = scene->basact?scene->basact->object:NULL;
        int editing = paint_facesel_test(ob);
@@ -1530,7 +1670,7 @@ static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask)
 
        mesh_calc_modifiers(scene, ob, NULL, &ob->derivedDeform,
                                                &ob->derivedFinal, 0, 1,
-                                               needMapping, dataMask, -1, 1);
+                                               needMapping, dataMask, -1, 1, build_shapekey_layers);
 
        DM_set_object_boundbox (ob, ob->derivedFinal);
 
@@ -1564,12 +1704,13 @@ static void editbmesh_build_data(Scene *scene, Object *obedit, BMEditMesh *em, C
        em->derivedCage->needsFree = 0;
 }
 
-void makeDerivedMesh(Scene *scene, Object *ob, BMEditMesh *em, CustomDataMask dataMask)
+void makeDerivedMesh(Scene *scene, Object *ob, BMEditMesh *em,
+       CustomDataMask dataMask, int build_shapekey_layers)
 {
        if (em) {
                editbmesh_build_data(scene, ob, em, dataMask);
        } else {
-               mesh_build_data(scene, ob, dataMask);
+               mesh_build_data(scene, ob, dataMask, build_shapekey_layers);
        }
 }
 
@@ -1581,7 +1722,7 @@ DerivedMesh *mesh_get_derived_final(Scene *scene, Object *ob, CustomDataMask dat
         * the data we need, rebuild the derived mesh
         */
        if(!ob->derivedFinal || (dataMask & ob->lastDataMask) != dataMask)
-               mesh_build_data(scene, ob, dataMask);
+               mesh_build_data(scene, ob, dataMask, 0);
 
        return ob->derivedFinal;
 }
@@ -1592,7 +1733,7 @@ DerivedMesh *mesh_get_derived_deform(Scene *scene, Object *ob, CustomDataMask da
         * the data we need, rebuild the derived mesh
         */
        if(!ob->derivedDeform || (dataMask & ob->lastDataMask) != dataMask)
-               mesh_build_data(scene, ob, dataMask);
+               mesh_build_data(scene, ob, dataMask, 0);
 
        return ob->derivedDeform;
 }
@@ -1601,7 +1742,7 @@ DerivedMesh *mesh_create_derived_render(Scene *scene, Object *ob, CustomDataMask
 {
        DerivedMesh *final;
        
-       mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 1, 1, 0, dataMask, -1, 0);
+       mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 1, 1, 0, dataMask, -1, 0, 0);
 
        return final;
 }
@@ -1610,7 +1751,7 @@ DerivedMesh *mesh_create_derived_index_render(Scene *scene, Object *ob, CustomDa
 {
        DerivedMesh *final;
        
-       mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 1, 1, 0, dataMask, index, 0);
+       mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 1, 1, 0, dataMask, index, 0, 0);
 
        return final;
 }
@@ -1619,7 +1760,7 @@ DerivedMesh *mesh_create_derived_view(Scene *scene, Object *ob, CustomDataMask d
 {
        DerivedMesh *final;
 
-       mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 0, 1, 0, dataMask, -1, 0);
+       mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 0, 1, 0, dataMask, -1, 0, 0);
 
        return final;
 }
@@ -1629,7 +1770,7 @@ DerivedMesh *mesh_create_derived_no_deform(Scene *scene, Object *ob, float (*ver
 {
        DerivedMesh *final;
        
-       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, 0, 0, dataMask, -1, 0);
+       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, 0, 0, dataMask, -1, 0, 0);
 
        return final;
 }
@@ -1639,7 +1780,7 @@ DerivedMesh *mesh_create_derived_no_virtual(Scene *scene, Object *ob, float (*ve
 {
        DerivedMesh *final;
        
-       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, -1, 0, dataMask, -1, 0);
+       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, -1, 0, dataMask, -1, 0, 0);
 
        return final;
 }
@@ -1649,7 +1790,7 @@ DerivedMesh *mesh_create_derived_physics(Scene *scene, Object *ob, float (*vertC
 {
        DerivedMesh *final;
        
-       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, -1, 1, dataMask, -1, 0);
+       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, -1, 1, dataMask, -1, 0, 0);
 
        return final;
 }
@@ -1660,7 +1801,7 @@ DerivedMesh *mesh_create_derived_no_deform_render(Scene *scene, Object *ob,
 {
        DerivedMesh *final;
 
-       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 1, 0, 0, dataMask, -1, 0);
+       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 1, 0, 0, dataMask, -1, 0, 0);
 
        return final;
 }
index cba4053ad3a7016fbaeae3f3f14a9de6a8c2c500..58e11042bf3842a5418cab6c4f66030c6eeb0747 100644 (file)
@@ -1872,6 +1872,10 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *me, int use_mdisps)
        add_orig = !CustomData_has_layer(&em->bm->pdata, CD_ORIGINDEX);
 
        flag = use_mdisps ? CD_MASK_DERIVEDMESH|CD_MASK_MDISPS : CD_MASK_DERIVEDMESH;
+       
+       /*don't process shapekeys, we only feed them through the modifier stack as needed,
+      e.g. for applying modifiers or the like*/
+       flag &= ~CD_SHAPEKEY;
        CustomData_merge(&em->bm->vdata, &dm->vertData, flag,
                         CD_CALLOC, dm->numVertData);
        CustomData_merge(&em->bm->edata, &dm->edgeData, flag,
index b29a669ed0547e71021b7e11688a5ab6690dc222..7276e4eb246ac1ad2f77663a43f1c9efd06e5aee 100644 (file)
@@ -969,7 +969,7 @@ const CustomDataMask CD_MASK_DERIVEDMESH =
        CD_MASK_MCOL | CD_MASK_ORIGINDEX | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_CLOTH_ORCO |
        CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_WEIGHT_MLOOPCOL |
        CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORCO | CD_MASK_TANGENT | 
-       CD_MASK_WEIGHT_MCOL | CD_MASK_NORMAL;
+       CD_MASK_WEIGHT_MCOL | CD_MASK_NORMAL | CD_MASK_SHAPEKEY;
 const CustomDataMask CD_MASK_BMESH = CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY |
        CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | 
        CD_MASK_PROP_STR | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_MDISPS;
@@ -1050,6 +1050,8 @@ void CustomData_merge(const struct CustomData *source, struct CustomData *dest,
                                layer->data, totelem, layer->name);
                
                if(newlayer) {
+                       newlayer->uid = layer->uid;
+                       
                        newlayer->active = lastactive;
                        newlayer->active_rnd = lastrender;
                        newlayer->active_clone = lastclone;
index 3035c95a1bc8025064d107a83bb8c4b508aebe28..85da641fa23b61f5b4892e0832abb00810e3e2f8 100644 (file)
@@ -1433,7 +1433,7 @@ void nurbs_to_mesh(Object *ob)
                mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
        } else {
                me= add_mesh("Mesh");
-               DM_to_mesh(dm, me);
+               DM_to_mesh(dm, me, ob);
        }
 
        me->totcol= cu->totcol;
@@ -1715,7 +1715,7 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
                ml = mloop + mp->loopstart;
                /*this is kindof hackish, probably need to calculate quads around face center for
                  ngons, not this weird quad-fitting thing I've got going here*/
-               for (j=0; j<mp->totloop; j += 4, ml++) {
+               for (j=0; j<mp->totloop; j += 4, ml += 4) {
                        int v1, v2, v3, v4;
                        
                        v1 = ml->v; 
@@ -1744,7 +1744,7 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
                mf = mfaces;
                for (i=0; i<numFaces; i++, mf++, origIndexFace++) {
                        if (*origIndexFace < numPolys) {
-                               VECCOPY(fnors[i], tnorms[*origIndexFace]);
+                               VECCOPY(fnors[i], pnors[*origIndexFace]);
                        } else {
                                /*eek, we're not corrusponding to polys*/
                                printf("error in mesh_calc_normals; tesselation face indices are incorrect.  normals may look bad.\n");
index fae65a366d1cd336d54f4022d2bca839b9044dbf..c761e9852bd356c89b881bef012b69b9af5b4e78 100644 (file)
@@ -2610,16 +2610,16 @@ void object_handle_update(Scene *scene, Object *ob)
                                        BMEditMesh *em = (ob == scene->obedit)? ((Mesh*)ob->data)->edit_btmesh : NULL;
                                        BLI_assert((scene->customdata_mask & CD_MASK_BAREMESH) == CD_MASK_BAREMESH);
                                        if(em) {
-                                               makeDerivedMesh(scene, ob, em,  scene->customdata_mask); /* was CD_MASK_BAREMESH */
+                                               makeDerivedMesh(scene, ob, em,  scene->customdata_mask, 0); /* was CD_MASK_BAREMESH */
                                        } else
-                                               makeDerivedMesh(scene, ob, NULL, scene->customdata_mask);
+                                               makeDerivedMesh(scene, ob, NULL, scene->customdata_mask, 0);
 
 #else                          /* ensure CD_MASK_BAREMESH for now */
                                        BMEditMesh *em = (ob == scene->obedit)? ((Mesh*)ob->data)->edit_btmesh : NULL;
                                        if(em) {
-                                               makeDerivedMesh(scene, ob, em,  scene->customdata_mask | CD_MASK_BAREMESH); /* was CD_MASK_BAREMESH */
+                                               makeDerivedMesh(scene, ob, em,  scene->customdata_mask | CD_MASK_BAREMESH, 0); /* was CD_MASK_BAREMESH */
                                        } else
-                                               makeDerivedMesh(scene, ob, NULL, scene->customdata_mask | CD_MASK_BAREMESH);
+                                               makeDerivedMesh(scene, ob, NULL, scene->customdata_mask | CD_MASK_BAREMESH, 0);
 #endif
 
                                }
index 45547a60c448c9a24da69faf2ac10e7ebb3ddb96..cee8ec80cb4f5518296f3c464b2fdaf51f07e387 100644 (file)
@@ -263,9 +263,7 @@ BMEdge *BM_Connect_Verts(BMesh *bm, BMVert *v1, BMVert *v2, BMFace **nf) {
        BMLoop *nl;
        BMFace *face;
 
-       /*this isn't the best thing in the world.  it doesn't handle cases where there's
-         multiple faces yet.  that might require a convexity test to figure out which
-         face is "best," and who knows what for non-manifold conditions.*/
+       /*be warned: this can do weird things in some ngon situation, see BM_LegalSplits*/
        for (face = BMIter_New(&iter, bm, BM_FACES_OF_VERT, v1); face; face=BMIter_Step(&iter)) {
                for (v=BMIter_New(&iter2, bm, BM_VERTS_OF_FACE, face); v; v=BMIter_Step(&iter2)) {
                        if (v == v2) {
index ed09eb9c4c4496967f2a711a0a79c38d0084ffd0..b14822e8c3cfb4c068997e3d09ae46503c616ac8 100644 (file)
@@ -118,7 +118,7 @@ static int facesel_face_pick(struct bContext *C, Mesh *me, Object *ob, short *mv
        me->totface = mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata, 
                me->mvert, me->totface, me->totloop, me->totpoly, 0, 0);
        mesh_update_customdata_pointers(me);
-       makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH);
+       makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH, 0);
 
        // XXX  if (v3d->flag & V3D_INVALID_BACKBUF) {
 // XXX drawview.c!             check_backbuf();
index 0138c44593b49813c3ad52b88005d3e66b5a687f..5dc2ee6fb19762ffdd2c2263a03f1beeab06055f 100644 (file)
@@ -1175,7 +1175,7 @@ static int convert_exec(bContext *C, wmOperator *op)
                        dm= mesh_get_derived_final(scene, newob, CD_MASK_MESH);
                        /* dm= mesh_create_derived_no_deform(ob1, NULL);        this was called original (instead of get_derived). man o man why! (ton) */
 
-                       DM_to_mesh(dm, newob->data);
+                       DM_to_mesh(dm, newob->data, newob);
 
                        dm->release(dm);
                        object_free_modifiers(newob);   /* after derivedmesh calls! */
index 88fa19a32e400f8ed099218bafeae1f2ad0dbbff..d1b7f534cb28d12677e010daef4487d22751ba72 100644 (file)
@@ -412,7 +412,7 @@ static int modifier_apply_shape(ReportList *reports, Scene *scene, Object *ob, M
                }
                mesh_pmv_off(me);
                
-               dm = mesh_create_derived_for_modifier(scene, ob, md);
+               dm = mesh_create_derived_for_modifier(scene, ob, md, 0);
                if (!dm) {
                        BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply");
                        return 0;
@@ -452,12 +452,7 @@ static int modifier_apply_obdata(ReportList *reports, Scene *scene, Object *ob,
                DerivedMesh *dm;
                Mesh *me = ob->data;
                MultiresModifierData *mmd= find_multires_modifier_before(scene, md);
-
-               if( me->key) {
-                       BKE_report(reports, RPT_ERROR, "Modifier cannot be applied to Mesh with Shape Keys");
-                       return 0;
-               }
-
+               
                mesh_pmv_off(me);
 
                /* Multires: ensure that recent sculpting is applied */
@@ -470,19 +465,19 @@ static int modifier_apply_obdata(ReportList *reports, Scene *scene, Object *ob,
                                return 0;
                        }
                } else {
-                       dm = mesh_create_derived_for_modifier(scene, ob, md);
+                       dm = mesh_create_derived_for_modifier(scene, ob, md, 1);
                        if (!dm) {
                                BKE_report(reports, RPT_ERROR, "Modifier returned error, skipping apply");
                                return 0;
                        }
 
-                       DM_to_mesh(dm, me);
+                       DM_to_mesh(dm, me, ob);
 
                        dm->release(dm);
 
                        if(md->type == eModifierType_Multires) {
-                               CustomData_external_remove(&me->fdata, &me->id, CD_MDISPS, me->totface);
-                               CustomData_free_layer_active(&me->fdata, CD_MDISPS, me->totface);
+                               CustomData_external_remove(&me->ldata, &me->id, CD_MDISPS, me->totloop);
+                               CustomData_free_layer_active(&me->ldata, CD_MDISPS, me->totloop);
                        }
                }
        } 
@@ -1166,7 +1161,7 @@ static int multires_external_save_exec(bContext *C, wmOperator *op)
        if(!me)
                return OPERATOR_CANCELLED;
 
-       if(CustomData_external_test(&me->fdata, CD_MDISPS))
+       if(CustomData_external_test(&me->ldata, CD_MDISPS))
                return OPERATOR_CANCELLED;
        
        RNA_string_get(op->ptr, "filepath", path);
@@ -1174,8 +1169,8 @@ static int multires_external_save_exec(bContext *C, wmOperator *op)
        if(relative)
                BLI_path_rel(path, G.main->name);
 
-       CustomData_external_add(&me->fdata, &me->id, CD_MDISPS, me->totface, path);
-       CustomData_external_write(&me->fdata, &me->id, CD_MASK_MESH, me->totface, 0);
+       CustomData_external_add(&me->ldata, &me->id, CD_MDISPS, me->totloop, path);
+       CustomData_external_write(&me->ldata, &me->id, CD_MASK_MESH, me->totloop, 0);
        
        return OPERATOR_FINISHED;
 }
@@ -1195,7 +1190,7 @@ static int multires_external_save_invoke(bContext *C, wmOperator *op, wmEvent *U
        if (!mmd)
                return OPERATOR_CANCELLED;
        
-       if(CustomData_external_test(&me->fdata, CD_MDISPS))
+       if(CustomData_external_test(&me->ldata, CD_MDISPS))
                return OPERATOR_CANCELLED;
 
        if(!RNA_property_is_set(op->ptr, "relative_path"))
@@ -1239,11 +1234,11 @@ static int multires_external_pack_exec(bContext *C, wmOperator *UNUSED(op))
        Object *ob = ED_object_active_context(C);
        Mesh *me= ob->data;
 
-       if(!CustomData_external_test(&me->fdata, CD_MDISPS))
+       if(!CustomData_external_test(&me->ldata, CD_MDISPS))
                return OPERATOR_CANCELLED;
 
        // XXX don't remove..
-       CustomData_external_remove(&me->fdata, &me->id, CD_MDISPS, me->totface);
+       CustomData_external_remove(&me->ldata, &me->id, CD_MDISPS, me->totloop);
        
        return OPERATOR_FINISHED;
 }
index 37bfa460db1a4e36d07f8342fef982636ccc513f..3ca2abf65fc164eee57928b9486fb6ff2bf52ab8 100644 (file)
@@ -4723,7 +4723,7 @@ static int texture_paint_init(bContext *C, wmOperator *op)
                mesh_update_customdata_pointers(me);
                
                /*force customdata update*/
-               makeDerivedMesh(scene, pop->ps.ob, NULL, CD_MASK_BAREMESH);
+               makeDerivedMesh(scene, pop->ps.ob, NULL, CD_MASK_BAREMESH, 0);
 
                /* Dont allow brush size below 2 */
                if (pop->ps.brush && pop->ps.brush->size<=1)
index 0b28d84bf3948c543236c0045b88180b65c6e54d..7807bb0195c80105719f932104ebddb79e3c55a3 100644 (file)
@@ -1403,7 +1403,7 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED
        me->totface = mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata, 
                me->mvert, me->totface, me->totloop, me->totpoly, 1, 0);
        mesh_update_customdata_pointers(me);
-       makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH);
+       makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH, 0);
 
        /* if nothing was added yet, we make dverts and a vertex deform group */
        if (!me->dvert) {
@@ -1854,7 +1854,7 @@ static void vpaint_build_poly_facemap(struct VPaintData *vd, Mesh *me,
        me->totface = mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata, 
                me->mvert, me->totface, me->totloop, me->totpoly, 1, 0);
        mesh_update_customdata_pointers(me);
-       makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH);
+       makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH, 0);
 
        origIndex = CustomData_get_layer(&me->fdata, CD_ORIGINDEX);
        mf = me->mface;
index 708f975065b988effbf9d4d4f70a3fc5e91303e2..9db9c6f2175d4a751d37a562d2aa0eb88aebb28e 100644 (file)
@@ -84,6 +84,7 @@ typedef struct TransVert {
        float *val, oldval;
        int flag;
        float *nor;
+       int f1;
 } TransVert;
 
 static TransVert *transvmain=NULL;
@@ -197,8 +198,10 @@ static void set_mapped_co(void *vuserdata, int index, float *co, float *no, shor
        TransVert *tv = userdata[1];
        BMVert *eve = EDBM_get_vert_for_index(em, index);
        
-       if (BMINDEX_GET(eve) != -1)
+       if (BMINDEX_GET(eve) != -1 && !tv[BMINDEX_GET(eve)].f1) {
                copy_v3_v3(tv[BMINDEX_GET(eve)].maploc, co);
+               tv[BMINDEX_GET(eve)].f1 = 1;
+       }
 }
 
 /* copied from editobject.c, needs to be replaced with new transform code still */
index 418f6c194e6790f0c47a24b1a3859fb3ed6e7d4a..fdba6b9a307fcdd3c6f80b8d200c3879e8915e25 100644 (file)
@@ -2009,7 +2009,7 @@ static float *get_crazy_mapped_editverts(TransInfo *t)
        /* disable subsurf temporal, get mapped cos, and enable it */
        if(modifiers_disable_subsurf_temporary(t->obedit)) {
                /* need to make new derivemesh */
-               makeDerivedMesh(t->scene, t->obedit, me->edit_btmesh, CD_MASK_BAREMESH);
+               makeDerivedMesh(t->scene, t->obedit, me->edit_btmesh, CD_MASK_BAREMESH, 0);
        }
 
        /* now get the cage */
index 12470145b4d9376119474488299f97dc42ae0bc7..ac403e716271342ab1e64b9c074ce1f320750766 100644 (file)
@@ -116,7 +116,7 @@ float *crazyspace_get_mapped_editverts(Scene *scene, Object *obedit)
        /* disable subsurf temporal, get mapped cos, and enable it */
        if(modifiers_disable_subsurf_temporary(obedit)) {
                /* need to make new derivemesh */
-               makeDerivedMesh(scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH);
+               makeDerivedMesh(scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH, 0);
        }
 
        /* now get the cage */
index d04d24f35f27753b5be65e7eba20c7aeaf2bf6d7..9a07ebb89cc7496d0271943228e1f71570b286a2 100644 (file)
@@ -406,7 +406,7 @@ static int rna_MultiresModifier_external_get(PointerRNA *ptr)
        Object *ob= (Object*)ptr->id.data;
        Mesh *me= ob->data;
 
-       return CustomData_external_test(&me->fdata, CD_MDISPS);
+       return CustomData_external_test(&me->ldata, CD_MDISPS);
 }
 
 static void rna_MultiresModifier_filepath_get(PointerRNA *ptr, char *value)
index 2a369ba9044341590b07322d7d804511cdc42ca7..ee33cfd55d9053bf173e03dbd9c861db34f9cdc2 100644 (file)
@@ -160,7 +160,7 @@ static Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int
                                dm = mesh_create_derived_view( sce, ob, mask );
                        
                        tmpmesh = add_mesh( "Mesh" );
-                       DM_to_mesh( dm, tmpmesh );
+                       DM_to_mesh( dm, tmpmesh, ob );
                        dm->release( dm );
                }
                
index cefad37ea26000701016cbc2dd3e83a920ad088d..46d67010d20a5d1514e153cd0937244392981154 100644 (file)
@@ -576,7 +576,7 @@ int NewBooleanMesh(Scene *scene, Base *base, Base *base_select, int int_op_type)
        ob_new= AddNewBlenderMesh(scene, base_select);
        me_new= ob_new->data;
 
-       DM_to_mesh(result, me_new);
+       DM_to_mesh(result, me_new, ob_new);
        result->release(result);
 
        dm->release(dm);
index 22fba3ceb35d7e7b42e5db74821c0f12c9dd8f92..12fb39ec8a670563e0dab0f1436574ab5fd3fe74 100644 (file)
@@ -113,7 +113,7 @@ DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
        float mtx[4][4], imtx[4][4];
        int i, j, *vtargetmap = NULL;
        BLI_array_declare(vtargetmap);
-       int vector_size=0, a, b;
+       int vector_size=0, a, b, totshape;
        
        origdm = dm;
        if (!CDDM_Check(dm))
@@ -164,6 +164,15 @@ DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
                } else BLI_array_append(vtargetmap, -1);
        }
        
+       /*handle shape keys*/
+       totshape = CustomData_number_of_layers(&cddm->vertData, CD_SHAPEKEY);
+       for (a=0; a<totshape; a++) {
+               float (*cos)[3] = CustomData_get_layer_n(&cddm->vertData, CD_SHAPEKEY, a);
+               for (i=dm->numVertData; i<cddm->numVertData; i++) {
+                       cos[i][axis] = -cos[i][axis];
+               }
+       }
+       
        for (i=0; i<dm->numVertData; i++) {
                BLI_array_append(vtargetmap, -1);
        }