From 620b960d3d8cfd90b9f0df6ba3671c33eccb8309 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 22 Apr 2019 09:19:45 +1000 Subject: Cleanup: style, use braces for editors --- source/blender/editors/armature/armature_add.c | 72 +++-- source/blender/editors/armature/armature_edit.c | 84 ++++-- source/blender/editors/armature/armature_naming.c | 24 +- .../blender/editors/armature/armature_relations.c | 33 ++- source/blender/editors/armature/armature_select.c | 84 ++++-- .../blender/editors/armature/armature_skinning.c | 42 ++- source/blender/editors/armature/armature_utils.c | 45 ++- source/blender/editors/armature/meshlaplacian.c | 312 ++++++++++++++------- source/blender/editors/armature/pose_edit.c | 27 +- source/blender/editors/armature/pose_group.c | 60 ++-- source/blender/editors/armature/pose_lib.c | 174 ++++++++---- source/blender/editors/armature/pose_select.c | 66 +++-- source/blender/editors/armature/pose_slide.c | 54 ++-- source/blender/editors/armature/pose_transform.c | 105 ++++--- source/blender/editors/armature/pose_utils.c | 27 +- 15 files changed, 806 insertions(+), 403 deletions(-) (limited to 'source/blender/editors/armature') diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c index 40526eb82fe..3b65f3a71ed 100644 --- a/source/blender/editors/armature/armature_add.c +++ b/source/blender/editors/armature/armature_add.c @@ -137,20 +137,23 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op)) /* find the active or selected bone */ for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { if (EBONE_VISIBLE(arm, ebone)) { - if (ebone->flag & BONE_TIPSEL || arm->act_edbone == ebone) + if (ebone->flag & BONE_TIPSEL || arm->act_edbone == ebone) { break; + } } } if (ebone == NULL) { for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { if (EBONE_VISIBLE(arm, ebone)) { - if (ebone->flag & BONE_ROOTSEL || arm->act_edbone == ebone) + if (ebone->flag & BONE_ROOTSEL || arm->act_edbone == ebone) { break; + } } } - if (ebone == NULL) + if (ebone == NULL) { return OPERATOR_CANCELLED; + } to_root = 1; } @@ -159,13 +162,15 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op)) /* we re-use code for mirror editing... */ flipbone = NULL; - if (arm->flag & ARM_MIRROR_EDIT) + if (arm->flag & ARM_MIRROR_EDIT) { flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone); + } for (a = 0; a < 2; a++) { if (a == 1) { - if (flipbone == NULL) + if (flipbone == NULL) { break; + } else { SWAP(EditBone *, flipbone, ebone); } @@ -190,8 +195,9 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op)) copy_v3_v3(newbone->tail, curs->location); sub_v3_v3v3(newbone->tail, newbone->tail, obedit->obmat[3]); - if (a == 1) + if (a == 1) { newbone->tail[0] = -newbone->tail[0]; + } copy_m3_m4(mat, obedit->obmat); invert_m3_m3(imat, mat); @@ -279,8 +285,9 @@ static EditBone *get_named_editbone(ListBase *edbo, const char *name) if (name) { for (eBone = edbo->first; eBone; eBone = eBone->next) { - if (STREQ(name, eBone->name)) + if (STREQ(name, eBone->name)) { return eBone; + } } } @@ -410,8 +417,9 @@ void updateDuplicateSubtargetObjects(EditBone *dupBone, } } - if (cti->flush_constraint_targets) + if (cti->flush_constraint_targets) { cti->flush_constraint_targets(curcon, &targets, 0); + } } } } @@ -442,8 +450,9 @@ EditBone *duplicateEditBoneObjects( BLI_addtail(editbones, eBone); /* copy the ID property */ - if (curBone->prop) + if (curBone->prop) { eBone->prop = IDP_CopyProperty(curBone->prop); + } /* Lets duplicate the list of constraints that the * current bone has. @@ -478,8 +487,9 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *op) const bool do_flip_names = RNA_boolean_get(op->ptr, "do_flip_names"); /* cancel if nothing selected */ - if (CTX_DATA_COUNT(C, selected_bones) == 0) + if (CTX_DATA_COUNT(C, selected_bones) == 0) { return OPERATOR_CANCELLED; + } uint objects_len = 0; Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( @@ -888,8 +898,9 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) if (EBONE_VISIBLE(arm, ebone)) { if (ebone->flag & BONE_ROOTSEL) { if (ebone->parent && (ebone->flag & BONE_CONNECTED)) { - if (ebone->parent->flag & BONE_TIPSEL) + if (ebone->parent->flag & BONE_TIPSEL) { ebone->flag &= ~BONE_ROOTSEL; + } } } } @@ -920,18 +931,21 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone); if (flipbone) { forked_iter = 0; // we extrude 2 different bones - if (flipbone->flag & (BONE_TIPSEL | BONE_ROOTSEL | BONE_SELECTED)) + if (flipbone->flag & (BONE_TIPSEL | BONE_ROOTSEL | BONE_SELECTED)) { /* don't want this bone to be selected... */ flipbone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL); + } } - if ((flipbone == NULL) && (forked_iter)) + if ((flipbone == NULL) && (forked_iter)) { flipbone = ebone; + } } for (a = 0; a < 2; a++) { if (a == 1) { - if (flipbone == NULL) + if (flipbone == NULL) { break; + } else { SWAP(EditBone *, flipbone, ebone); } @@ -948,8 +962,9 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) /* copies it, in case mirrored bone */ newbone->flag = ebone->flag & (BONE_TIPSEL | BONE_RELATIVE_PARENTING); - if (newbone->parent) + if (newbone->parent) { newbone->flag |= BONE_CONNECTED; + } } else { copy_v3_v3(newbone->head, ebone->head); @@ -988,22 +1003,26 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) if (flipbone && forked_iter) { // only set if mirror edit if (strlen(newbone->name) < (MAXBONENAME - 2)) { - if (a == 0) + if (a == 0) { strcat(newbone->name, "_L"); - else + } + else { strcat(newbone->name, "_R"); + } } } ED_armature_ebone_unique_name(arm->edbo, newbone->name, NULL); /* Add the new bone to the list */ BLI_addtail(arm->edbo, newbone); - if (!first) + if (!first) { first = newbone; + } /* restore ebone if we were flipping */ - if (a == 1 && flipbone) + if (a == 1 && flipbone) { SWAP(EditBone *, flipbone, ebone); + } } } @@ -1073,10 +1092,12 @@ static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op) invert_m4_m4(obedit->imat, obedit->obmat); mul_m4_v3(obedit->imat, curs); - if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) + if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) { copy_m3_m4(obmat, rv3d->viewmat); - else + } + else { unit_m3(obmat); + } copy_m3_m4(viewmat, obedit->obmat); mul_m3_m3m3(totmat, obmat, viewmat); @@ -1089,10 +1110,12 @@ static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op) copy_v3_v3(bone->head, curs); - if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) + if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) { add_v3_v3v3(bone->tail, bone->head, imat[1]); // bone with unit length 1 - else + } + else { add_v3_v3v3(bone->tail, bone->head, imat[2]); // bone with unit length 1, pointing up Z + } /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit); @@ -1174,8 +1197,9 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op) /* correct parent bones */ for (tbone = arm->edbo->first; tbone; tbone = tbone->next) { - if (tbone->parent == ebone) + if (tbone->parent == ebone) { tbone->parent = newbone; + } } newbone->parent = ebone; } diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c index ad563e569c3..c5430e06b6e 100644 --- a/source/blender/editors/armature/armature_edit.c +++ b/source/blender/editors/armature/armature_edit.c @@ -334,8 +334,9 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op) if (EBONE_VISIBLE(arm, ebone) && EBONE_EDITABLE(ebone)) { float cursor_rel[3]; sub_v3_v3v3(cursor_rel, cursor_local, ebone->head); - if (axis_flip) + if (axis_flip) { negate_v3(cursor_rel); + } if (normalize_v3(cursor_rel) != 0.0f) { ebone->roll = ED_armature_ebone_roll_to_vector(ebone, cursor_rel, axis_only); changed = true; @@ -375,8 +376,9 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op) (ebone_other = ebone_other->parent)); if (!is_vec_zero) { - if (axis_flip) + if (axis_flip) { negate_v3(vec); + } if (is_edit) { ebone->roll = ED_armature_ebone_roll_to_vector(ebone, vec, axis_only); @@ -424,16 +426,19 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op) } else { /* Axis */ assert(type <= 5); - if (type < 3) + if (type < 3) { vec[type] = 1.0f; - else + } + else { vec[type - 2] = -1.0f; + } mul_m3_v3(imat, vec); normalize_v3(vec); } - if (axis_flip) + if (axis_flip) { negate_v3(vec); + } for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { if (EBONE_VISIBLE(arm, ebone) && EBONE_EDITABLE(ebone)) { @@ -591,12 +596,14 @@ static void chains_find_tips(ListBase *edbo, ListBase *list) } } - if (stop) + if (stop) { break; + } } /* skip current bone if it is part of an existing chain */ - if (stop) + if (stop) { continue; + } /* is any existing chain part of the chain formed by this bone? */ stop = 0; @@ -609,12 +616,14 @@ static void chains_find_tips(ListBase *edbo, ListBase *list) } } - if (stop) + if (stop) { break; + } } /* current bone has already been added to a chain? */ - if (stop) + if (stop) { continue; + } /* add current bone to a new chain */ ld = MEM_callocN(sizeof(LinkData), "BoneChain"); @@ -817,17 +826,21 @@ static int armature_fill_bones_exec(bContext *C, wmOperator *op) /* do parenting (will need to set connected flag too) */ if (headtail == 2) { /* ebp tail or head - tail gets priority */ - if (ebp_a->tail_owner) + if (ebp_a->tail_owner) { newbone->parent = ebp_a->tail_owner; - else + } + else { newbone->parent = ebp_a->head_owner; + } } else { /* ebp_b tail or head - tail gets priority */ - if (ebp_b->tail_owner) + if (ebp_b->tail_owner) { newbone->parent = ebp_b->tail_owner; - else + } + else { newbone->parent = ebp_b->head_owner; + } } /* don't set for bone connecting two head points of bones */ @@ -940,14 +953,16 @@ static void bones_merge( } /* carry on to the next tip now */ - if (found) + if (found) { break; + } } } /* step 2b: parent child of end to newbone (child from this chain) */ - if (endchild) + if (endchild) { endchild->parent = newbone; + } /* step 3: delete all bones between and including start and end */ for (ebo = end; ebo; ebo = ebone) { @@ -1006,13 +1021,15 @@ static int armature_merge_exec(bContext *C, wmOperator *op) bend = ebo; bchild = child; } - else + else { bstart = ebo; + } } else { /* chain is broken... merge any continuous segments then clear */ - if (bstart && bend) + if (bstart && bend) { bones_merge(obedit, bstart, bend, bchild, &chains); + } bstart = NULL; bend = NULL; @@ -1021,8 +1038,9 @@ static int armature_merge_exec(bContext *C, wmOperator *op) } /* merge from bstart to bend if something not merged */ - if (bstart && bend) + if (bstart && bend) { bones_merge(obedit, bstart, bend, bchild, &chains); + } /* put back link */ BLI_insertlinkbefore(&chains, nchain, chain); @@ -1137,10 +1155,12 @@ static int armature_switch_direction_exec(bContext *C, wmOperator *UNUSED(op)) * - connected flag is only set if points are coincidental */ ebo->parent = child; - if ((child) && equals_v3v3(ebo->head, child->tail)) + if ((child) && equals_v3v3(ebo->head, child->tail)) { ebo->flag |= BONE_CONNECTED; - else + } + else { ebo->flag &= ~BONE_CONNECTED; + } /* get next bones * - child will become the new parent of next bone @@ -1207,8 +1227,9 @@ static void fix_connected_bone(EditBone *ebone) float diff[3]; if (!(ebone->parent) || !(ebone->flag & BONE_CONNECTED) || - equals_v3v3(ebone->parent->tail, ebone->head)) + equals_v3v3(ebone->parent->tail, ebone->head)) { return; + } /* if the parent has moved we translate child's head and tail accordingly */ sub_v3_v3v3(diff, ebone->parent->tail, ebone->head); @@ -1271,8 +1292,9 @@ static int armature_align_bones_exec(bContext *C, wmOperator *op) * then just use actbone. Useful when doing upper arm to spine. */ actmirb = ED_armature_ebone_get_mirrored(arm->edbo, actbone); - if (actmirb == NULL) + if (actmirb == NULL) { actmirb = actbone; + } } /* if there is only 1 selected bone, we assume that that is the active bone, @@ -1286,8 +1308,9 @@ static int armature_align_bones_exec(bContext *C, wmOperator *op) if (actbone->parent) { bone_align_to_bone(arm->edbo, actbone, actbone->parent); - if ((arm->flag & ARM_MIRROR_EDIT) && (actmirb->parent)) + if ((arm->flag & ARM_MIRROR_EDIT) && (actmirb->parent)) { bone_align_to_bone(arm->edbo, actmirb, actmirb->parent); + } BKE_reportf(op->reports, RPT_INFO, "Aligned bone '%s' to parent", actbone->name); } @@ -1304,10 +1327,12 @@ static int armature_align_bones_exec(bContext *C, wmOperator *op) /* align selected bones to the active one */ CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) { if (ELEM(ebone, actbone, actmirb) == 0) { - if (ebone->flag & BONE_SELECTED) + if (ebone->flag & BONE_SELECTED) { bone_align_to_bone(arm->edbo, ebone, actbone); - else + } + else { bone_align_to_bone(arm->edbo, ebone, actmirb); + } } } CTX_DATA_END; @@ -1401,8 +1426,9 @@ static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op)) bool changed_multi = false; /* cancel if nothing selected */ - if (CTX_DATA_COUNT(C, selected_bones) == 0) + if (CTX_DATA_COUNT(C, selected_bones) == 0) { return OPERATOR_CANCELLED; + } ViewLayer *view_layer = CTX_data_view_layer(C); uint objects_len = 0; @@ -1421,8 +1447,9 @@ static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op)) ebone_next = curBone->next; if (arm->layer & curBone->layer) { if (curBone->flag & BONE_SELECTED) { - if (curBone == arm->act_edbone) + if (curBone == arm->act_edbone) { arm->act_edbone = NULL; + } ED_armature_ebone_remove(arm, curBone); changed = true; } @@ -1643,8 +1670,9 @@ static int armature_hide_exec(bContext *C, wmOperator *op) const int invert = RNA_boolean_get(op->ptr, "unselected") ? BONE_SELECTED : 0; /* cancel if nothing selected */ - if (CTX_DATA_COUNT(C, selected_bones) == 0) + if (CTX_DATA_COUNT(C, selected_bones) == 0) { return OPERATOR_CANCELLED; + } uint objects_len = 0; Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( diff --git a/source/blender/editors/armature/armature_naming.c b/source/blender/editors/armature/armature_naming.c index 6bf289c1b95..6d25fac79f6 100644 --- a/source/blender/editors/armature/armature_naming.c +++ b/source/blender/editors/armature/armature_naming.c @@ -130,8 +130,9 @@ static void constraint_bone_name_fix(Object *ob, } } - if (cti->flush_constraint_targets) + if (cti->flush_constraint_targets) { cti->flush_constraint_targets(curcon, &targets, 0); + } } /* action constraints */ @@ -221,8 +222,9 @@ void ED_armature_bone_rename(Main *bmain, /* Update any object constraints to use the new bone name */ for (cob = bmain->objects.first; cob; cob = cob->id.next) { - if (cob->constraints.first) + if (cob->constraints.first) { constraint_bone_name_fix(ob, &cob->constraints, oldname, newname); + } if (cob->pose) { bPoseChannel *pchan; for (pchan = cob->pose->chanbase.first; pchan; pchan = pchan->next) { @@ -236,8 +238,9 @@ void ED_armature_bone_rename(Main *bmain, if (ob->parent && (ob->parent->data == arm)) { if (ob->partype == PARBONE) { /* bone name in object */ - if (STREQ(ob->parsubstr, oldname)) + if (STREQ(ob->parsubstr, oldname)) { BLI_strncpy(ob->parsubstr, newname, MAXBONENAME); + } } } @@ -255,8 +258,9 @@ void ED_armature_bone_rename(Main *bmain, HookModifierData *hmd = (HookModifierData *)md; if (hmd->object && (hmd->object->data == arm)) { - if (STREQ(hmd->subtarget, oldname)) + if (STREQ(hmd->subtarget, oldname)) { BLI_strncpy(hmd->subtarget, newname, MAXBONENAME); + } } break; } @@ -264,12 +268,14 @@ void ED_armature_bone_rename(Main *bmain, UVWarpModifierData *umd = (UVWarpModifierData *)md; if (umd->object_src && (umd->object_src->data == arm)) { - if (STREQ(umd->bone_src, oldname)) + if (STREQ(umd->bone_src, oldname)) { BLI_strncpy(umd->bone_src, newname, MAXBONENAME); + } } if (umd->object_dst && (umd->object_dst->data == arm)) { - if (STREQ(umd->bone_dst, oldname)) + if (STREQ(umd->bone_dst, oldname)) { BLI_strncpy(umd->bone_dst, newname, MAXBONENAME); + } } break; } @@ -284,8 +290,9 @@ void ED_armature_bone_rename(Main *bmain, bGPdata *gpd = (bGPdata *)ob->data; for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { if ((gpl->parent != NULL) && (gpl->parent->data == arm)) { - if (STREQ(gpl->parsubstr, oldname)) + if (STREQ(gpl->parsubstr, oldname)) { BLI_strncpy(gpl->parsubstr, newname, MAXBONENAME); + } } } @@ -305,8 +312,9 @@ void ED_armature_bone_rename(Main *bmain, case eGpencilModifierType_Hook: { HookGpencilModifierData *hgp_md = (HookGpencilModifierData *)gp_md; if (hgp_md->object && (hgp_md->object->data == arm)) { - if (STREQ(hgp_md->subtarget, oldname)) + if (STREQ(hgp_md->subtarget, oldname)) { BLI_strncpy(hgp_md->subtarget, newname, MAXBONENAME); + } } break; } diff --git a/source/blender/editors/armature/armature_relations.c b/source/blender/editors/armature/armature_relations.c index 5d193c56c06..037703c50bf 100644 --- a/source/blender/editors/armature/armature_relations.c +++ b/source/blender/editors/armature/armature_relations.c @@ -92,8 +92,9 @@ static void joined_armature_fix_links_constraints( } } - if (cti->flush_constraint_targets) + if (cti->flush_constraint_targets) { cti->flush_constraint_targets(con, &targets, 0); + } } /* action constraint? (pose constraints only) */ @@ -248,10 +249,12 @@ 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_active || ob_active->type != OB_ARMATURE) + if (!ob_active || ob_active->type != OB_ARMATURE) { return OPERATOR_CANCELLED; - if (!arm || arm->edbo) + } + if (!arm || arm->edbo) { return OPERATOR_CANCELLED; + } CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) { if (ob_iter == ob_active) { @@ -696,8 +699,9 @@ static void bone_connect_to_new_parent(ListBase *edbo, EditBone *ebone; float offset[3]; - if ((selbone->parent) && (selbone->flag & BONE_CONNECTED)) + if ((selbone->parent) && (selbone->flag & BONE_CONNECTED)) { selbone->parent->flag &= ~(BONE_TIPSEL); + } /* make actbone the parent of selbone */ selbone->parent = actbone; @@ -767,8 +771,9 @@ static int armature_parent_set_exec(bContext *C, wmOperator *op) * then just use actbone. Useful when doing upper arm to spine. */ actmirb = ED_armature_ebone_get_mirrored(arm->edbo, actbone); - if (actmirb == NULL) + if (actmirb == NULL) { actmirb = actbone; + } } /* if there is only 1 selected bone, we assume that that is the active bone, @@ -781,8 +786,9 @@ static int armature_parent_set_exec(bContext *C, wmOperator *op) if (actbone->parent) { bone_connect_to_existing_parent(actbone); - if ((arm->flag & ARM_MIRROR_EDIT) && (actmirb->parent)) + if ((arm->flag & ARM_MIRROR_EDIT) && (actmirb->parent)) { bone_connect_to_existing_parent(actmirb); + } } } else { @@ -797,10 +803,12 @@ static int armature_parent_set_exec(bContext *C, wmOperator *op) /* parent selected bones to the active one */ CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) { if (ELEM(ebone, actbone, actmirb) == 0) { - if (ebone->flag & BONE_SELECTED) + if (ebone->flag & BONE_SELECTED) { bone_connect_to_new_parent(arm->edbo, ebone, actbone, val); - else + } + else { bone_connect_to_new_parent(arm->edbo, ebone, actmirb, val); + } } } CTX_DATA_END; @@ -824,8 +832,9 @@ static int armature_parent_set_invoke(bContext *C, CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) { if (ebone != actbone) { - if (ebone->parent != actbone) + if (ebone->parent != actbone) { allchildbones = 1; + } } } CTX_DATA_END; @@ -833,8 +842,9 @@ static int armature_parent_set_invoke(bContext *C, uiItemEnumO(layout, "ARMATURE_OT_parent_set", NULL, 0, "type", ARM_PAR_CONNECT); /* ob becomes parent, make the associated menus */ - if (allchildbones) + if (allchildbones) { uiItemEnumO(layout, "ARMATURE_OT_parent_set", NULL, 0, "type", ARM_PAR_OFFSET); + } UI_popup_menu_end(C, pup); @@ -873,8 +883,9 @@ static void editbone_clear_parent(EditBone *ebone, int mode) ebone->parent->flag &= ~(BONE_TIPSEL); } - if (mode == 1) + if (mode == 1) { ebone->parent = NULL; + } ebone->flag &= ~BONE_CONNECTED; } diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c index 0c493672d9e..95c10b79678 100644 --- a/source/blender/editors/armature/armature_select.c +++ b/source/blender/editors/armature/armature_select.c @@ -167,10 +167,12 @@ void *get_bone_from_selectbuffer(Base **bases, if (is_editmode == false) { base = ED_armature_base_and_bone_from_select_buffer(bases, bases_len, hitresult, &bone); if (bone != NULL) { - if (findunsel) + if (findunsel) { sel = (bone->flag & BONE_SELECTED); - else + } + else { sel = !(bone->flag & BONE_SELECTED); + } data = bone; } @@ -182,10 +184,12 @@ void *get_bone_from_selectbuffer(Base **bases, else { base = ED_armature_base_and_ebone_from_select_buffer( bases, bases_len, hitresult, &ebone); - if (findunsel) + if (findunsel) { sel = (ebone->flag & BONE_SELECTED); - else + } + else { sel = !(ebone->flag & BONE_SELECTED); + } data = ebone; } @@ -300,8 +304,9 @@ static int armature_select_linked_invoke(bContext *C, wmOperator *op, const wmEv Base *base = NULL; bone = get_nearest_bone(C, event->mval, true, &base); - if (!bone) + if (!bone) { return OPERATOR_CANCELLED; + } arm = base->object->data; @@ -316,10 +321,12 @@ static int armature_select_linked_invoke(bContext *C, wmOperator *op, const wmEv } } - if (curBone->flag & BONE_CONNECTED) + if (curBone->flag & BONE_CONNECTED) { next = curBone->parent; - else + } + else { next = NULL; + } } /* Select children */ @@ -343,8 +350,9 @@ static int armature_select_linked_invoke(bContext *C, wmOperator *op, const wmEv } } } - if (!curBone) + if (!curBone) { bone = NULL; + } } ED_armature_edit_sync_selection(arm->edbo); @@ -515,12 +523,15 @@ cache_end: if (hitresult & (BONESEL_ROOT | BONESEL_TIP)) { /* but also the unselected one */ if (findunsel) { - if ((hitresult & BONESEL_ROOT) && (ebone->flag & BONE_ROOTSEL) == 0) + if ((hitresult & BONESEL_ROOT) && (ebone->flag & BONE_ROOTSEL) == 0) { dep = 1; - else if ((hitresult & BONESEL_TIP) && (ebone->flag & BONE_TIPSEL) == 0) + } + else if ((hitresult & BONESEL_TIP) && (ebone->flag & BONE_TIPSEL) == 0) { dep = 1; - else + } + else { dep = 2; + } } else { dep = 1; @@ -529,10 +540,12 @@ cache_end: else { /* bone found */ if (findunsel) { - if ((ebone->flag & BONE_SELECTED) == 0) + if ((ebone->flag & BONE_SELECTED) == 0) { dep = 3; - else + } + else { dep = 4; + } } else { dep = 3; @@ -698,8 +711,9 @@ bool ED_armature_edit_select_pick( /* deselect this bone */ nearBone->flag &= ~(BONE_TIPSEL | BONE_SELECTED); /* only deselect parent tip if it is not selected */ - if (!(nearBone->parent->flag & BONE_SELECTED)) + if (!(nearBone->parent->flag & BONE_SELECTED)) { nearBone->parent->flag &= ~BONE_TIPSEL; + } } else if (toggle) { /* hold shift inverts this bone's selection */ @@ -707,8 +721,9 @@ bool ED_armature_edit_select_pick( /* deselect this bone */ nearBone->flag &= ~(BONE_TIPSEL | BONE_SELECTED); /* only deselect parent tip if it is not selected */ - if (!(nearBone->parent->flag & BONE_SELECTED)) + if (!(nearBone->parent->flag & BONE_SELECTED)) { nearBone->parent->flag &= ~BONE_TIPSEL; + } } else { /* select this bone */ @@ -731,24 +746,31 @@ bool ED_armature_edit_select_pick( } else if (toggle) { /* hold shift inverts this bone's selection */ - if (nearBone->flag & BONE_SELECTED) + if (nearBone->flag & BONE_SELECTED) { nearBone->flag &= ~(BONE_TIPSEL | BONE_ROOTSEL); - else + } + else { nearBone->flag |= (BONE_TIPSEL | BONE_ROOTSEL); + } } - else + else { nearBone->flag |= (BONE_TIPSEL | BONE_ROOTSEL); + } } } else { - if (extend) + if (extend) { nearBone->flag |= selmask; - else if (deselect) + } + else if (deselect) { nearBone->flag &= ~selmask; - else if (toggle && (nearBone->flag & selmask)) + } + else if (toggle && (nearBone->flag & selmask)) { nearBone->flag &= ~selmask; - else + } + else { nearBone->flag |= selmask; + } } ED_armature_edit_sync_selection(arm->edbo); @@ -1373,8 +1395,9 @@ static void select_similar_suffix(bContext *C) BLI_string_split_suffix(ebone_act->name, body_tmp, suffix_act, sizeof(ebone_act->name)); - if (suffix_act[0] == '\0') + if (suffix_act[0] == '\0') { return; + } uint objects_len = 0; Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( @@ -1429,11 +1452,13 @@ static void select_similar_data_pchan(bContext *C, const size_t bytes_size, cons static void is_ancestor(EditBone *bone, EditBone *ancestor) { - if (bone->temp.ebone == ancestor || bone->temp.ebone == NULL) + if (bone->temp.ebone == ancestor || bone->temp.ebone == NULL) { return; + } - if (bone->temp.ebone->temp.ebone != NULL && bone->temp.ebone->temp.ebone != ancestor) + if (bone->temp.ebone->temp.ebone != NULL && bone->temp.ebone->temp.ebone != ancestor) { is_ancestor(bone->temp.ebone, ancestor); + } bone->temp.ebone = bone->temp.ebone->temp.ebone; } @@ -1451,8 +1476,9 @@ static void select_similar_children(bContext *C) for (EditBone *ebone_iter = arm->edbo->first; ebone_iter; ebone_iter = ebone_iter->next) { is_ancestor(ebone_iter, ebone_act); - if (ebone_iter->temp.ebone == ebone_act && EBONE_SELECTABLE(arm, ebone_iter)) + if (ebone_iter->temp.ebone == ebone_act && EBONE_SELECTABLE(arm, ebone_iter)) { ED_armature_ebone_select_set(ebone_iter, true); + } } WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit); @@ -1757,8 +1783,9 @@ static bool armature_shortest_path_select( { do { - if (!use_parent && (ebone_child == ebone_parent)) + if (!use_parent && (ebone_child == ebone_parent)) { break; + } if (is_test) { if (!EBONE_SELECTABLE(arm, ebone_child)) { @@ -1769,8 +1796,9 @@ static bool armature_shortest_path_select( ED_armature_ebone_selectflag_set(ebone_child, (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL)); } - if (ebone_child == ebone_parent) + if (ebone_child == ebone_parent) { break; + } ebone_child = ebone_child->parent; } while (true); diff --git a/source/blender/editors/armature/armature_skinning.c b/source/blender/editors/armature/armature_skinning.c index c267485d553..08de699a70b 100644 --- a/source/blender/editors/armature/armature_skinning.c +++ b/source/blender/editors/armature/armature_skinning.c @@ -93,10 +93,12 @@ static int bone_skinnable_cb(Object *UNUSED(ob), Bone *bone, void *datap) if (!(data->is_weight_paint) || !(bone->flag & BONE_HIDDEN_P)) { if (!(bone->flag & BONE_NO_DEFORM)) { if (data->heat && data->armob->pose && - BKE_pose_channel_find_name(data->armob->pose, bone->name)) + BKE_pose_channel_find_name(data->armob->pose, bone->name)) { segments = bone->segments; - else + } + else { segments = 1; + } if (data->list != NULL) { hbone = (Bone ***)&data->list; @@ -165,10 +167,12 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap) if (!data->is_weight_paint || !(bone->flag & BONE_HIDDEN_P)) { if (!(bone->flag & BONE_NO_DEFORM)) { if (data->heat && data->armob->pose && - BKE_pose_channel_find_name(data->armob->pose, bone->name)) + BKE_pose_channel_find_name(data->armob->pose, bone->name)) { segments = bone->segments; - else + } + else { segments = 1; + } if (!data->is_weight_paint || ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED))) { if (!(defgroup = defgroup_find_name(ob, bone->name))) { @@ -231,8 +235,9 @@ static void envelope_bone_weighting(Object *ob, /* for each skinnable bone */ for (j = 0; j < numbones; ++j) { - if (!selected[j]) + if (!selected[j]) { continue; + } bone = bonelist[j]; dgroup = dgrouplist[j]; @@ -246,17 +251,21 @@ static void envelope_bone_weighting(Object *ob, bone->dist * scale); /* add the vert to the deform group if (weight != 0.0) */ - if (distance != 0.0f) + if (distance != 0.0f) { ED_vgroup_vert_add(ob, dgroup, i, distance, WEIGHT_REPLACE); - else + } + else { ED_vgroup_vert_remove(ob, dgroup, i); + } /* do same for mirror */ if (dgroupflip && dgroupflip[j] && iflip != -1) { - if (distance != 0.0f) + if (distance != 0.0f) { ED_vgroup_vert_add(ob, dgroupflip[j], iflip, distance, WEIGHT_REPLACE); - else + } + else { ED_vgroup_vert_remove(ob, dgroupflip[j], iflip); + } } } } @@ -308,11 +317,13 @@ static void add_verts_to_dgroups(ReportList *reports, /* count the number of skinnable bones */ numbones = bone_looper(ob, arm->bonebase.first, &looper_data, bone_skinnable_cb); - if (numbones == 0) + if (numbones == 0) { return; + } - if (BKE_object_defgroup_data_create(ob->data) == NULL) + if (BKE_object_defgroup_data_create(ob->data) == NULL) { return; + } /* create an array of pointer to bones that are skinnable * and fill it with all of the skinnable bones */ @@ -377,11 +388,13 @@ static void add_verts_to_dgroups(ReportList *reports, /* set selected */ if (wpmode) { - if ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED)) + if ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED)) { selected[j] = 1; + } } - else + else { selected[j] = 1; + } /* find flipped group */ if (dgroup && mirror) { @@ -415,8 +428,9 @@ static void add_verts_to_dgroups(ReportList *reports, /* transform verts to global space */ for (i = 0; i < mesh->totvert; i++) { - if (!vertsfilled) + if (!vertsfilled) { copy_v3_v3(verts[i], mesh->mvert[i].co); + } mul_m4_v3(ob->obmat, verts[i]); } diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c index ebb0b6b4c22..b4e4396ce89 100644 --- a/source/blender/editors/armature/armature_utils.c +++ b/source/blender/editors/armature/armature_utils.c @@ -56,16 +56,20 @@ void ED_armature_edit_sync_selection(ListBase *edbo) /* if bone is not selectable, we shouldn't alter this setting... */ if ((ebo->flag & BONE_UNSELECTABLE) == 0) { if ((ebo->flag & BONE_CONNECTED) && (ebo->parent)) { - if (ebo->parent->flag & BONE_TIPSEL) + if (ebo->parent->flag & BONE_TIPSEL) { ebo->flag |= BONE_ROOTSEL; - else + } + else { ebo->flag &= ~BONE_ROOTSEL; + } } - if ((ebo->flag & BONE_TIPSEL) && (ebo->flag & BONE_ROOTSEL)) + if ((ebo->flag & BONE_TIPSEL) && (ebo->flag & BONE_ROOTSEL)) { ebo->flag |= BONE_SELECTED; - else + } + else { ebo->flag &= ~BONE_SELECTED; + } } } } @@ -75,8 +79,9 @@ void ED_armature_edit_validate_active(struct bArmature *arm) EditBone *ebone = arm->act_edbone; if (ebone) { - if (ebone->flag & BONE_HIDDEN_A) + if (ebone->flag & BONE_HIDDEN_A) { arm->act_edbone = NULL; + } } } @@ -116,8 +121,9 @@ int bone_looper(Object *ob, Bone *bone, void *data, int (*bone_func)(Object *, B void bone_free(bArmature *arm, EditBone *bone) { - if (arm->act_edbone == bone) + if (arm->act_edbone == bone) { arm->act_edbone = NULL; + } if (bone->prop) { IDP_FreeProperty(bone->prop); @@ -165,8 +171,9 @@ void ED_armature_ebone_remove(bArmature *arm, EditBone *exBone) bool ED_armature_ebone_is_child_recursive(EditBone *ebone_parent, EditBone *ebone_child) { for (ebone_child = ebone_child->parent; ebone_child; ebone_child = ebone_child->parent) { - if (ebone_child == ebone_parent) + if (ebone_child == ebone_parent) { return true; + } } return false; } @@ -274,8 +281,9 @@ EditBone *ED_armature_ebone_get_mirrored(const ListBase *edbo, EditBone *ebo) { char name_flip[MAXBONENAME]; - if (ebo == NULL) + if (ebo == NULL) { return NULL; + } BLI_string_flip_side_name(name_flip, ebo->name, false, sizeof(name_flip)); @@ -301,8 +309,9 @@ void armature_select_mirrored_ex(bArmature *arm, const int flag) if (arm->layer & curBone->layer) { if (curBone->flag & flag) { ebone_mirr = ED_armature_ebone_get_mirrored(arm->edbo, curBone); - if (ebone_mirr) + if (ebone_mirr) { ebone_mirr->flag |= (curBone->flag & flag); + } } } } @@ -499,20 +508,23 @@ static EditBone *make_boneList_rec(ListBase *edbo, eBone->bbone_prev_type = curBone->bbone_prev_type; eBone->bbone_next_type = curBone->bbone_next_type; - if (curBone->prop) + if (curBone->prop) { eBone->prop = IDP_CopyProperty(curBone->prop); + } BLI_addtail(edbo, eBone); /* Add children if necessary */ if (curBone->childbase.first) { eBoneTest = make_boneList_rec(edbo, &curBone->childbase, eBone, actBone); - if (eBoneTest) + if (eBoneTest) { eBoneAct = eBoneTest; + } } - if (curBone == actBone) + if (curBone == actBone) { eBoneAct = eBone; + } } return eBoneAct; @@ -648,11 +660,13 @@ void ED_armature_from_edit(Main *bmain, bArmature *arm) /* Find any bones that refer to this bone */ for (fBone = arm->edbo->first; fBone; fBone = fBone->next) { - if (fBone->parent == eBone) + if (fBone->parent == eBone) { fBone->parent = eBone->parent; + } } - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Warning: removed zero sized bone: %s\n", eBone->name); + } bone_free(arm, eBone); } } @@ -704,8 +718,9 @@ void ED_armature_from_edit(Main *bmain, bArmature *arm) newBone->bbone_prev_type = eBone->bbone_prev_type; newBone->bbone_next_type = eBone->bbone_next_type; - if (eBone->prop) + if (eBone->prop) { newBone->prop = IDP_CopyProperty(eBone->prop); + } } /* Fix parenting in a separate pass to ensure ebone->bone connections are valid at this point. diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index a9f8925febc..b194650060a 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -122,10 +122,12 @@ static void laplacian_increase_edge_count(EdgeHash *edgehash, int v1, int v2) { void **p; - if (BLI_edgehash_ensure_p(edgehash, v1, v2, &p)) + if (BLI_edgehash_ensure_p(edgehash, v1, v2, &p)) { *p = (void *)((intptr_t)*p + (intptr_t)1); - else + } + else { *p = (void *)((intptr_t)1); + } } static int laplacian_edge_count(EdgeHash *edgehash, int v1, int v2) @@ -147,12 +149,15 @@ static void laplacian_triangle_area(LaplacianSystem *sys, int i1, int i2, int i3 t2 = cotangent_tri_weight_v3(v2, v3, v1); t3 = cotangent_tri_weight_v3(v3, v1, v2); - if (angle_v3v3v3(v2, v1, v3) > DEG2RADF(90.0f)) + if (angle_v3v3v3(v2, v1, v3) > DEG2RADF(90.0f)) { obtuse = 1; - else if (angle_v3v3v3(v1, v2, v3) > DEG2RADF(90.0f)) + } + else if (angle_v3v3v3(v1, v2, v3) > DEG2RADF(90.0f)) { obtuse = 2; - else if (angle_v3v3v3(v1, v3, v2) > DEG2RADF(90.0f)) + } + else if (angle_v3v3v3(v1, v3, v2) > DEG2RADF(90.0f)) { obtuse = 3; + } if (obtuse > 0) { area = area_tri_v3(v1, v2, v3); @@ -228,10 +233,12 @@ static LaplacianSystem *laplacian_system_construct_begin(int totvert, int totfac sys->storeweights = 0; /* create linear solver */ - if (lsq) + if (lsq) { sys->context = EIG_linear_least_squares_solver_new(0, totvert, 1); - else + } + else { sys->context = EIG_linear_solver_new(0, totvert, 1); + } return sys; } @@ -267,28 +274,35 @@ static void laplacian_system_construct_end(LaplacianSystem *sys) laplacian_increase_edge_count(sys->edgehash, (*face)[2], (*face)[0]); } - if (sys->areaweights) - for (a = 0, face = sys->faces; a < sys->totface; a++, face++) + if (sys->areaweights) { + for (a = 0, face = sys->faces; a < sys->totface; a++, face++) { laplacian_triangle_area(sys, (*face)[0], (*face)[1], (*face)[2]); + } + } for (a = 0; a < totvert; a++) { if (sys->areaweights) { - if (sys->varea[a] != 0.0f) + if (sys->varea[a] != 0.0f) { sys->varea[a] = 0.5f / sys->varea[a]; + } } - else + else { sys->varea[a] = 1.0f; + } /* for heat weighting */ - if (sys->heat.H) + if (sys->heat.H) { EIG_linear_solver_matrix_add(sys->context, a, a, sys->heat.H[a]); + } } - if (sys->storeweights) + if (sys->storeweights) { sys->fweights = MEM_callocN(sizeof(float) * 3 * totface, "LaplacianFWeight"); + } - for (a = 0, face = sys->faces; a < totface; a++, face++) + for (a = 0, face = sys->faces; a < totface; a++, face++) { laplacian_triangle_weights(sys, a, (*face)[0], (*face)[1], (*face)[2]); + } MEM_freeN(sys->faces); sys->faces = NULL; @@ -304,16 +318,21 @@ static void laplacian_system_construct_end(LaplacianSystem *sys) static void laplacian_system_delete(LaplacianSystem *sys) { - if (sys->verts) + if (sys->verts) { MEM_freeN(sys->verts); - if (sys->varea) + } + if (sys->varea) { MEM_freeN(sys->varea); - if (sys->vpinned) + } + if (sys->vpinned) { MEM_freeN(sys->vpinned); - if (sys->faces) + } + if (sys->faces) { MEM_freeN(sys->faces); - if (sys->fweights) + } + if (sys->fweights) { MEM_freeN(sys->fweights); + } EIG_linear_solver_delete(sys->context); MEM_freeN(sys); @@ -450,8 +469,9 @@ static int heat_ray_source_visible(LaplacianSystem *sys, int vertex, int source) int visible; lt = sys->heat.vltree[vertex]; - if (lt == NULL) + if (lt == NULL) { return 1; + } data.sys = sys; copy_v3_v3(data.start, sys->heat.verts[vertex]); @@ -496,9 +516,11 @@ static int heat_source_closest(LaplacianSystem *sys, int vertex, int source) dist = heat_source_distance(sys, vertex, source); - if (dist <= sys->heat.mindist[vertex] * (1.0f + DISTANCE_EPSILON)) - if (heat_ray_source_visible(sys, vertex, source)) + if (dist <= sys->heat.mindist[vertex] * (1.0f + DISTANCE_EPSILON)) { + if (heat_ray_source_visible(sys, vertex, source)) { return 1; + } + } return 0; } @@ -514,16 +536,19 @@ static void heat_set_H(LaplacianSystem *sys, int vertex) for (j = 0; j < sys->heat.numsource; j++) { dist = heat_source_distance(sys, vertex, j); - if (dist < mindist) + if (dist < mindist) { mindist = dist; + } } sys->heat.mindist[vertex] = mindist; /* count number of sources with approximately this minimum distance */ - for (j = 0; j < sys->heat.numsource; j++) - if (heat_source_closest(sys, vertex, j)) + for (j = 0; j < sys->heat.numsource; j++) { + if (heat_source_closest(sys, vertex, j)) { numclosest++; + } + } sys->heat.p[vertex] = (numclosest > 0) ? 1.0f / numclosest : 0.0f; @@ -532,8 +557,9 @@ static void heat_set_H(LaplacianSystem *sys, int vertex) mindist = max_ff(mindist, 1e-4f); h = numclosest * C_WEIGHT / (mindist * mindist); } - else + else { h = 0.0f; + } sys->heat.H[vertex] = h; } @@ -557,8 +583,9 @@ static void heat_calc_vnormals(LaplacianSystem *sys) add_v3_v3(sys->heat.vnors[v3], fnor); } - for (a = 0; a < sys->totvert; a++) + for (a = 0; a < sys->totvert; a++) { normalize_v3(sys->heat.vnors[a]); + } } static void heat_laplacian_create(LaplacianSystem *sys) @@ -575,8 +602,9 @@ static void heat_laplacian_create(LaplacianSystem *sys) sys->heat.p = MEM_callocN(sizeof(float) * totvert, "HeatP"); /* add verts and faces to laplacian */ - for (a = 0; a < totvert; a++) + for (a = 0; a < totvert; a++) { laplacian_add_vertex(sys, sys->heat.verts[a], 0); + } for (a = 0, lt = mlooptri; a < tottri; a++, lt++) { int vtri[3]; @@ -589,8 +617,9 @@ static void heat_laplacian_create(LaplacianSystem *sys) /* for distance computation in set_H */ heat_calc_vnormals(sys); - for (a = 0; a < totvert; a++) + for (a = 0; a < totvert; a++) { heat_set_H(sys, a); + } } static void heat_system_free(LaplacianSystem *sys) @@ -616,8 +645,9 @@ static float heat_limit_weight(float weight) t = (weight - WEIGHT_LIMIT_END) / (WEIGHT_LIMIT_START - WEIGHT_LIMIT_END); return t * WEIGHT_LIMIT_START; } - else + else { return weight; + } } void heat_bone_weighting(Object *ob, @@ -695,14 +725,16 @@ void heat_bone_weighting(Object *ob, if (dgroupflip) { vertsflipped = MEM_callocN(sizeof(int) * me->totvert, "vertsflipped"); - for (a = 0; a < me->totvert; a++) + for (a = 0; a < me->totvert; a++) { vertsflipped[a] = mesh_get_x_mirror_vert(ob, NULL, a, use_topology); + } } /* compute weights per bone */ for (j = 0; j < numsource; j++) { - if (!selected[j]) + if (!selected[j]) { continue; + } firstsegment = (j == 0 || dgrouplist[j - 1] != dgrouplist[j]); lastsegment = (j == numsource - 1 || dgrouplist[j] != dgrouplist[j + 1]); @@ -711,55 +743,66 @@ void heat_bone_weighting(Object *ob, /* clear weights */ if (bbone && firstsegment) { for (a = 0; a < me->totvert; a++) { - if (mask && !mask[a]) + if (mask && !mask[a]) { continue; + } ED_vgroup_vert_remove(ob, dgrouplist[j], a); - if (vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) + if (vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) { ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]); + } } } /* fill right hand side */ laplacian_begin_solve(sys, -1); - for (a = 0; a < me->totvert; a++) - if (heat_source_closest(sys, a, j)) + for (a = 0; a < me->totvert; a++) { + if (heat_source_closest(sys, a, j)) { laplacian_add_right_hand_side(sys, a, sys->heat.H[a] * sys->heat.p[a]); + } + } /* solve */ if (laplacian_system_solve(sys)) { /* load solution into vertex groups */ for (a = 0; a < me->totvert; a++) { - if (mask && !mask[a]) + if (mask && !mask[a]) { continue; + } solution = laplacian_system_get_solution(sys, a); if (bbone) { - if (solution > 0.0f) + if (solution > 0.0f) { ED_vgroup_vert_add(ob, dgrouplist[j], a, solution, WEIGHT_ADD); + } } else { weight = heat_limit_weight(solution); - if (weight > 0.0f) + if (weight > 0.0f) { ED_vgroup_vert_add(ob, dgrouplist[j], a, weight, WEIGHT_REPLACE); - else + } + else { ED_vgroup_vert_remove(ob, dgrouplist[j], a); + } } /* do same for mirror */ if (vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) { if (bbone) { - if (solution > 0.0f) + if (solution > 0.0f) { ED_vgroup_vert_add(ob, dgroupflip[j], vertsflipped[a], solution, WEIGHT_ADD); + } } else { weight = heat_limit_weight(solution); - if (weight > 0.0f) + if (weight > 0.0f) { ED_vgroup_vert_add(ob, dgroupflip[j], vertsflipped[a], weight, WEIGHT_REPLACE); - else + } + else { ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]); + } } } } @@ -772,29 +815,34 @@ void heat_bone_weighting(Object *ob, /* remove too small vertex weights */ if (bbone && lastsegment) { for (a = 0; a < me->totvert; a++) { - if (mask && !mask[a]) + if (mask && !mask[a]) { continue; + } weight = ED_vgroup_vert_weight(ob, dgrouplist[j], a); weight = heat_limit_weight(weight); - if (weight <= 0.0f) + if (weight <= 0.0f) { ED_vgroup_vert_remove(ob, dgrouplist[j], a); + } if (vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) { weight = ED_vgroup_vert_weight(ob, dgroupflip[j], vertsflipped[a]); weight = heat_limit_weight(weight); - if (weight <= 0.0f) + if (weight <= 0.0f) { ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]); + } } } } } /* free */ - if (vertsflipped) + if (vertsflipped) { MEM_freeN(vertsflipped); - if (mask) + } + if (mask) { MEM_freeN(mask); + } heat_system_free(sys); @@ -964,8 +1012,9 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb, float end[3], vec_normal[3]; /* happens binding when a cage has no faces */ - if (UNLIKELY(mdb->bvhtree == NULL)) + if (UNLIKELY(mdb->bvhtree == NULL)) { return NULL; + } /* setup isec */ memset(&isect_mdef, 0, sizeof(isect_mdef)); @@ -1037,8 +1086,9 @@ static int meshdeform_inside_cage(MeshDeformBind *mdb, float *co) normalize_v3(dir); isect = meshdeform_ray_tree_intersect(mdb, start, outside); - if (isect && !isect->facing) + if (isect && !isect->facing) { return 1; + } } return 0; @@ -1054,12 +1104,15 @@ BLI_INLINE int meshdeform_index(MeshDeformBind *mdb, int x, int y, int z, int n) y += MESHDEFORM_OFFSET[n][1]; z += MESHDEFORM_OFFSET[n][2]; - if (x < 0 || x >= mdb->size) + if (x < 0 || x >= mdb->size) { return -1; - if (y < 0 || y >= mdb->size) + } + if (y < 0 || y >= mdb->size) { return -1; - if (z < 0 || z >= mdb->size) + } + if (z < 0 || z >= mdb->size) { return -1; + } return x + y * size + z * size * size; } @@ -1087,8 +1140,9 @@ static void meshdeform_add_intersections(MeshDeformBind *mdb, int x, int y, int /* check each outgoing edge for intersection */ for (i = 1; i <= 6; i++) { - if (meshdeform_index(mdb, x, y, z, i) == -1) + if (meshdeform_index(mdb, x, y, z, i) == -1) { continue; + } meshdeform_cell_center(mdb, x, y, z, i, ncenter); @@ -1134,9 +1188,11 @@ static void meshdeform_bind_floodfill(MeshDeformBind *mdb) } /* other cells are interior */ - for (a = 0; a < size * size * size; a++) - if (tag[a] == MESHDEFORM_TAG_UNTYPED) + for (a = 0; a < size * size * size; a++) { + if (tag[a] == MESHDEFORM_TAG_UNTYPED) { tag[a] = MESHDEFORM_TAG_INTERIOR; + } + } #if 0 { @@ -1230,8 +1286,9 @@ static float meshdeform_interp_w(MeshDeformBind *mdb, totweight += weight; } - if (totweight > 0.0f) + if (totweight > 0.0f) { result /= totweight; + } return result; } @@ -1241,12 +1298,15 @@ static void meshdeform_check_semibound(MeshDeformBind *mdb, int x, int y, int z) int i, a; a = meshdeform_index(mdb, x, y, z, 0); - if (mdb->tag[a] != MESHDEFORM_TAG_EXTERIOR) + if (mdb->tag[a] != MESHDEFORM_TAG_EXTERIOR) { return; + } - for (i = 1; i <= 6; i++) - if (mdb->boundisect[a][i - 1]) + for (i = 1; i <= 6; i++) { + if (mdb->boundisect[a][i - 1]) { mdb->semibound[a] = 1; + } + } } static float meshdeform_boundary_total_weight(MeshDeformBind *mdb, int x, int y, int z) @@ -1258,15 +1318,19 @@ static float meshdeform_boundary_total_weight(MeshDeformBind *mdb, int x, int y, /* count weight for neighbor cells */ for (i = 1; i <= 6; i++) { - if (meshdeform_index(mdb, x, y, z, i) == -1) + if (meshdeform_index(mdb, x, y, z, i) == -1) { continue; + } - if (mdb->boundisect[a][i - 1]) + if (mdb->boundisect[a][i - 1]) { weight = 1.0f / mdb->boundisect[a][i - 1]->len; - else if (!mdb->semibound[a]) + } + else if (!mdb->semibound[a]) { weight = 1.0f / mdb->width[0]; - else + } + else { weight = 0.0f; + } totweight += weight; } @@ -1282,16 +1346,18 @@ static void meshdeform_matrix_add_cell( int i, a, acenter; acenter = meshdeform_index(mdb, x, y, z, 0); - if (mdb->tag[acenter] == MESHDEFORM_TAG_EXTERIOR) + if (mdb->tag[acenter] == MESHDEFORM_TAG_EXTERIOR) { return; + } EIG_linear_solver_matrix_add(context, mdb->varidx[acenter], mdb->varidx[acenter], 1.0f); totweight = meshdeform_boundary_total_weight(mdb, x, y, z); for (i = 1; i <= 6; i++) { a = meshdeform_index(mdb, x, y, z, i); - if (a == -1 || mdb->tag[a] == MESHDEFORM_TAG_EXTERIOR) + if (a == -1 || mdb->tag[a] == MESHDEFORM_TAG_EXTERIOR) { continue; + } isect = mdb->boundisect[acenter][i - 1]; if (!isect) { @@ -1309,14 +1375,16 @@ static void meshdeform_matrix_add_rhs( int i, a, acenter; acenter = meshdeform_index(mdb, x, y, z, 0); - if (mdb->tag[acenter] == MESHDEFORM_TAG_EXTERIOR) + if (mdb->tag[acenter] == MESHDEFORM_TAG_EXTERIOR) { return; + } totweight = meshdeform_boundary_total_weight(mdb, x, y, z); for (i = 1; i <= 6; i++) { a = meshdeform_index(mdb, x, y, z, i); - if (a == -1) + if (a == -1) { continue; + } isect = mdb->boundisect[acenter][i - 1]; @@ -1336,8 +1404,9 @@ static void meshdeform_matrix_add_semibound_phi( int i, a; a = meshdeform_index(mdb, x, y, z, 0); - if (!mdb->semibound[a]) + if (!mdb->semibound[a]) { return; + } mdb->phi[a] = 0.0f; @@ -1360,8 +1429,9 @@ static void meshdeform_matrix_add_exterior_phi( int i, a, acenter; acenter = meshdeform_index(mdb, x, y, z, 0); - if (mdb->tag[acenter] != MESHDEFORM_TAG_EXTERIOR || mdb->semibound[acenter]) + if (mdb->tag[acenter] != MESHDEFORM_TAG_EXTERIOR || mdb->semibound[acenter]) { return; + } phi = 0.0f; totweight = 0.0f; @@ -1374,8 +1444,9 @@ static void meshdeform_matrix_add_exterior_phi( } } - if (totweight != 0.0f) + if (totweight != 0.0f) { mdb->phi[acenter] = phi / totweight; + } } static void meshdeform_matrix_solve(MeshDeformModifierData *mmd, MeshDeformBind *mdb) @@ -1387,8 +1458,9 @@ static void meshdeform_matrix_solve(MeshDeformModifierData *mmd, MeshDeformBind /* setup variable indices */ mdb->varidx = MEM_callocN(sizeof(int) * mdb->size3, "MeshDeformDSvaridx"); - for (a = 0, totvar = 0; a < mdb->size3; a++) + for (a = 0, totvar = 0; a < mdb->size3; a++) { mdb->varidx[a] = (mdb->tag[a] == MESHDEFORM_TAG_EXTERIOR) ? -1 : totvar++; + } if (totvar == 0) { MEM_freeN(mdb->varidx); @@ -1401,33 +1473,46 @@ static void meshdeform_matrix_solve(MeshDeformModifierData *mmd, MeshDeformBind context = EIG_linear_solver_new(totvar, totvar, 1); /* build matrix */ - for (z = 0; z < mdb->size; z++) - for (y = 0; y < mdb->size; y++) - for (x = 0; x < mdb->size; x++) + for (z = 0; z < mdb->size; z++) { + for (y = 0; y < mdb->size; y++) { + for (x = 0; x < mdb->size; x++) { meshdeform_matrix_add_cell(mdb, context, x, y, z); + } + } + } /* solve for each cage vert */ for (a = 0; a < mdb->totcagevert; a++) { /* fill in right hand side and solve */ - for (z = 0; z < mdb->size; z++) - for (y = 0; y < mdb->size; y++) - for (x = 0; x < mdb->size; x++) + for (z = 0; z < mdb->size; z++) { + for (y = 0; y < mdb->size; y++) { + for (x = 0; x < mdb->size; x++) { meshdeform_matrix_add_rhs(mdb, context, x, y, z, a); + } + } + } if (EIG_linear_solver_solve(context)) { - for (z = 0; z < mdb->size; z++) - for (y = 0; y < mdb->size; y++) - for (x = 0; x < mdb->size; x++) + for (z = 0; z < mdb->size; z++) { + for (y = 0; y < mdb->size; y++) { + for (x = 0; x < mdb->size; x++) { meshdeform_matrix_add_semibound_phi(mdb, x, y, z, a); + } + } + } - for (z = 0; z < mdb->size; z++) - for (y = 0; y < mdb->size; y++) - for (x = 0; x < mdb->size; x++) + for (z = 0; z < mdb->size; z++) { + for (y = 0; y < mdb->size; y++) { + for (x = 0; x < mdb->size; x++) { meshdeform_matrix_add_exterior_phi(mdb, x, y, z, a); + } + } + } for (b = 0; b < mdb->size3; b++) { - if (mdb->tag[b] != MESHDEFORM_TAG_EXTERIOR) + if (mdb->tag[b] != MESHDEFORM_TAG_EXTERIOR) { mdb->phi[b] = EIG_linear_solver_variable_get(context, 0, mdb->varidx[b]); + } mdb->totalphi[b] += mdb->phi[b]; } @@ -1499,8 +1584,9 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin /* compute bounding box of the cage mesh */ INIT_MINMAX(mdb->min, mdb->max); - for (a = 0; a < mdb->totcagevert; a++) + for (a = 0; a < mdb->totcagevert; a++) { minmax_v3v3_v3(mdb->min, mdb->max, mdb->cagecos[a]); + } /* allocate memory */ mdb->size = (2 << (mmd->gridsize - 1)) + 2; @@ -1513,10 +1599,12 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin mdb->bvhtree = BKE_bvhtree_from_mesh_get(&mdb->bvhdata, mdb->cagemesh, BVHTREE_FROM_LOOPTRI, 4); mdb->inside = MEM_callocN(sizeof(int) * mdb->totvert, "MDefInside"); - if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) + if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) { mdb->dyngrid = MEM_callocN(sizeof(MDefBindInfluence *) * mdb->size3, "MDefDynGrid"); - else + } + else { mdb->weights = MEM_callocN(sizeof(float) * mdb->totvert * mdb->totcagevert, "MDefWeights"); + } mdb->memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "harmonic coords arena"); BLI_memarena_use_calloc(mdb->memarena); @@ -1534,9 +1622,11 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin /* make bounding box equal size in all directions, add padding, and compute * width of the cells */ maxwidth = -1.0f; - for (a = 0; a < 3; a++) - if (mdb->max[a] - mdb->min[a] > maxwidth) + for (a = 0; a < 3; a++) { + if (mdb->max[a] - mdb->min[a] > maxwidth) { maxwidth = mdb->max[a] - mdb->min[a]; + } + } for (a = 0; a < 3; a++) { center[a] = (mdb->min[a] + mdb->max[a]) * 0.5f; @@ -1557,8 +1647,9 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin for (a = 0; a < mdb->totvert; a++) { copy_v3_v3(vec, mdb->vertexcos[a]); mdb->inside[a] = meshdeform_inside_cage(mdb, vec); - if (mdb->inside[a]) + if (mdb->inside[a]) { totinside++; + } } /* free temporary MDefBoundIsects */ @@ -1566,22 +1657,29 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin mdb->memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "harmonic coords arena"); /* start with all cells untyped */ - for (a = 0; a < mdb->size3; a++) + for (a = 0; a < mdb->size3; a++) { mdb->tag[a] = MESHDEFORM_TAG_UNTYPED; + } /* detect intersections and tag boundary cells */ - for (z = 0; z < mdb->size; z++) - for (y = 0; y < mdb->size; y++) - for (x = 0; x < mdb->size; x++) + for (z = 0; z < mdb->size; z++) { + for (y = 0; y < mdb->size; y++) { + for (x = 0; x < mdb->size; x++) { meshdeform_add_intersections(mdb, x, y, z); + } + } + } /* compute exterior and interior tags */ meshdeform_bind_floodfill(mdb); - for (z = 0; z < mdb->size; z++) - for (y = 0; y < mdb->size; y++) - for (x = 0; x < mdb->size; x++) + for (z = 0; z < mdb->size; z++) { + for (y = 0; y < mdb->size; y++) { + for (x = 0; x < mdb->size; x++) { meshdeform_check_semibound(mdb, x, y, z); + } + } + } /* solve */ meshdeform_matrix_solve(mmd, mdb); @@ -1589,9 +1687,11 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin /* assign results */ if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) { mmd->totinfluence = 0; - for (a = 0; a < mdb->size3; a++) - for (inf = mdb->dyngrid[a]; inf; inf = inf->next) + for (a = 0; a < mdb->size3; a++) { + for (inf = mdb->dyngrid[a]; inf; inf = inf->next) { mmd->totinfluence++; + } + } /* convert MDefBindInfluences to smaller MDefInfluences */ mmd->dyngrid = MEM_callocN(sizeof(MDefCell) * mdb->size3, "MDefDynGrid"); @@ -1612,8 +1712,9 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin if (totweight > 0.0f) { mdinf = mmd->dyninfluences + cell->offset; - for (b = 0; b < cell->totinfluence; b++, mdinf++) + for (b = 0; b < cell->totinfluence; b++, mdinf++) { mdinf->weight /= totweight; + } } offset += cell->totinfluence; @@ -1666,10 +1767,12 @@ void ED_mesh_deform_bind_callback(MeshDeformModifierData *mmd, copy_m4_m4(mdb.cagemat, cagemat); mvert = mdb.cagemesh->mvert; - for (a = 0; a < mdb.totcagevert; a++) + for (a = 0; a < mdb.totcagevert; a++) { copy_v3_v3(mdb.cagecos[a], mvert[a].co); - for (a = 0; a < mdb.totvert; a++) + } + for (a = 0; a < mdb.totvert; a++) { mul_v3_m4v3(mdb.vertexcos[a], mdb.cagemat, vertexcos + a * 3); + } /* solve */ harmonic_coordinates_bind(mmd_orig, &mdb); @@ -1681,8 +1784,9 @@ void ED_mesh_deform_bind_callback(MeshDeformModifierData *mmd, copy_m4_m4(mmd_orig->bindmat, mmd_orig->object->obmat); /* transform bindcagecos to world space */ - for (a = 0; a < mdb.totcagevert; a++) + for (a = 0; a < mdb.totcagevert; a++) { mul_m4_v3(mmd_orig->object->obmat, mmd_orig->bindcagecos + a * 3); + } /* free */ MEM_freeN(mdb.vertexcos); diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c index 0a886074f42..cf64210ebdb 100644 --- a/source/blender/editors/armature/pose_edit.c +++ b/source/blender/editors/armature/pose_edit.c @@ -263,8 +263,9 @@ static int pose_calculate_paths_invoke(bContext *C, wmOperator *op, const wmEven { Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } /* set default settings from existing/stored settings */ { @@ -291,8 +292,9 @@ static int pose_calculate_paths_exec(bContext *C, wmOperator *op) Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); Scene *scene = CTX_data_scene(C); - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } /* grab baking settings from operator settings */ { @@ -391,8 +393,9 @@ static int pose_update_paths_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); Scene *scene = CTX_data_scene(C); - if (ELEM(NULL, ob, scene)) + if (ELEM(NULL, ob, scene)) { return OPERATOR_CANCELLED; + } /* calculate the bones that now have motionpaths... */ /* TODO: only make for the selected bones? */ @@ -427,8 +430,9 @@ static void ED_pose_clear_paths(Object *ob, bool only_selected) bPoseChannel *pchan; bool skipped = false; - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return; + } /* free the motionpath blocks for all bones - This is easier for users to quickly clear all */ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { @@ -444,8 +448,9 @@ static void ED_pose_clear_paths(Object *ob, bool only_selected) } /* if nothing was skipped, there should be no paths left! */ - if (skipped == false) + if (skipped == false) { ob->pose->avs.path_bakeflag &= ~MOTIONPATH_BAKE_HAS_PATHS; + } /* tag armature object for copy on write - so removed paths don't still show */ DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); @@ -458,8 +463,9 @@ static int pose_clear_paths_exec(bContext *C, wmOperator *op) bool only_selected = RNA_boolean_get(op->ptr, "only_selected"); /* only continue if there's an object */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } /* use the backend function for this */ ED_pose_clear_paths(ob, only_selected); @@ -735,8 +741,9 @@ static int pose_armature_layers_showall_exec(bContext *C, wmOperator *op) int i; /* sanity checking */ - if (arm == NULL) + if (arm == NULL) { return OPERATOR_CANCELLED; + } /* use RNA to set the layers * although it would be faster to just set directly using bitflags, we still @@ -744,8 +751,9 @@ static int pose_armature_layers_showall_exec(bContext *C, wmOperator *op) */ RNA_id_pointer_create(&arm->id, &ptr); - for (i = 0; i < maxLayers; i++) + for (i = 0; i < maxLayers; i++) { layers[i] = 1; + } RNA_boolean_set_array(&ptr, "layers", layers); @@ -788,8 +796,9 @@ static int armature_layers_invoke(bContext *C, wmOperator *op, const wmEvent *ev bool layers[32]; /* sanity checking */ - if (arm == NULL) + if (arm == NULL) { return OPERATOR_CANCELLED; + } /* Get RNA pointer to armature data to use that to retrieve the layers as ints * to init the operator. */ diff --git a/source/blender/editors/armature/pose_group.c b/source/blender/editors/armature/pose_group.c index 0d100a09dfd..3ae9976c948 100644 --- a/source/blender/editors/armature/pose_group.c +++ b/source/blender/editors/armature/pose_group.c @@ -59,8 +59,9 @@ static int pose_group_add_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_pose_object_from_context(C); /* only continue if there's an object and pose */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } /* for now, just call the API function for this */ BKE_pose_add_group(ob->pose, NULL); @@ -91,8 +92,9 @@ static int pose_group_remove_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_pose_object_from_context(C); /* only continue if there's an object and pose */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } /* for now, just call the API function for this */ BKE_pose_remove_group_index(ob->pose, ob->pose->active_group); @@ -134,8 +136,9 @@ static int pose_groups_menu_invoke(bContext *C, wmOperator *op, const wmEvent *U int i; /* only continue if there's an object, and a pose there too */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } pose = ob->pose; /* If group index is set, try to use it! */ @@ -164,8 +167,9 @@ static int pose_groups_menu_invoke(bContext *C, wmOperator *op, const wmEvent *U } /* add entries for each group */ - for (grp = pose->agroups.first, i = 1; grp; grp = grp->next, i++) + for (grp = pose->agroups.first, i = 1; grp; grp = grp->next, i++) { uiItemIntO(layout, grp->name, ICON_NONE, op->idname, "type", i); + } /* finish building the menu, and process it (should result in calling self again) */ UI_popup_menu_end(C, pup); @@ -187,8 +191,9 @@ static int pose_group_assign_exec(bContext *C, wmOperator *op) bool done = false; /* only continue if there's an object, and a pose there too */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } pose = ob->pose; @@ -196,8 +201,9 @@ static int pose_group_assign_exec(bContext *C, wmOperator *op) * - if 0 after this, make a new group... */ pose->active_group = RNA_int_get(op->ptr, "type"); - if (pose->active_group == 0) + if (pose->active_group == 0) { BKE_pose_add_group(ob->pose, NULL); + } /* add selected bones to group then */ FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob, pchan) { @@ -211,10 +217,12 @@ static int pose_group_assign_exec(bContext *C, wmOperator *op) DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); /* report done status */ - if (done) + if (done) { return OPERATOR_FINISHED; - else + } + else { return OPERATOR_CANCELLED; + } } void POSE_OT_group_assign(wmOperatorType *ot) @@ -242,8 +250,9 @@ static int pose_group_unassign_exec(bContext *C, wmOperator *UNUSED(op)) bool done = false; /* only continue if there's an object, and a pose there too */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } /* find selected bones to remove from all bone groups */ FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob, pchan) { @@ -259,10 +268,12 @@ static int pose_group_unassign_exec(bContext *C, wmOperator *UNUSED(op)) DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); /* report done status */ - if (done) + if (done) { return OPERATOR_FINISHED; - else + } + else { return OPERATOR_CANCELLED; + } } void POSE_OT_group_unassign(wmOperatorType *ot) @@ -288,15 +299,18 @@ static int group_move_exec(bContext *C, wmOperator *op) bActionGroup *grp; int dir = RNA_enum_get(op->ptr, "direction"); - if (ELEM(NULL, ob, pose)) + if (ELEM(NULL, ob, pose)) { return OPERATOR_CANCELLED; - if (pose->active_group <= 0) + } + if (pose->active_group <= 0) { return OPERATOR_CANCELLED; + } /* get group to move */ grp = BLI_findlink(&pose->agroups, pose->active_group - 1); - if (grp == NULL) + if (grp == NULL) { return OPERATOR_CANCELLED; + } /* move bone group */ if (BLI_listbase_link_move(&pose->agroups, grp, dir)) { @@ -374,10 +388,12 @@ static int group_sort_exec(bContext *C, wmOperator *UNUSED(op)) int agrp_count; int i; - if (ELEM(NULL, ob, pose)) + if (ELEM(NULL, ob, pose)) { return OPERATOR_CANCELLED; - if (pose->active_group <= 0) + } + if (pose->active_group <= 0) { return OPERATOR_CANCELLED; + } /* create temporary array with bone groups and indices */ agrp_count = BLI_listbase_count(&pose->agroups); @@ -439,12 +455,14 @@ static void pose_group_select(Object *ob, bool select) FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (ob, pchan) { if ((pchan->bone->flag & BONE_UNSELECTABLE) == 0) { if (select) { - if (pchan->agrp_index == pose->active_group) + if (pchan->agrp_index == pose->active_group) { pchan->bone->flag |= BONE_SELECTED; + } } else { - if (pchan->agrp_index == pose->active_group) + if (pchan->agrp_index == pose->active_group) { pchan->bone->flag &= ~BONE_SELECTED; + } } } } @@ -456,8 +474,9 @@ static int pose_group_select_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_pose_object_from_context(C); /* only continue if there's an object, and a pose there too */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } pose_group_select(ob, 1); @@ -489,8 +508,9 @@ static int pose_group_deselect_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_pose_object_from_context(C); /* only continue if there's an object, and a pose there too */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } pose_group_select(ob, 0); diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c index f373f775079..010f1c0e654 100644 --- a/source/blender/editors/armature/pose_lib.c +++ b/source/blender/editors/armature/pose_lib.c @@ -105,8 +105,9 @@ static int poselib_get_free_index(bAction *act) bool changed = false; /* sanity checks */ - if (ELEM(NULL, act, act->markers.first)) + if (ELEM(NULL, act, act->markers.first)) { return 1; + } /* As poses are not stored in chronological order, we must iterate over this list * a few times until we don't make any new discoveries (mostly about the lower bound). @@ -135,19 +136,23 @@ static int poselib_get_free_index(bAction *act) /* - if low is not equal to high, then low+1 is a gap * - if low is equal to high, then high+1 is the next index (add at end) */ - if (low < high) + if (low < high) { return (low + 1); - else + } + else { return (high + 1); + } } /* returns the active pose for a poselib */ static TimeMarker *poselib_get_active_pose(bAction *act) { - if ((act) && (act->active_marker)) + if ((act) && (act->active_marker)) { return BLI_findlink(&act->markers, act->active_marker - 1); - else + } + else { return NULL; + } } /* Get object that Pose Lib should be found on */ @@ -157,15 +162,18 @@ static Object *get_poselib_object(bContext *C) ScrArea *sa; /* sanity check */ - if (C == NULL) + if (C == NULL) { return NULL; + } sa = CTX_wm_area(C); - if (sa && (sa->spacetype == SPACE_PROPERTIES)) + if (sa && (sa->spacetype == SPACE_PROPERTIES)) { return ED_object_context(C); - else + } + else { return BKE_object_pose_armature_get(CTX_data_active_object(C)); + } } /* Poll callback for operators that require existing PoseLib data (with poses) to work */ @@ -190,12 +198,14 @@ static bool has_poselib_pose_data_for_editing_poll(bContext *C) static bAction *poselib_init_new(Main *bmain, Object *ob) { /* sanity checks - only for armatures */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return NULL; + } /* init object's poselib action (unlink old one if there) */ - if (ob->poselib) + if (ob->poselib) { id_us_min(&ob->poselib->id); + } ob->poselib = BKE_action_add(bmain, "PoseLib"); ob->poselib->idroot = ID_OB; @@ -206,12 +216,15 @@ static bAction *poselib_init_new(Main *bmain, Object *ob) /* Initialize a new poselib (checks if that needs to happen) */ static bAction *poselib_validate(Main *bmain, Object *ob) { - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return NULL; - else if (ob->poselib == NULL) + } + else if (ob->poselib == NULL) { return poselib_init_new(bmain, ob); - else + } + else { return ob->poselib; + } } /* ************************************************************* */ @@ -223,8 +236,9 @@ static int poselib_new_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = get_poselib_object(C); /* sanity checks */ - if (ob == NULL) + if (ob == NULL) { return OPERATOR_CANCELLED; + } /* new method here deals with the rest... */ poselib_init_new(bmain, ob); @@ -257,8 +271,9 @@ static int poselib_unlink_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = get_poselib_object(C); /* sanity checks */ - if (ELEM(NULL, ob, ob->poselib)) + if (ELEM(NULL, ob, ob->poselib)) { return OPERATOR_CANCELLED; + } /* there should be a poselib (we just checked above!), so just lower its user count and remove */ id_us_min(&ob->poselib->id); @@ -338,10 +353,12 @@ static int poselib_sanitize_exec(bContext *C, wmOperator *op) for (marker = act->markers.first; marker; marker = markern) { markern = marker->next; - if (marker->flag != -1) + if (marker->flag != -1) { BLI_freelinkN(&act->markers, marker); - else + } + else { marker->flag = 0; + } } /* free temp memory */ @@ -423,8 +440,9 @@ static int poselib_add_menu_invoke(bContext *C, wmOperator *op, const wmEvent *U uiLayout *layout; /* sanity check */ - if (ELEM(NULL, ob, pose)) + if (ELEM(NULL, ob, pose)) { return OPERATOR_CANCELLED; + } /* start building */ pup = UI_popup_menu_begin(C, op->type->name, ICON_NONE); @@ -472,8 +490,9 @@ static int poselib_add_exec(bContext *C, wmOperator *op) char name[64]; /* sanity check (invoke should have checked this anyway) */ - if (ELEM(NULL, ob, pose)) + if (ELEM(NULL, ob, pose)) { return OPERATOR_CANCELLED; + } /* get name to give to pose */ RNA_string_get(op->ptr, "name", name); @@ -955,8 +974,9 @@ static void poselib_backup_posecopy(tPoseLib_PreviewData *pld) plb->pchan = pchan; memcpy(&plb->olddata, plb->pchan, sizeof(bPoseChannel)); - if (pchan->prop) + if (pchan->prop) { plb->oldprops = IDP_CopyProperty(pchan->prop); + } BLI_addtail(&pld->backups, plb); @@ -976,8 +996,9 @@ static void poselib_backup_restore(tPoseLib_PreviewData *pld) memcpy(plb->pchan, &plb->olddata, sizeof(bPoseChannel)); /* just overwrite values of properties from the stored copies (there should be some) */ - if (plb->oldprops) + if (plb->oldprops) { IDP_SyncGroupValues(plb->pchan->prop, plb->oldprops); + } /* TODO: constraints settings aren't restored yet, * even though these could change (though not that likely) */ @@ -1025,10 +1046,12 @@ static void poselib_apply_pose(tPoseLib_PreviewData *pld) const bool any_bone_selected = pld->flag & PL_PREVIEW_ANY_BONE_SELECTED; /* get the frame */ - if (pld->marker) + if (pld->marker) { frame = pld->marker->frame; - else + } + else { return; + } /* init settings for testing groups for keyframes */ group_ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE); @@ -1059,8 +1082,9 @@ static void poselib_apply_pose(tPoseLib_PreviewData *pld) } } - if (ok) + if (ok) { animsys_evaluate_action_group(ptr, act, agrp, (float)frame); + } } } } @@ -1091,13 +1115,15 @@ static void poselib_keytag_pose(bContext *C, Scene *scene, tPoseLib_PreviewData ANIM_relative_keyingset_add_source(&dsources, &pld->ob->id, &RNA_PoseBone, pchan); /* clear any unkeyed tags */ - if (pchan->bone) + if (pchan->bone) { pchan->bone->flag &= ~BONE_UNKEYED; + } } else { /* add unkeyed tags */ - if (pchan->bone) + if (pchan->bone) { pchan->bone->flag |= BONE_UNKEYED; + } } } } @@ -1122,27 +1148,32 @@ static void poselib_preview_apply(bContext *C, wmOperator *op) /* only recalc pose (and its dependencies) if pose has changed */ if (pld->redraw == PL_PREVIEW_REDRAWALL) { /* don't clear pose if firsttime */ - if ((pld->flag & PL_PREVIEW_FIRSTTIME) == 0) + if ((pld->flag & PL_PREVIEW_FIRSTTIME) == 0) { poselib_backup_restore(pld); - else + } + else { pld->flag &= ~PL_PREVIEW_FIRSTTIME; + } /* pose should be the right one to draw (unless we're temporarily not showing it) */ if ((pld->flag & PL_PREVIEW_SHOWORIGINAL) == 0) { RNA_int_set(op->ptr, "pose_index", BLI_findindex(&pld->act->markers, pld->marker)); poselib_apply_pose(pld); } - else + else { RNA_int_set(op->ptr, "pose_index", -2); /* -2 means don't apply any pose */ + } /* old optimize trick... this enforces to bypass the depsgraph * - note: code copied from transform_generics.c -> recalcData() */ // FIXME: shouldn't this use the builtin stuff? - if ((pld->arm->flag & ARM_DELAYDEFORM) == 0) + if ((pld->arm->flag & ARM_DELAYDEFORM) == 0) { DEG_id_tag_update(&pld->ob->id, ID_RECALC_GEOMETRY); /* sets recalc flags */ - else + } + else { BKE_pose_where_is(CTX_data_depsgraph(C), pld->scene, pld->ob); + } } /* do header print - if interactively previewing */ @@ -1203,8 +1234,9 @@ static void poselib_preview_apply(bContext *C, wmOperator *op) static void poselib_preview_get_next(tPoseLib_PreviewData *pld, int step) { /* stop if not going anywhere, as we assume that there is a direction to move in */ - if (step == 0) + if (step == 0) { return; + } /* search-string dictates a special approach */ if (pld->searchstr[0]) { @@ -1242,50 +1274,59 @@ static void poselib_preview_get_next(tPoseLib_PreviewData *pld, int step) /* find first match */ for (ldc = pld->searchp.first; ldc; ldc = ldc->next) { - if (ldc->data == pld->marker) + if (ldc->data == pld->marker) { break; + } } - if (ldc == NULL) + if (ldc == NULL) { ldc = pld->searchp.first; + } /* Loop through the matches in a cyclic fashion, incrementing/decrementing step as appropriate * until step == 0. At this point, marker should be the correct marker. */ if (step > 0) { - for (ld = ldc; ld && step; ld = ldn, step--) + for (ld = ldc; ld && step; ld = ldn, step--) { ldn = (ld->next) ? ld->next : pld->searchp.first; + } } else { - for (ld = ldc; ld && step; ld = ldn, step++) + for (ld = ldc; ld && step; ld = ldn, step++) { ldn = (ld->prev) ? ld->prev : pld->searchp.last; + } } /* set marker */ - if (ld) + if (ld) { pld->marker = ld->data; + } } else { TimeMarker *marker, *next; /* if no marker, because we just ended searching, then set that to the start of the list */ - if (pld->marker == NULL) + if (pld->marker == NULL) { pld->marker = pld->act->markers.first; + } /* Loop through the markers in a cyclic fashion, incrementing/decrementing step as appropriate * until step == 0. At this point, marker should be the correct marker. */ if (step > 0) { - for (marker = pld->marker; marker && step; marker = next, step--) + for (marker = pld->marker; marker && step; marker = next, step--) { next = (marker->next) ? marker->next : pld->act->markers.first; + } } else { - for (marker = pld->marker; marker && step; marker = next, step++) + for (marker = pld->marker; marker && step; marker = next, step++) { next = (marker->prev) ? marker->prev : pld->act->markers.last; + } } /* it should be fairly impossible for marker to be NULL */ - if (marker) + if (marker) { pld->marker = marker; + } } } @@ -1302,8 +1343,9 @@ static void poselib_preview_handle_search(tPoseLib_PreviewData *pld, short index = pld->search_cursor; short i; - for (i = index; i <= len; i++) + for (i = index; i <= len; i++) { pld->searchstr[i - 1] = pld->searchstr[i]; + } pld->search_cursor--; @@ -1320,8 +1362,9 @@ static void poselib_preview_handle_search(tPoseLib_PreviewData *pld, int i; if (index < len) { - for (i = index; i < len; i++) + for (i = index; i < len; i++) { pld->searchstr[i] = pld->searchstr[i + 1]; + } poselib_preview_get_next(pld, 1); pld->redraw = PL_PREVIEW_REDRAWALL; @@ -1338,11 +1381,13 @@ static void poselib_preview_handle_search(tPoseLib_PreviewData *pld, short i; if (len) { - for (i = len; i > index; i--) + for (i = len; i > index; i--) { pld->searchstr[i] = pld->searchstr[i - 1]; + } } - else + else { pld->searchstr[1] = 0; + } pld->searchstr[index] = ascii; pld->search_cursor++; @@ -1476,8 +1521,9 @@ static int poselib_preview_handle_event(bContext *UNUSED(C), wmOperator *op, con case RIGHTARROWKEY: if (pld->searchstr[0]) { /* move text-cursor to the right */ - if (pld->search_cursor < strlen(pld->searchstr)) + if (pld->search_cursor < strlen(pld->searchstr)) { pld->search_cursor++; + } pld->redraw = PL_PREVIEW_REDRAWHEADER; } else { @@ -1491,8 +1537,9 @@ static int poselib_preview_handle_event(bContext *UNUSED(C), wmOperator *op, con case LEFTARROWKEY: if (pld->searchstr[0]) { /* move text-cursor to the left */ - if (pld->search_cursor) + if (pld->search_cursor) { pld->search_cursor--; + } pld->redraw = PL_PREVIEW_REDRAWHEADER; } else { @@ -1597,12 +1644,15 @@ static void poselib_preview_init_data(bContext *C, wmOperator *op) pld->sa = CTX_wm_area(C); /* get starting pose based on RNA-props for this operator */ - if (pose_index == -1) + if (pose_index == -1) { pld->marker = poselib_get_active_pose(pld->act); - else if (pose_index == -2) + } + else if (pose_index == -2) { pld->flag |= PL_PREVIEW_SHOWORIGINAL; - else + } + else { pld->marker = (pld->act) ? BLI_findlink(&pld->act->markers, pose_index) : NULL; + } /* check if valid poselib */ if (ELEM(NULL, pld->ob, pld->pose, pld->arm)) { @@ -1619,8 +1669,9 @@ static void poselib_preview_init_data(bContext *C, wmOperator *op) if (pld->act->markers.first) { /* just use first one then... */ pld->marker = pld->act->markers.first; - if (pose_index > -2) + if (pose_index > -2) { BKE_report(op->reports, RPT_WARNING, "Pose lib had no active pose"); + } } else { BKE_report(op->reports, RPT_ERROR, "Pose lib has no poses to preview/apply"); @@ -1675,10 +1726,12 @@ static void poselib_preview_cleanup(bContext *C, wmOperator *op) /* old optimize trick... this enforces to bypass the depgraph * - note: code copied from transform_generics.c -> recalcData() */ - if ((arm->flag & ARM_DELAYDEFORM) == 0) + if ((arm->flag & ARM_DELAYDEFORM) == 0) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); /* sets recalc flags */ - else + } + else { BKE_pose_where_is(CTX_data_depsgraph(C), scene, ob); + } } else if (pld->state == PL_PREVIEW_CONFIRM) { /* tag poses as appropriate */ @@ -1695,8 +1748,9 @@ static void poselib_preview_cleanup(bContext *C, wmOperator *op) if (IS_AUTOKEY_MODE(scene, NORMAL)) { //remake_action_ipos(ob->action); } - else + else { BKE_pose_where_is(CTX_data_depsgraph(C), scene, ob); + } } /* Request final redraw of the view. */ @@ -1720,10 +1774,12 @@ static int poselib_preview_exit(bContext *C, wmOperator *op) /* finish up */ poselib_preview_cleanup(C, op); - if (ELEM(exit_state, PL_PREVIEW_CANCEL, PL_PREVIEW_ERROR)) + if (ELEM(exit_state, PL_PREVIEW_CANCEL, PL_PREVIEW_ERROR)) { return OPERATOR_CANCELLED; - else + } + else { return OPERATOR_FINISHED; + } } /* Cancel previewing operation (called when exiting Blender) */ @@ -1739,15 +1795,17 @@ static int poselib_preview_modal(bContext *C, wmOperator *op, const wmEvent *eve int ret; /* 1) check state to see if we're still running */ - if (pld->state != PL_PREVIEW_RUNNING) + if (pld->state != PL_PREVIEW_RUNNING) { return poselib_preview_exit(C, op); + } /* 2) handle events */ ret = poselib_preview_handle_event(C, op, event); /* 3) apply changes and redraw, otherwise, confirming goes wrong */ - if (pld->redraw) + if (pld->redraw) { poselib_preview_apply(C, op); + } return ret; } diff --git a/source/blender/editors/armature/pose_select.c b/source/blender/editors/armature/pose_select.c index d26eb7e904d..e9ea49aaf03 100644 --- a/source/blender/editors/armature/pose_select.c +++ b/source/blender/editors/armature/pose_select.c @@ -71,8 +71,9 @@ static void pose_do_bone_select(bPoseChannel *pchan, const int select_mode) /* select pchan only if selectable, but deselect works always */ switch (select_mode) { case SEL_SELECT: - if (!(pchan->bone->flag & BONE_UNSELECTABLE)) + if (!(pchan->bone->flag & BONE_UNSELECTABLE)) { pchan->bone->flag |= BONE_SELECTED; + } break; case SEL_DESELECT: pchan->bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); @@ -110,8 +111,9 @@ void ED_pose_bone_select(Object *ob, bPoseChannel *pchan, bool select) /* sanity checks */ // XXX: actually, we can probably still get away with no object - at most we have no updates - if (ELEM(NULL, ob, ob->pose, pchan, pchan->bone)) + if (ELEM(NULL, ob, ob->pose, pchan, pchan->bone)) { return; + } arm = ob->data; @@ -147,8 +149,9 @@ bool ED_armature_pose_select_pick_with_buffer(ViewLayer *view_layer, Object *ob = base->object; Bone *nearBone; - if (!ob || !ob->pose) + if (!ob || !ob->pose) { return 0; + } Object *ob_act = OBACT(view_layer); Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); @@ -346,16 +349,20 @@ static void selectconnected_posebonechildren(Object *ob, Bone *bone, int extend) Bone *curBone; /* stop when unconnected child is encountered, or when unselectable bone is encountered */ - if (!(bone->flag & BONE_CONNECTED) || (bone->flag & BONE_UNSELECTABLE)) + if (!(bone->flag & BONE_CONNECTED) || (bone->flag & BONE_UNSELECTABLE)) { return; + } - if (extend) + if (extend) { bone->flag &= ~BONE_SELECTED; - else + } + else { bone->flag |= BONE_SELECTED; + } - for (curBone = bone->childbase.first; curBone; curBone = curBone->next) + for (curBone = bone->childbase.first; curBone; curBone = curBone->next) { selectconnected_posebonechildren(ob, curBone, extend); + } } /* within active object context */ @@ -370,30 +377,37 @@ static int pose_select_connected_invoke(bContext *C, wmOperator *op, const wmEve Base *base = NULL; bone = get_nearest_bone(C, event->mval, !extend, &base); - if (!bone) + if (!bone) { return OPERATOR_CANCELLED; + } /* Select parents */ for (curBone = bone; curBone; curBone = next) { /* ignore bone if cannot be selected */ if ((curBone->flag & BONE_UNSELECTABLE) == 0) { - if (extend) + if (extend) { curBone->flag &= ~BONE_SELECTED; - else + } + else { curBone->flag |= BONE_SELECTED; + } - if (curBone->flag & BONE_CONNECTED) + if (curBone->flag & BONE_CONNECTED) { next = curBone->parent; - else + } + else { next = NULL; + } } - else + else { next = NULL; + } } /* Select children */ - for (curBone = bone->childbase.first; curBone; curBone = next) + for (curBone = bone->childbase.first; curBone; curBone = next) { selectconnected_posebonechildren(base->object, curBone, extend); + } ED_pose_bone_select_tag_update(base->object); @@ -557,16 +571,18 @@ static int pose_select_constraint_target_exec(bContext *C, wmOperator *UNUSED(op } } - if (cti->flush_constraint_targets) + if (cti->flush_constraint_targets) { cti->flush_constraint_targets(con, &targets, 1); + } } } } } CTX_DATA_END; - if (!found) + if (!found) { return OPERATOR_CANCELLED; + } return OPERATOR_FINISHED; } @@ -828,12 +844,14 @@ static bool pose_select_same_layer(bContext *C, bool extend) } /* Keep track of layers to use later? */ - if (pchan->bone->flag & BONE_SELECTED) + if (pchan->bone->flag & BONE_SELECTED) { *layers |= pchan->bone->layer; + } /* Deselect all bones before selecting new ones? */ - if ((extend == false) && (pchan->bone->flag & BONE_UNSELECTABLE) == 0) + if ((extend == false) && (pchan->bone->flag & BONE_UNSELECTABLE) == 0) { pchan->bone->flag &= ~BONE_SELECTED; + } } CTX_DATA_END; @@ -912,8 +930,9 @@ static bool pose_select_same_keyingset(bContext *C, ReportList *reports, bool ex /* if not extending selection, deselect all selected first */ if (extend == false) { CTX_DATA_BEGIN (C, bPoseChannel *, pchan, visible_pose_bones) { - if ((pchan->bone->flag & BONE_UNSELECTABLE) == 0) + if ((pchan->bone->flag & BONE_UNSELECTABLE) == 0) { pchan->bone->flag &= ~BONE_SELECTED; + } } CTX_DATA_END; } @@ -977,8 +996,9 @@ static int pose_select_grouped_exec(bContext *C, wmOperator *op) bool changed = false; /* sanity check */ - if (ob->pose == NULL) + if (ob->pose == NULL) { return OPERATOR_CANCELLED; + } /* selection types */ switch (type) { @@ -1000,10 +1020,12 @@ static int pose_select_grouped_exec(bContext *C, wmOperator *op) } /* report done status */ - if (changed) + if (changed) { return OPERATOR_FINISHED; - else + } + else { return OPERATOR_CANCELLED; + } } void POSE_OT_select_grouped(wmOperatorType *ot) diff --git a/source/blender/editors/armature/pose_slide.c b/source/blender/editors/armature/pose_slide.c index 7bc934e07a2..79182a89096 100644 --- a/source/blender/editors/armature/pose_slide.c +++ b/source/blender/editors/armature/pose_slide.c @@ -459,8 +459,9 @@ static void pose_slide_apply_props(tPoseSlideOp *pso, FCurve *fcu = (FCurve *)ld->data; const char *bPtr, *pPtr; - if (fcu->rna_path == NULL) + if (fcu->rna_path == NULL) { continue; + } /* do we have a match? * - bPtr is the RNA Path with the standard part chopped off @@ -1209,8 +1210,9 @@ static int pose_slide_push_invoke(bContext *C, wmOperator *op, const wmEvent *ev pose_slide_exit(op); return OPERATOR_CANCELLED; } - else + else { pso = op->customdata; + } /* initialise percentage so that it won't pop on first mouse move */ pose_slide_mouse_update_percentage(pso, op, event); @@ -1229,8 +1231,9 @@ static int pose_slide_push_exec(bContext *C, wmOperator *op) pose_slide_exit(op); return OPERATOR_CANCELLED; } - else + else { pso = op->customdata; + } /* do common exec work */ return pose_slide_exec_common(C, op, pso); @@ -1269,8 +1272,9 @@ static int pose_slide_relax_invoke(bContext *C, wmOperator *op, const wmEvent *e pose_slide_exit(op); return OPERATOR_CANCELLED; } - else + else { pso = op->customdata; + } /* initialise percentage so that it won't pop on first mouse move */ pose_slide_mouse_update_percentage(pso, op, event); @@ -1289,8 +1293,9 @@ static int pose_slide_relax_exec(bContext *C, wmOperator *op) pose_slide_exit(op); return OPERATOR_CANCELLED; } - else + else { pso = op->customdata; + } /* do common exec work */ return pose_slide_exec_common(C, op, pso); @@ -1329,8 +1334,9 @@ static int pose_slide_breakdown_invoke(bContext *C, wmOperator *op, const wmEven pose_slide_exit(op); return OPERATOR_CANCELLED; } - else + else { pso = op->customdata; + } /* initialise percentage so that it won't pop on first mouse move */ pose_slide_mouse_update_percentage(pso, op, event); @@ -1349,8 +1355,9 @@ static int pose_slide_breakdown_exec(bContext *C, wmOperator *op) pose_slide_exit(op); return OPERATOR_CANCELLED; } - else + else { pso = op->customdata; + } /* do common exec work */ return pose_slide_exec_common(C, op, pso); @@ -1565,15 +1572,17 @@ static void pose_propagate_fcurve( short first = 1; /* skip if no keyframes to edit */ - if ((fcu->bezt == NULL) || (fcu->totvert < 2)) + if ((fcu->bezt == NULL) || (fcu->totvert < 2)) { return; + } /* find the reference value from bones directly, which means that the user * doesn't need to firstly keyframe the pose (though this doesn't mean that * they can't either) */ - if (!pose_propagate_get_refVal(ob, fcu, &refVal)) + if (!pose_propagate_get_refVal(ob, fcu, &refVal)) { return; + } /* find the first keyframe to start propagating from * - if there's a keyframe on the current frame, we probably want to save this value there too @@ -1585,10 +1594,12 @@ static void pose_propagate_fcurve( if (mode != POSE_PROPAGATE_SELECTED_KEYS) { match = binarysearch_bezt_index(fcu->bezt, startFrame, fcu->totvert, &keyExists); - if (fcu->bezt[match].vec[1][0] < startFrame) + if (fcu->bezt[match].vec[1][0] < startFrame) { i = match + 1; - else + } + else { i = match; + } } else { /* selected - start from first keyframe */ @@ -1599,18 +1610,21 @@ static void pose_propagate_fcurve( /* additional termination conditions based on the operator 'mode' property go here... */ if (ELEM(mode, POSE_PROPAGATE_BEFORE_FRAME, POSE_PROPAGATE_SMART_HOLDS)) { /* stop if keyframe is outside the accepted range */ - if (bezt->vec[1][0] > modeData.end_frame) + if (bezt->vec[1][0] > modeData.end_frame) { break; + } } else if (mode == POSE_PROPAGATE_NEXT_KEY) { /* stop after the first keyframe has been processed */ - if (first == 0) + if (first == 0) { break; + } } else if (mode == POSE_PROPAGATE_LAST_KEY) { /* only affect this frame if it will be the last one */ - if (i != (fcu->totvert - 1)) + if (i != (fcu->totvert - 1)) { continue; + } } else if (mode == POSE_PROPAGATE_SELECTED_MARKERS) { /* only allow if there's a marker on this frame */ @@ -1618,18 +1632,21 @@ static void pose_propagate_fcurve( /* stop on matching marker if there is one */ for (ce = modeData.sel_markers.first; ce; ce = ce->next) { - if (ce->cfra == round_fl_to_int(bezt->vec[1][0])) + if (ce->cfra == round_fl_to_int(bezt->vec[1][0])) { break; + } } /* skip this keyframe if no marker */ - if (ce == NULL) + if (ce == NULL) { continue; + } } else if (mode == POSE_PROPAGATE_SELECTED_KEYS) { /* only allow if this keyframe is already selected - skip otherwise */ - if (BEZT_ISSEL_ANY(bezt) == 0) + if (BEZT_ISSEL_ANY(bezt) == 0) { continue; + } } /* just flatten handles, since values will now be the same either side... */ @@ -1698,8 +1715,9 @@ static int pose_propagate_exec(bContext *C, wmOperator *op) /* free temp data */ poseAnim_mapping_free(&pflinks); - if (mode == POSE_PROPAGATE_SELECTED_MARKERS) + if (mode == POSE_PROPAGATE_SELECTED_MARKERS) { BLI_freelistN(&modeData.sel_markers); + } /* updates + notifiers */ FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob) { diff --git a/source/blender/editors/armature/pose_transform.c b/source/blender/editors/armature/pose_transform.c index 824e8b1a327..91f0bdc51ad 100644 --- a/source/blender/editors/armature/pose_transform.c +++ b/source/blender/editors/armature/pose_transform.c @@ -102,8 +102,9 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op) EditBone *curbone; /* don't check if editmode (should be done by caller) */ - if (ob->type != OB_ARMATURE) + if (ob->type != OB_ARMATURE) { return OPERATOR_CANCELLED; + } if (BKE_object_obdata_is_libdata(ob)) { BKE_report(op->reports, RPT_ERROR, "Cannot apply pose to lib-linked armature"); return OPERATOR_CANCELLED; @@ -111,11 +112,12 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op) /* helpful warnings... */ /* TODO: add warnings to be careful about actions, applying deforms first, etc. */ - if (ob->adt && ob->adt->action) + if (ob->adt && ob->adt->action) { BKE_report(op->reports, RPT_WARNING, "Actions on this armature will be destroyed by this new rest pose as the " "transforms stored are relative to the old rest pose"); + } /* Get editbones of active armature to alter */ ED_armature_to_edit(arm); @@ -293,10 +295,12 @@ static void set_pose_keys(Object *ob) if (ob->pose) { for (chan = ob->pose->chanbase.first; chan; chan = chan->next) { Bone *bone = chan->bone; - if ((bone) && (bone->flag & BONE_SELECTED) && (arm->layer & bone->layer)) + if ((bone) && (bone->flag & BONE_SELECTED) && (arm->layer & bone->layer)) { chan->flag |= POSE_KEY; - else + } + else { chan->flag &= ~POSE_KEY; + } } } } @@ -320,10 +324,12 @@ static bPoseChannel *pose_bone_do_paste(Object *ob, short paste_ok; /* get the name - if flipping, we must flip this first */ - if (flip) + if (flip) { BLI_string_flip_side_name(name, chan->name, false, sizeof(name)); - else + } + else { BLI_strncpy(name, chan->name, sizeof(name)); + } /* only copy when: * 1) channel exists - poses are not meant to add random channels to anymore @@ -332,10 +338,12 @@ static bPoseChannel *pose_bone_do_paste(Object *ob, */ pchan = BKE_pose_channel_find_name(ob->pose, name); - if (selOnly) + if (selOnly) { paste_ok = ((pchan) && (pchan->bone->flag & BONE_SELECTED)); - else + } + else { paste_ok = (pchan != NULL); + } /* continue? */ if (paste_ok) { @@ -362,24 +370,30 @@ static bPoseChannel *pose_bone_do_paste(Object *ob, } else if (pchan->rotmode > 0) { /* quat/axis-angle to euler */ - if (chan->rotmode == ROT_MODE_AXISANGLE) + if (chan->rotmode == ROT_MODE_AXISANGLE) { axis_angle_to_eulO(pchan->eul, pchan->rotmode, chan->rotAxis, chan->rotAngle); - else + } + else { quat_to_eulO(pchan->eul, pchan->rotmode, chan->quat); + } } else if (pchan->rotmode == ROT_MODE_AXISANGLE) { /* quat/euler to axis angle */ - if (chan->rotmode > 0) + if (chan->rotmode > 0) { eulO_to_axis_angle(pchan->rotAxis, &pchan->rotAngle, chan->eul, chan->rotmode); - else + } + else { quat_to_axis_angle(pchan->rotAxis, &pchan->rotAngle, chan->quat); + } } else { /* euler/axis-angle to quat */ - if (chan->rotmode > 0) + if (chan->rotmode > 0) { eulO_to_quat(pchan->quat, chan->eul, chan->rotmode); - else + } + else { axis_angle_to_quat(pchan->quat, chan->rotAxis, pchan->rotAngle); + } } /* B-Bone posing options should also be included... */ @@ -628,12 +642,15 @@ void POSE_OT_paste(wmOperatorType *ot) /* clear scale of pose-channel */ static void pchan_clear_scale(bPoseChannel *pchan) { - if ((pchan->protectflag & OB_LOCK_SCALEX) == 0) + if ((pchan->protectflag & OB_LOCK_SCALEX) == 0) { pchan->size[0] = 1.0f; - if ((pchan->protectflag & OB_LOCK_SCALEY) == 0) + } + if ((pchan->protectflag & OB_LOCK_SCALEY) == 0) { pchan->size[1] = 1.0f; - if ((pchan->protectflag & OB_LOCK_SCALEZ) == 0) + } + if ((pchan->protectflag & OB_LOCK_SCALEZ) == 0) { pchan->size[2] = 1.0f; + } pchan->ease1 = 0.0f; pchan->ease2 = 0.0f; @@ -644,12 +661,15 @@ static void pchan_clear_scale(bPoseChannel *pchan) /* clear location of pose-channel */ static void pchan_clear_loc(bPoseChannel *pchan) { - if ((pchan->protectflag & OB_LOCK_LOCX) == 0) + if ((pchan->protectflag & OB_LOCK_LOCX) == 0) { pchan->loc[0] = 0.0f; - if ((pchan->protectflag & OB_LOCK_LOCY) == 0) + } + if ((pchan->protectflag & OB_LOCK_LOCY) == 0) { pchan->loc[1] = 0.0f; - if ((pchan->protectflag & OB_LOCK_LOCZ) == 0) + } + if ((pchan->protectflag & OB_LOCK_LOCZ) == 0) { pchan->loc[2] = 0.0f; + } } /* clear rotation of pose-channel */ @@ -660,39 +680,51 @@ static void pchan_clear_rot(bPoseChannel *pchan) if (pchan->protectflag & OB_LOCK_ROT4D) { /* perform clamping on a component by component basis */ if (pchan->rotmode == ROT_MODE_AXISANGLE) { - if ((pchan->protectflag & OB_LOCK_ROTW) == 0) + if ((pchan->protectflag & OB_LOCK_ROTW) == 0) { pchan->rotAngle = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTX) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTX) == 0) { pchan->rotAxis[0] = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTY) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTY) == 0) { pchan->rotAxis[1] = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) { pchan->rotAxis[2] = 0.0f; + } /* check validity of axis - axis should never be 0,0,0 * (if so, then we make it rotate about y). */ if (IS_EQF(pchan->rotAxis[0], pchan->rotAxis[1]) && - IS_EQF(pchan->rotAxis[1], pchan->rotAxis[2])) + IS_EQF(pchan->rotAxis[1], pchan->rotAxis[2])) { pchan->rotAxis[1] = 1.0f; + } } else if (pchan->rotmode == ROT_MODE_QUAT) { - if ((pchan->protectflag & OB_LOCK_ROTW) == 0) + if ((pchan->protectflag & OB_LOCK_ROTW) == 0) { pchan->quat[0] = 1.0f; - if ((pchan->protectflag & OB_LOCK_ROTX) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTX) == 0) { pchan->quat[1] = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTY) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTY) == 0) { pchan->quat[2] = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) { pchan->quat[3] = 0.0f; + } } else { /* the flag may have been set for the other modes, so just ignore the extra flag... */ - if ((pchan->protectflag & OB_LOCK_ROTX) == 0) + if ((pchan->protectflag & OB_LOCK_ROTX) == 0) { pchan->eul[0] = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTY) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTY) == 0) { pchan->eul[1] = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) { pchan->eul[2] = 0.0f; + } } } else { @@ -713,12 +745,15 @@ static void pchan_clear_rot(bPoseChannel *pchan) eul[0] = eul[1] = eul[2] = 0.0f; - if (pchan->protectflag & OB_LOCK_ROTX) + if (pchan->protectflag & OB_LOCK_ROTX) { eul[0] = oldeul[0]; - if (pchan->protectflag & OB_LOCK_ROTY) + } + if (pchan->protectflag & OB_LOCK_ROTY) { eul[1] = oldeul[1]; - if (pchan->protectflag & OB_LOCK_ROTZ) + } + if (pchan->protectflag & OB_LOCK_ROTZ) { eul[2] = oldeul[2]; + } if (pchan->rotmode == ROT_MODE_QUAT) { eul_to_quat(pchan->quat, eul); diff --git a/source/blender/editors/armature/pose_utils.c b/source/blender/editors/armature/pose_utils.c index 844fce49d28..2b7bd9ea05a 100644 --- a/source/blender/editors/armature/pose_utils.c +++ b/source/blender/editors/armature/pose_utils.c @@ -91,14 +91,18 @@ static void fcurves_to_pchan_links_get(ListBase *pfLinks, BLI_addtail(pfLinks, pfl); /* set pchan's transform flags */ - if (transFlags & ACT_TRANS_LOC) + if (transFlags & ACT_TRANS_LOC) { pchan->flag |= POSE_LOC; - if (transFlags & ACT_TRANS_ROT) + } + if (transFlags & ACT_TRANS_ROT) { pchan->flag |= POSE_ROT; - if (transFlags & ACT_TRANS_SCALE) + } + if (transFlags & ACT_TRANS_SCALE) { pchan->flag |= POSE_SIZE; - if (transFlags & ACT_TRANS_BBONE) + } + if (transFlags & ACT_TRANS_BBONE) { pchan->flag |= POSE_BBONE_SHAPE; + } /* store current transforms */ copy_v3_v3(pfl->oldloc, pchan->loc); @@ -121,8 +125,9 @@ static void fcurves_to_pchan_links_get(ListBase *pfLinks, pfl->scaleOut = pchan->scaleOut; /* make copy of custom properties */ - if (pchan->prop && (transFlags & ACT_TRANS_PROP)) + if (pchan->prop && (transFlags & ACT_TRANS_PROP)) { pfl->oldprops = IDP_CopyProperty(pchan->prop); + } } } @@ -222,10 +227,12 @@ void poseAnim_mapping_refresh(bContext *C, Scene *scene, Object *ob) * - note: code copied from transform_generics.c -> recalcData() */ /* FIXME: shouldn't this use the builtin stuff? */ - if ((arm->flag & ARM_DELAYDEFORM) == 0) + if ((arm->flag & ARM_DELAYDEFORM) == 0) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); /* sets recalc flags */ - else + } + else { BKE_pose_where_is(depsgraph, scene, ob); + } /* otherwise animation doesn't get updated */ DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); @@ -262,8 +269,9 @@ void poseAnim_mapping_reset(ListBase *pfLinks) pchan->scaleOut = pfl->scaleOut; /* just overwrite values of properties from the stored copies (there should be some) */ - if (pfl->oldprops) + if (pfl->oldprops) { IDP_SyncGroupValues(pfl->pchan->prop, pfl->oldprops); + } } } @@ -353,8 +361,9 @@ LinkData *poseAnim_mapping_getNextFCurve(ListBase *fcuLinks, LinkData *prev, con FCurve *fcu = (FCurve *)ld->data; /* check if paths match */ - if (STREQ(path, fcu->rna_path)) + if (STREQ(path, fcu->rna_path)) { return ld; + } } /* none found */ -- cgit v1.2.3