Multi-Objecs: Select similar armature: SIMEDBONE_PREFIX and SIMEDBONE_SUFFIX

This commit is contained in:
Dalai Felinto 2018-10-02 19:38:00 +00:00
parent 6b3ff1ec75
commit ecce4f49bb
1 changed files with 55 additions and 26 deletions

View File

@ -1087,33 +1087,52 @@ static void select_similar_layer(bArmature *arm, EditBone *ebone_act)
}
}
static void select_similar_prefix(bArmature *arm, EditBone *ebone_act)
static void select_similar_prefix(bContext *C)
{
EditBone *ebone;
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob_act = CTX_data_edit_object(C);
EditBone *ebone_act = CTX_data_active_bone(C);
char body_tmp[MAXBONENAME];
char prefix_act[MAXBONENAME];
BLI_string_split_prefix(ebone_act->name, prefix_act, body_tmp, sizeof(ebone_act->name));
if (prefix_act[0] == '\0')
if (prefix_act[0] == '\0') {
return;
}
/* Find matches */
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
if (EBONE_SELECTABLE(arm, ebone)) {
char prefix_other[MAXBONENAME];
BLI_string_split_prefix(ebone->name, prefix_other, body_tmp, sizeof(ebone->name));
if (STREQ(prefix_act, prefix_other)) {
ED_armature_ebone_select_set(ebone, true);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object * ob = objects[ob_index];
bArmature * arm = ob->data;
bool changed = false;
/* Find matches */
for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next) {
if (EBONE_SELECTABLE(arm, ebone)) {
char prefix_other[MAXBONENAME];
BLI_string_split_prefix(ebone->name, prefix_other, body_tmp, sizeof(ebone->name));
if (STREQ(prefix_act, prefix_other)) {
ED_armature_ebone_select_set(ebone, true);
changed = true;
}
}
}
if (changed) {
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
}
}
MEM_freeN(objects);
}
static void select_similar_suffix(bArmature *arm, EditBone *ebone_act)
static void select_similar_suffix(bContext *C)
{
EditBone *ebone;
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob_act = CTX_data_edit_object(C);
EditBone *ebone_act = CTX_data_active_bone(C);
char body_tmp[MAXBONENAME];
char suffix_act[MAXBONENAME];
@ -1123,16 +1142,30 @@ static void select_similar_suffix(bArmature *arm, EditBone *ebone_act)
if (suffix_act[0] == '\0')
return;
/* Find matches */
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
if (EBONE_SELECTABLE(arm, ebone)) {
char suffix_other[MAXBONENAME];
BLI_string_split_suffix(ebone->name, body_tmp, suffix_other, sizeof(ebone->name));
if (STREQ(suffix_act, suffix_other)) {
ED_armature_ebone_select_set(ebone, true);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object * ob = objects[ob_index];
bArmature * arm = ob->data;
bool changed = false;
/* Find matches */
for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next) {
if (EBONE_SELECTABLE(arm, ebone)) {
char suffix_other[MAXBONENAME];
BLI_string_split_suffix(ebone->name, body_tmp, suffix_other, sizeof(ebone->name));
if (STREQ(suffix_act, suffix_other)) {
ED_armature_ebone_select_set(ebone, true);
changed = true;
}
}
}
if (changed) {
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
}
}
MEM_freeN(objects);
}
/** Use for matching any pose channel data. */
@ -1236,11 +1269,7 @@ static int armature_select_similar_exec(bContext *C, wmOperator *op)
int type = RNA_enum_get(op->ptr, "type");
float thresh = RNA_float_get(op->ptr, "threshold");
if (ELEM(type,
SIMEDBONE_PREFIX,
SIMEDBONE_SUFFIX,
SIMEDBONE_LAYER))
{
if (type == SIMEDBONE_LAYER) {
BKE_report(op->reports, RPT_ERROR, "Armature select similar mode not supported at the moment");
return OPERATOR_CANCELLED;
}
@ -1271,10 +1300,10 @@ static int armature_select_similar_exec(bContext *C, wmOperator *op)
select_similar_direction(C, thresh);
break;
case SIMEDBONE_PREFIX:
select_similar_prefix(arm, ebone_act);
select_similar_prefix(C);
break;
case SIMEDBONE_SUFFIX:
select_similar_suffix(arm, ebone_act);
select_similar_suffix(C);
break;
case SIMEDBONE_LAYER:
select_similar_layer(arm, ebone_act);