diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2017-05-22 23:49:02 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2017-05-22 23:49:02 +0300 |
commit | 44f91a9a18d6d942d958e7640f4d1c301d230150 (patch) | |
tree | e7e97a57a920f02e87b7539740590a5058f7614e /source/blender/editors/mesh | |
parent | 6cc293a6d97a2f8277660613a1ced9b2688bd7c0 (diff) | |
parent | 9b2923380092c7e3c771d354f8938c5ca20bfd9d (diff) |
Merge branch 'master' into blender2.8
Conflicts:
source/blender/blenloader/intern/versioning_270.c
Diffstat (limited to 'source/blender/editors/mesh')
-rw-r--r-- | source/blender/editors/mesh/meshtools.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index be5f1013630..8727511035e 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -104,22 +104,26 @@ static void join_mesh_single( /* vertex groups */ MDeformVert *dvert = CustomData_get(vdata, *vertofs, CD_MDEFORMVERT); + MDeformVert *dvert_src = CustomData_get(&me->vdata, 0, CD_MDEFORMVERT); - /* NB: vertex groups here are new version */ - if (dvert) { - for (a = 0; a < me->totvert; a++) { - for (b = 0; b < dvert[a].totweight; b++) { - /* Find the old vertex group */ - bDeformGroup *dg, *odg = BLI_findlink(&base_src->object->defbase, dvert[a].dw[b].def_nr); - int index; - if (odg) { - /* Search for a match in the new object, and set new index */ - for (dg = ob_dst->defbase.first, index = 0; dg; dg = dg->next, index++) { - if (STREQ(dg->name, odg->name)) { - dvert[a].dw[b].def_nr = index; - break; - } - } + /* Remap to correct new vgroup indices, if needed. */ + if (dvert_src) { + BLI_assert(dvert != NULL); + + /* Build src to merged mapping of vgroup indices. */ + bDeformGroup *dg_src; + int *vgroup_index_map = alloca(sizeof(*vgroup_index_map) * BLI_listbase_count(&base_src->object->defbase)); + bool is_vgroup_remap_needed = false; + + for (dg_src = base_src->object->defbase.first, b = 0; dg_src; dg_src = dg_src->next, b++) { + vgroup_index_map[b] = defgroup_name_index(ob_dst, dg_src->name); + is_vgroup_remap_needed = is_vgroup_remap_needed || (vgroup_index_map[b] != b); + } + + if (is_vgroup_remap_needed) { + for (a = 0; a < me->totvert; a++) { + for (b = 0; b < dvert[a].totweight; b++) { + dvert[a].dw[b].def_nr = vgroup_index_map[dvert_src[a].dw[b].def_nr]; } } } |