diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-11 19:24:13 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-11 19:24:13 +0400 |
commit | 1f6369fd41c8821d876b7fe0d717655b2d89c319 (patch) | |
tree | eb86eeba81fa574c7729804801bb9d3238138949 /source/blender | |
parent | e7b7bc12725032a82740a752026e396c8d25a5a9 (diff) |
bmesh shape key conversion on exiting editmode.
there were 2 blocks of code (both calculating the offset array), now move the fallback method into the main key conversions block.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh_conv.c | 118 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_key_types.h | 30 |
2 files changed, 63 insertions, 85 deletions
diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.c b/source/blender/bmesh/intern/bmesh_mesh_conv.c index cc4b4683c6a..b5aad355ab6 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_conv.c +++ b/source/blender/bmesh/intern/bmesh_mesh_conv.c @@ -498,8 +498,7 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, int dotess) BMLoop *l; BMFace *f; BMIter iter, liter; - int i, j, *keyi, ototvert; - int use_old_key_code_fallback = FALSE; + int i, j, ototvert; ototvert = me->totvert; @@ -766,12 +765,16 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, int dotess) for (currkey = me->key->block.first; currkey; currkey = currkey->next) { + int apply_offset = (ofs && (currkey != actkey) && (bm->shapenr - 1 == currkey->relative)); + int *keyi; + float (*ofs_pt)[3] = ofs; + float *fp; + j = bm_to_mesh_shape_layer_index_from_kb(bm, currkey); if (j != -1) { - int apply_offset = (ofs && (currkey != actkey) && (bm->shapenr - 1 == currkey->relative)); - float *fp, *co; - float (*ofs_pt)[3] = ofs; + /* new bmesh conversion method */ + float *co; if (currkey->data) MEM_freeN(currkey->data); @@ -806,91 +809,58 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, int dotess) else { /* if we didn't find a shapekey, tag the block to be reconstructed * via the old method below */ - currkey->flag |= KEYBLOCK_MISSING; - use_old_key_code_fallback = TRUE; - } - } - - if (ofs) MEM_freeN(ofs); - } - - /* XXX, code below is from trunk and a duplicate functionality - * to the block above. - * We should use one or the other, having both means we have to maintain - * both and keep them working the same way which is a hassle - campbell */ - - /* old method of reconstructing keys via vertice's original key indices, - * currently used if the new method above fails (which is theoretically - * possible in certain cases of undo) */ - if (me->key && use_old_key_code_fallback) { - float *fp, *newkey, *oldkey; - KeyBlock *currkey; - KeyBlock *actkey = BLI_findlink(&me->key->block, bm->shapenr - 1); - - float (*ofs)[3] = NULL; - - /* editing the base key should update others */ - if (me->key->type == KEY_RELATIVE && oldverts) { - ofs = bm_to_mesh_shape_basis_offset(me, bm); /* may be NULL */ - } - - /* Lets reorder the key data so that things line up roughly - * with the way things were before editmode */ - for (currkey = me->key->block.first; currkey; currkey = currkey->next) { - int apply_offset = (ofs && (currkey != actkey) && (bm->shapenr - 1 == currkey->relative)); - if (!(currkey->flag & KEYBLOCK_MISSING)) { - currkey = currkey->next; - continue; - } + /* old method of reconstructing keys via vertice's original key indices, + * currently used if the new method above fails (which is theoretically + * possible in certain cases of undo) */ - printf("warning: had to hackishly reconstruct shape key \"%s\"," - " it may not be correct anymore.\n", currkey->name); + float *newkey, *oldkey; - currkey->flag &= ~KEYBLOCK_MISSING; + printf("warning: had to hackishly reconstruct shape key \"%s\"," + " it may not be correct anymore.\n", currkey->name); - fp = newkey = MEM_callocN(me->key->elemsize * bm->totvert, "currkey->data"); - oldkey = currkey->data; + fp = newkey = MEM_callocN(me->key->elemsize * bm->totvert, "currkey->data"); + oldkey = currkey->data; - eve = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL); - - mvert = me->mvert; - BM_ITER_INDEX(eve, &iter, bm, BM_VERTS_OF_MESH, NULL, i) { - keyi = CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_SHAPE_KEYINDEX); + mvert = me->mvert; + BM_ITER(eve, &iter, bm, BM_VERTS_OF_MESH, NULL) { + keyi = CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_SHAPE_KEYINDEX); - if (keyi && *keyi != ORIGINDEX_NONE && *keyi < currkey->totelem) { /* valid old vertex */ - if (currkey == actkey) { - if (actkey == me->key->refkey) { - copy_v3_v3(fp, mvert->co); + if (keyi && *keyi != ORIGINDEX_NONE && *keyi < currkey->totelem) { /* valid old vertex */ + if (currkey == actkey) { + if (actkey == me->key->refkey) { + copy_v3_v3(fp, mvert->co); + } + else { + copy_v3_v3(fp, mvert->co); + if (oldverts) { + copy_v3_v3(mvert->co, oldverts[*keyi].co); + } + } } else { - copy_v3_v3(fp, mvert->co); - if (oldverts) { - copy_v3_v3(mvert->co, oldverts[*keyi].co); + if (oldkey) { + copy_v3_v3(fp, oldkey + 3 * *keyi); } } } else { - if (oldkey) { - copy_v3_v3(fp, oldkey + 3 * *keyi); - } + copy_v3_v3(fp, mvert->co); } - } - else { - copy_v3_v3(fp, mvert->co); - } - /* propagate edited basis offsets to other shapes */ - if (apply_offset) { - add_v3_v3(fp, ofs[i]); - } + /* propagate edited basis offsets to other shapes */ + if (apply_offset) { + add_v3_v3(fp, *ofs_pt++); + } - fp += 3; - mvert++; + fp += 3; + mvert++; + } + currkey->totelem = bm->totvert; + if (currkey->data) MEM_freeN(currkey->data); + currkey->data = newkey; + /* end old compad code */ } - currkey->totelem = bm->totvert; - if (currkey->data) MEM_freeN(currkey->data); - currkey->data = newkey; } if (ofs) MEM_freeN(ofs); diff --git a/source/blender/makesdna/DNA_key_types.h b/source/blender/makesdna/DNA_key_types.h index 611f4c2a25f..85d8b9bec7e 100644 --- a/source/blender/makesdna/DNA_key_types.h +++ b/source/blender/makesdna/DNA_key_types.h @@ -83,20 +83,28 @@ typedef struct Key { /* **************** KEY ********************* */ /* key->type */ -#define KEY_NORMAL 0 -#define KEY_RELATIVE 1 +enum { + KEY_NORMAL = 0, + KEY_RELATIVE = 1 +}; /* key->flag */ -#define KEY_DS_EXPAND 1 +enum { + KEY_DS_EXPAND = 1 +}; /* keyblock->type */ -#define KEY_LINEAR 0 -#define KEY_CARDINAL 1 -#define KEY_BSPLINE 2 +enum { + KEY_LINEAR = 0, + KEY_CARDINAL = 1, + KEY_BSPLINE = 2 +}; /* keyblock->flag */ -#define KEYBLOCK_MUTE (1<<0) -#define KEYBLOCK_SEL (1<<1) -#define KEYBLOCK_LOCKED (1<<2) -#define KEYBLOCK_MISSING (1<<3) /*temporary flag*/ -#endif +enum { + KEYBLOCK_MUTE = (1 << 0), + KEYBLOCK_SEL = (1 << 1), + KEYBLOCK_LOCKED = (1 << 2) +}; + +#endif /* __DNA_KEY_TYPES_H__ */ |