Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-09-19 16:11:28 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-09-19 16:11:28 +0400
commit15ce5f95b3933eaa2be7cbf1e3dcc211138b0f0b (patch)
treef86883086d9ac5f8a6beeb39631a50aa3b30b13d /source/blender/editors/mesh/meshtools.c
parent0d5d2146ebc026c254fc68e4970a1dfb3a9b5b31 (diff)
joining mesh objects now keeps relative key setting of each keyblock. also joining absolute shapekeys now sorts by time.
Diffstat (limited to 'source/blender/editors/mesh/meshtools.c')
-rw-r--r--source/blender/editors/mesh/meshtools.c55
1 files changed, 40 insertions, 15 deletions
diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c
index d2c42e82065..191c831bd79 100644
--- a/source/blender/editors/mesh/meshtools.c
+++ b/source/blender/editors/mesh/meshtools.c
@@ -243,19 +243,24 @@ int join_mesh_exec(bContext *C, wmOperator *op)
/* if this mesh has shapekeys, check if destination mesh already has matching entries too */
if (me->key && key) {
- for (kb = me->key->block.first; kb; kb = kb->next) {
+ /* for remapping KeyBlock.relative */
+ int *index_map = MEM_mallocN(sizeof(int) * me->key->totkey, __func__);
+ KeyBlock **kb_map = MEM_mallocN(sizeof(KeyBlock *) * me->key->totkey, __func__);
+
+ for (kb = me->key->block.first, i = 0; kb; kb = kb->next, i++) {
+ BLI_assert(i < me->key->totkey);
+
+ kbn = BKE_keyblock_find_name(key, kb->name);
/* if key doesn't exist in destination mesh, add it */
- if (BKE_keyblock_find_name(key, kb->name) == NULL) {
+ if (kbn) {
+ index_map[i] = BLI_findindex(&key->block, kbn);
+ }
+ else {
+ index_map[i] = key->totkey;
+
kbn = BKE_keyblock_add(key, kb->name);
-
- /* copy most settings */
- kbn->pos = kb->pos;
- kbn->curval = kb->curval;
- kbn->type = kb->type;
- kbn->relative = kb->relative;
- BLI_strncpy(kbn->vgroup, kb->vgroup, sizeof(kbn->vgroup));
- kbn->slidermin = kb->slidermin;
- kbn->slidermax = kb->slidermax;
+
+ BKE_keyblock_copy_settings(kbn, kb);
/* adjust settings to fit (allocate a new data-array) */
kbn->data = MEM_callocN(sizeof(float) * 3 * totvert, "joined_shapekey");
@@ -270,13 +275,26 @@ int join_mesh_exec(bContext *C, wmOperator *op)
}
#endif
}
+
+ kb_map[i] = kbn;
+ }
+
+ /* remap relative index values */
+ for (kb = me->key->block.first, i = 0; kb; kb = kb->next, i++) {
+ if (LIKELY(kb->relative < me->key->totkey)) { /* sanity check, should always be true */
+ kb_map[i]->relative = index_map[kb->relative];
+ }
}
+
+ MEM_freeN(index_map);
+ MEM_freeN(kb_map);
}
}
}
}
CTX_DATA_END;
-
+
+
/* setup new data for destination mesh */
memset(&vdata, 0, sizeof(vdata));
memset(&edata, 0, sizeof(edata));
@@ -351,7 +369,8 @@ int join_mesh_exec(bContext *C, wmOperator *op)
fp1 = ((float *)kb->data) + (vertofs * 3);
/* check if this mesh has such a shapekey */
- okb = BKE_keyblock_find_name(me->key, kb->name);
+ okb = me->key ? BKE_keyblock_find_name(me->key, kb->name) : NULL;
+
if (okb) {
/* copy this mesh's shapekey to the destination shapekey (need to transform first) */
fp2 = ((float *)(okb->data));
@@ -422,8 +441,8 @@ int join_mesh_exec(bContext *C, wmOperator *op)
if ((mmd = get_multires_modifier(scene, base->object, TRUE))) {
ED_object_iter_other(bmain, base->object, TRUE,
- ED_object_multires_update_totlevels_cb,
- &mmd->totlvl);
+ ED_object_multires_update_totlevels_cb,
+ &mmd->totlvl);
}
}
@@ -543,6 +562,12 @@ int join_mesh_exec(bContext *C, wmOperator *op)
MEM_freeN(nkey);
}
+ /* ensure newly inserted keys are time sorted */
+ if (key && (key->type != KEY_RELATIVE)) {
+ BKE_key_sort(key);
+ }
+
+
DAG_scene_sort(bmain, scene); // removed objects, need to rebuild dag before editmode call
#if 0