diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-10-01 09:43:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-10-01 09:45:57 +0300 |
commit | c06333d77bf085c177ed78282e6b9f010295aef6 (patch) | |
tree | 198310c223455bd103f8888bcbd92a8f50914eae /source | |
parent | 5fca5c8065fc611961d6507bc468494ba358a224 (diff) |
Object Join: use 'selected_editable_objects'
Was using 'selected_editable_bases', which used to save a lookup.
This is no longer the case and complicates access from Python
which cant yet easily access Bases.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/armature/armature_relations.c | 48 | ||||
-rw-r--r-- | source/blender/editors/curve/editcurve.c | 30 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_data.c | 67 | ||||
-rw-r--r-- | source/blender/editors/mesh/meshtools.c | 62 |
4 files changed, 106 insertions, 101 deletions
diff --git a/source/blender/editors/armature/armature_relations.c b/source/blender/editors/armature/armature_relations.c index 1ab5d3dda1f..57b5f27cc91 100644 --- a/source/blender/editors/armature/armature_relations.c +++ b/source/blender/editors/armature/armature_relations.c @@ -247,8 +247,8 @@ int join_armature_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - Object *ob = CTX_data_active_object(C); - bArmature *arm = (ob) ? ob->data : NULL; + Object *ob_active = CTX_data_active_object(C); + bArmature *arm = (ob_active) ? ob_active->data : NULL; bPose *pose, *opose; bPoseChannel *pchan, *pchann; EditBone *curbone; @@ -256,14 +256,14 @@ int join_armature_exec(bContext *C, wmOperator *op) bool ok = false; /* Ensure we're not in editmode and that the active object is an armature*/ - if (!ob || ob->type != OB_ARMATURE) + if (!ob_active || ob_active->type != OB_ARMATURE) return OPERATOR_CANCELLED; if (!arm || arm->edbo) return OPERATOR_CANCELLED; - CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) { - if (base->object == ob) { + if (ob_iter == ob_active) { ok = true; break; } @@ -280,34 +280,34 @@ int join_armature_exec(bContext *C, wmOperator *op) ED_armature_to_edit(arm); /* get pose of active object and move it out of posemode */ - pose = ob->pose; - ob->mode &= ~OB_MODE_POSE; + pose = ob_active->pose; + ob_active->mode &= ~OB_MODE_POSE; - CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) { - if ((base->object->type == OB_ARMATURE) && (base->object != ob)) { + if ((ob_iter->type == OB_ARMATURE) && (ob_iter != ob_active)) { tJoinArmature_AdtFixData afd = {NULL}; - bArmature *curarm = base->object->data; + bArmature *curarm = ob_iter->data; /* we assume that each armature datablock is only used in a single place */ - BLI_assert(ob->data != base->object->data); + BLI_assert(ob_active->data != ob_iter->data); /* init callback data for fixing up AnimData links later */ - afd.srcArm = base->object; - afd.tarArm = ob; + afd.srcArm = ob_iter; + afd.tarArm = ob_active; afd.names_map = BLI_ghash_str_new("join_armature_adt_fix"); /* Make a list of editbones in current armature */ - ED_armature_to_edit(base->object->data); + ED_armature_to_edit(ob_iter->data); /* Get Pose of current armature */ - opose = base->object->pose; - base->object->mode &= ~OB_MODE_POSE; + opose = ob_iter->pose; + ob_iter->mode &= ~OB_MODE_POSE; //BASACT->flag &= ~OB_MODE_POSE; /* Find the difference matrix */ - invert_m4_m4(oimat, ob->obmat); - mul_m4_m4m4(mat, oimat, base->object->obmat); + invert_m4_m4(oimat, ob_active->obmat); + mul_m4_m4m4(mat, oimat, ob_iter->obmat); /* Copy bones and posechannels from the object to the edit armature */ for (pchan = opose->chanbase.first; pchan; pchan = pchann) { @@ -347,7 +347,7 @@ int join_armature_exec(bContext *C, wmOperator *op) } /* Fix Constraints and Other Links to this Bone and Armature */ - joined_armature_fix_links(bmain, ob, base->object, pchan, curbone); + joined_armature_fix_links(bmain, ob_active, ob_iter, pchan, curbone); /* Rename pchan */ BLI_strncpy(pchan->name, curbone->name, sizeof(pchan->name)); @@ -370,14 +370,14 @@ int join_armature_exec(bContext *C, wmOperator *op) * so that we don't have to worry about ambiguities re which armature * a bone came from! */ - if (base->object->adt) { - if (ob->adt == NULL) { + if (ob_iter->adt) { + if (ob_active->adt == NULL) { /* no animdata, so just use a copy of the whole thing */ - ob->adt = BKE_animdata_copy(bmain, base->object->adt, false, true); + ob_active->adt = BKE_animdata_copy(bmain, ob_iter->adt, false, true); } else { /* merge in data - we'll fix the drivers manually */ - BKE_animdata_merge_copy(bmain, &ob->id, &base->object->id, ADT_MERGECOPY_KEEP_DST, false); + BKE_animdata_merge_copy(bmain, &ob_active->id, &ob_iter->id, ADT_MERGECOPY_KEEP_DST, false); } } @@ -393,7 +393,7 @@ int join_armature_exec(bContext *C, wmOperator *op) } /* Free the old object data */ - ED_object_base_free_and_unlink(bmain, scene, base->object); + ED_object_base_free_and_unlink(bmain, scene, ob_iter); } } CTX_DATA_END; diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 9154d72f493..cdd59203cd6 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -6084,7 +6084,7 @@ int join_curve_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - Object *ob = CTX_data_active_object(C); + Object *ob_active = CTX_data_active_object(C); Curve *cu; Nurb *nu, *newnu; BezTriple *bezt; @@ -6094,9 +6094,9 @@ int join_curve_exec(bContext *C, wmOperator *op) int a; bool ok = false; - CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) { - if (base->object == ob) { + if (ob_iter == ob_active) { ok = true; break; } @@ -6112,24 +6112,24 @@ int join_curve_exec(bContext *C, wmOperator *op) BLI_listbase_clear(&tempbase); /* trasnform all selected curves inverse in obact */ - invert_m4_m4(imat, ob->obmat); + invert_m4_m4(imat, ob_active->obmat); - CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) { - if (base->object->type == ob->type) { - if (base->object != ob) { + if (ob_iter->type == ob_active->type) { + if (ob_iter != ob_active) { - cu = base->object->data; + cu = ob_iter->data; if (cu->nurb.first) { /* watch it: switch order here really goes wrong */ - mul_m4_m4m4(cmat, imat, base->object->obmat); + mul_m4_m4m4(cmat, imat, ob_iter->obmat); nu = cu->nurb.first; while (nu) { newnu = BKE_nurb_duplicate(nu); - if (ob->totcol) { /* TODO, merge material lists */ - CLAMP(newnu->mat_nr, 0, ob->totcol - 1); + if (ob_active->totcol) { /* TODO, merge material lists */ + CLAMP(newnu->mat_nr, 0, ob_active->totcol - 1); } else { newnu->mat_nr = 0; @@ -6157,23 +6157,23 @@ int join_curve_exec(bContext *C, wmOperator *op) } } - ED_object_base_free_and_unlink(bmain, scene, base->object); + ED_object_base_free_and_unlink(bmain, scene, ob_iter); } } } CTX_DATA_END; - cu = ob->data; + cu = ob_active->data; BLI_movelisttolist(&cu->nurb, &tempbase); - if (ob->type == OB_CURVE) { + if (ob_active->type == OB_CURVE) { /* Account for mixed 2D/3D curves when joining */ BKE_curve_curve_dimension_update(cu); } DEG_relations_tag_update(bmain); // because we removed object(s), call before editmode! - DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA); + DEG_id_tag_update(&ob_active->id, OB_RECALC_OB | OB_RECALC_DATA); DEG_id_tag_update(&scene->id, DEG_TAG_SELECT_UPDATE); WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c index d2ad38fed3a..068478af325 100644 --- a/source/blender/editors/gpencil/gpencil_data.c +++ b/source/blender/editors/gpencil/gpencil_data.c @@ -2038,27 +2038,27 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); Depsgraph *depsgraph = CTX_data_depsgraph(C); - Object *obact = CTX_data_active_object(C); + Object *ob_active = CTX_data_active_object(C); bGPdata *gpd_dst = NULL; bool ok = false; /* Ensure we're in right mode and that the active object is correct */ - if (!obact || obact->type != OB_GPENCIL) + if (!ob_active || ob_active->type != OB_GPENCIL) return OPERATOR_CANCELLED; - bGPdata *gpd = (bGPdata *)obact->data; + bGPdata *gpd = (bGPdata *)ob_active->data; if ((!gpd) || GPENCIL_ANY_MODE(gpd)) { return OPERATOR_CANCELLED; } /* Ensure all rotations are applied before */ // XXX: Why don't we apply them here instead of warning? - CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) { - if (base->object->type == OB_GPENCIL) { - if ((base->object->rot[0] != 0) || - (base->object->rot[1] != 0) || - (base->object->rot[2] != 0)) + if (ob_iter->type == OB_GPENCIL) { + if ((ob_iter->rot[0] != 0) || + (ob_iter->rot[1] != 0) || + (ob_iter->rot[2] != 0)) { BKE_report(op->reports, RPT_ERROR, "Apply all rotations before join objects"); return OPERATOR_CANCELLED; @@ -2067,9 +2067,9 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) { - if (base->object == obact) { + if (ob_iter == ob_active) { ok = true; break; } @@ -2082,33 +2082,33 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - gpd_dst = obact->data; - Object *ob_dst = obact; + gpd_dst = ob_active->data; + Object *ob_dst = ob_active; /* loop and join all data */ - CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) { - if ((base->object->type == OB_GPENCIL) && (base->object != obact)) { + if ((ob_iter->type == OB_GPENCIL) && (ob_iter != ob_active)) { /* we assume that each datablock is not already used in active object */ - if (obact->data != base->object->data) { - Object *ob_src = base->object; - bGPdata *gpd_src = base->object->data; + if (ob_active->data != ob_iter->data) { + Object *ob_src = ob_iter; + bGPdata *gpd_src = ob_iter->data; /* Apply all GP modifiers before */ - for (GpencilModifierData *md = base->object->greasepencil_modifiers.first; md; md = md->next) { + for (GpencilModifierData *md = ob_iter->greasepencil_modifiers.first; md; md = md->next) { const GpencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(md->type); if (mti->bakeModifier) { - mti->bakeModifier(bmain, depsgraph, md, base->object); + mti->bakeModifier(bmain, depsgraph, md, ob_iter); } } /* copy vertex groups to the base one's */ int old_idx = 0; - for (bDeformGroup *dg = base->object->defbase.first; dg; dg = dg->next) { + for (bDeformGroup *dg = ob_iter->defbase.first; dg; dg = dg->next) { bDeformGroup *vgroup = MEM_dupallocN(dg); - int idx = BLI_listbase_count(&obact->defbase); - defgroup_unique_name(vgroup, obact); - BLI_addtail(&obact->defbase, vgroup); + int idx = BLI_listbase_count(&ob_active->defbase); + defgroup_unique_name(vgroup, ob_active); + BLI_addtail(&ob_active->defbase, vgroup); /* update vertex groups in strokes in original data */ for (bGPDlayer *gpl_src = gpd->layers.first; gpl_src; gpl_src = gpl_src->next) { for (bGPDframe *gpf = gpl_src->frames.first; gpf; gpf = gpf->next) { @@ -2125,8 +2125,9 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) } old_idx++; } - if (obact->defbase.first && obact->actdef == 0) - obact->actdef = 1; + if (ob_active->defbase.first && ob_active->actdef == 0) { + ob_active->actdef = 1; + } /* add missing materials reading source materials and checking in destination object */ short *totcol = give_totcolp(ob_src); @@ -2149,8 +2150,8 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) float offset_global[3]; float offset_local[3]; - sub_v3_v3v3(offset_global, obact->loc, base->object->obmat[3]); - copy_m3_m4(bmat, obact->obmat); + sub_v3_v3v3(offset_global, ob_active->loc, ob_iter->obmat[3]); + copy_m3_m4(bmat, ob_active->obmat); invert_m3_m3(imat, bmat); mul_m3_v3(imat, offset_global); mul_v3_m3v3(offset_local, imat, offset_global); @@ -2162,7 +2163,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) float inverse_diff_mat[4][4]; /* recalculate all stroke points */ - ED_gpencil_parent_location(depsgraph, base->object, gpd_src, gpl_src, diff_mat); + ED_gpencil_parent_location(depsgraph, ob_iter, gpd_src, gpl_src, diff_mat); invert_m4_m4(inverse_diff_mat, diff_mat); Material *ma_src = NULL; @@ -2212,14 +2213,14 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) * so that we don't have to worry about ambiguities re which datablock * a layer came from! */ - if (base->object->adt) { - if (obact->adt == NULL) { + if (ob_iter->adt) { + if (ob_active->adt == NULL) { /* no animdata, so just use a copy of the whole thing */ - obact->adt = BKE_animdata_copy(bmain, base->object->adt, false, true); + ob_active->adt = BKE_animdata_copy(bmain, ob_iter->adt, false, true); } else { /* merge in data - we'll fix the drivers manually */ - BKE_animdata_merge_copy(bmain, &obact->id, &base->object->id, ADT_MERGECOPY_KEEP_DST, false); + BKE_animdata_merge_copy(bmain, &ob_active->id, &ob_iter->id, ADT_MERGECOPY_KEEP_DST, false); } } @@ -2236,7 +2237,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) } /* Free the old object */ - ED_object_base_free_and_unlink(bmain, scene, base->object); + ED_object_base_free_and_unlink(bmain, scene, ob_iter); } } CTX_DATA_END; diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index b4033af1523..84f209b5889 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -298,18 +298,18 @@ int join_mesh_exec(bContext *C, wmOperator *op) Depsgraph *depsgraph = CTX_data_depsgraph(C); /* count & check */ - CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) { - if (base->object->type == OB_MESH) { - me = base->object->data; + if (ob_iter->type == OB_MESH) { + me = ob_iter->data; totvert += me->totvert; totedge += me->totedge; totloop += me->totloop; totpoly += me->totpoly; - totmat += base->object->totcol; + totmat += ob_iter->totcol; - if (base->object == ob) + if (ob_iter == ob) ok = true; /* check for shapekeys */ @@ -379,14 +379,14 @@ int join_mesh_exec(bContext *C, wmOperator *op) } /* first pass over objects - copying materials and vertexgroups across */ - CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) { /* only act if a mesh, and not the one we're joining to */ - if ((ob != base->object) && (base->object->type == OB_MESH)) { - me = base->object->data; + if ((ob != ob_iter) && (ob_iter->type == OB_MESH)) { + me = ob_iter->data; /* Join this object's vertex groups to the base one's */ - for (dg = base->object->defbase.first; dg; dg = dg->next) { + for (dg = ob_iter->defbase.first; dg; dg = dg->next) { /* See if this group exists in the object (if it doesn't, add it to the end) */ if (!defgroup_find_name(ob, dg->name)) { odg = MEM_callocN(sizeof(bDeformGroup), "join deformGroup"); @@ -401,8 +401,8 @@ int join_mesh_exec(bContext *C, wmOperator *op) if (me->totvert) { /* Add this object's materials to the base one's if they don't exist already (but only if limits not exceeded yet) */ if (totcol < MAXMAT) { - for (a = 1; a <= base->object->totcol; a++) { - ma = give_current_material(base->object, a); + for (a = 1; a <= ob_iter->totcol; a++) { + ma = give_current_material(ob_iter, a); for (b = 0; b < totcol; b++) { if (ma == matar[b]) { @@ -500,16 +500,16 @@ int join_mesh_exec(bContext *C, wmOperator *op) matar, matmap, totcol, &vertofs, &edgeofs, &loopofs, &polyofs); - CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) { - if (base->object == ob) { + if (ob_iter == ob) { continue; } /* only join if this is a mesh */ - if (base->object->type == OB_MESH) { + if (ob_iter->type == OB_MESH) { join_mesh_single( depsgraph, bmain, scene, - ob, base->object, imat, + ob, ob_iter, imat, &mvert, &medge, &mloop, &mpoly, &vdata, &edata, &ldata, &pdata, totvert, totedge, totloop, totpoly, @@ -518,8 +518,8 @@ int join_mesh_exec(bContext *C, wmOperator *op) &vertofs, &edgeofs, &loopofs, &polyofs); /* free base, now that data is merged */ - if (base->object != ob) { - ED_object_base_free_and_unlink(bmain, scene, base->object); + if (ob_iter != ob) { + ED_object_base_free_and_unlink(bmain, scene, ob_iter); } } } @@ -609,21 +609,23 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - Object *ob = CTX_data_active_object(C); + Object *ob_active = CTX_data_active_object(C); Depsgraph *depsgraph = CTX_data_depsgraph(C); - Mesh *me = (Mesh *)ob->data; + Mesh *me = (Mesh *)ob_active->data; Mesh *selme = NULL; Mesh *me_deformed = NULL; Key *key = me->key; KeyBlock *kb; bool ok = false, nonequal_verts = false; - CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) { - if (base->object == ob) continue; + if (ob_iter == ob_active) { + continue; + } - if (base->object->type == OB_MESH) { - selme = (Mesh *)base->object->data; + if (ob_iter->type == OB_MESH) { + selme = (Mesh *)ob_iter->data; if (selme->totvert == me->totvert) ok = true; @@ -651,21 +653,23 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) } /* now ready to add new keys from selected meshes */ - CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) { - if (base->object == ob) continue; + if (ob_iter == ob_active) { + continue; + } - if (base->object->type == OB_MESH) { - selme = (Mesh *)base->object->data; + if (ob_iter->type == OB_MESH) { + selme = (Mesh *)ob_iter->data; if (selme->totvert == me->totvert) { - me_deformed = mesh_get_eval_deform(depsgraph, scene, base->object, CD_MASK_BAREMESH); + me_deformed = mesh_get_eval_deform(depsgraph, scene, ob_iter, CD_MASK_BAREMESH); if (!me_deformed) { continue; } - kb = BKE_keyblock_add(key, base->object->id.name + 2); + kb = BKE_keyblock_add(key, ob_iter->id.name + 2); BKE_mesh_runtime_eval_to_meshkey(me_deformed, me, kb); } |