- improve select grouped prefix/suffix from recent patch
- added select similar direction (Y axis)
This commit is contained in:
@@ -71,7 +71,10 @@ void defvert_normalize_lock(struct MDeformVert *dvert, const int def_nr_lock);
|
||||
|
||||
/* utility function, note that 32 chars is the maximum string length since its only
|
||||
* used with defgroups currently */
|
||||
int BKE_deform_is_char_sep(const char c);
|
||||
|
||||
void BKE_deform_split_suffix(const char string[MAX_VGROUP_NAME], char base[MAX_VGROUP_NAME], char ext[MAX_VGROUP_NAME]);
|
||||
void BKE_deform_split_prefix(const char string[MAX_VGROUP_NAME], char base[MAX_VGROUP_NAME], char ext[MAX_VGROUP_NAME]);
|
||||
|
||||
void flip_side_name(char name[64], const char from_name[64], int strip_number);
|
||||
|
||||
#endif
|
||||
|
@@ -437,11 +437,51 @@ void defgroup_unique_name(bDeformGroup *dg, Object *ob)
|
||||
BLI_uniquename_cb(defgroup_unique_check, &data, "Group", '.', dg->name, sizeof(dg->name));
|
||||
}
|
||||
|
||||
int BKE_deform_is_char_sep(const char c)
|
||||
static int is_char_sep(const char c)
|
||||
{
|
||||
return ELEM4(c, '.', ' ', '-', '_');
|
||||
}
|
||||
|
||||
/* based on BLI_split_dirfile() / os.path.splitext(), "a.b.c" -> ("a.b", ".c") */
|
||||
|
||||
void BKE_deform_split_suffix(const char string[MAX_VGROUP_NAME], char body[MAX_VGROUP_NAME], char suf[MAX_VGROUP_NAME])
|
||||
{
|
||||
size_t len = BLI_strnlen(string, MAX_VGROUP_NAME);
|
||||
size_t i;
|
||||
|
||||
body[0] = suf[0] = '\0';
|
||||
|
||||
for (i = len - 1; i > 1; i--) {
|
||||
if (is_char_sep(string[i])) {
|
||||
BLI_strncpy(body, string, i + 1);
|
||||
BLI_strncpy(suf, string + i, (len + 1) - i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
BLI_strncpy(body, string, len);
|
||||
}
|
||||
|
||||
/* "a.b.c" -> ("a.", "b.c") */
|
||||
void BKE_deform_split_prefix(const char string[MAX_VGROUP_NAME], char pre[MAX_VGROUP_NAME], char body[MAX_VGROUP_NAME])
|
||||
{
|
||||
size_t len = BLI_strnlen(string, MAX_VGROUP_NAME);
|
||||
size_t i;
|
||||
|
||||
body[0] = pre[0] = '\0';
|
||||
|
||||
for (i = 1; i < len; i++) {
|
||||
if (is_char_sep(string[i])) {
|
||||
i++;
|
||||
BLI_strncpy(pre, string, i + 1);
|
||||
BLI_strncpy(body, string + i, (len + 1) - i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
BLI_strncpy(body, string, len);
|
||||
}
|
||||
|
||||
/* finds the best possible flipped name. For renaming; check for unique names afterwards */
|
||||
/* if strip_number: removes number extensions
|
||||
* note: don't use sizeof() for 'name' or 'from_name' */
|
||||
@@ -478,7 +518,7 @@ void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_
|
||||
BLI_strncpy(prefix, name, sizeof(prefix));
|
||||
|
||||
/* first case; separator . - _ with extensions r R l L */
|
||||
if (BKE_deform_is_char_sep(name[len - 2])) {
|
||||
if (is_char_sep(name[len - 2])) {
|
||||
switch (name[len - 1]) {
|
||||
case 'l':
|
||||
prefix[len - 1] = 0;
|
||||
@@ -499,7 +539,7 @@ void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_
|
||||
}
|
||||
}
|
||||
/* case; beginning with r R l L , with separator after it */
|
||||
else if (BKE_deform_is_char_sep(name[1])) {
|
||||
else if (is_char_sep(name[1])) {
|
||||
switch (name[0]) {
|
||||
case 'l':
|
||||
strcpy(replace, "r");
|
||||
|
@@ -56,6 +56,7 @@
|
||||
#include "DNA_space_types.h"
|
||||
#include "DNA_view3d_types.h"
|
||||
#include "DNA_world_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_bpath.h"
|
||||
|
@@ -77,6 +77,7 @@
|
||||
#include "DNA_nla_types.h"
|
||||
#include "DNA_node_types.h"
|
||||
#include "DNA_object_fluidsim.h" // NT
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_packedFile_types.h"
|
||||
#include "DNA_particle_types.h"
|
||||
#include "DNA_property_types.h"
|
||||
|
@@ -42,6 +42,7 @@
|
||||
#include "DNA_armature_types.h"
|
||||
#include "DNA_constraint_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
@@ -4029,6 +4030,7 @@ void ARMATURE_OT_select_all(wmOperatorType *ot)
|
||||
|
||||
enum {
|
||||
SIMEDBONE_LENGTH = 1,
|
||||
SIMEDBONE_DIRECTION,
|
||||
SIMEDBONE_PREFIX,
|
||||
SIMEDBONE_SUFFIX,
|
||||
SIMEDBONE_LAYER
|
||||
@@ -4036,6 +4038,7 @@ enum {
|
||||
|
||||
static EnumPropertyItem prop_similar_types[] = {
|
||||
{SIMEDBONE_LENGTH, "LENGTH", 0, "Length", ""},
|
||||
{SIMEDBONE_DIRECTION, "DIRECTION", 0, "Direction (Y axis)", ""},
|
||||
{SIMEDBONE_PREFIX, "PREFIX", 0, "Prefix", ""},
|
||||
{SIMEDBONE_SUFFIX, "SUFFIX", 0, "Suffix", ""},
|
||||
{SIMEDBONE_LAYER, "LAYER", 0, "Layer", ""},
|
||||
@@ -4053,13 +4056,13 @@ static void ED_armature_edit_bone_select(EditBone *ebone)
|
||||
}
|
||||
}
|
||||
|
||||
static void select_similar_length(bArmature *arm, EditBone *actBone, const float thresh)
|
||||
static void select_similar_length(bArmature *arm, EditBone *ebone_act, const float thresh)
|
||||
{
|
||||
EditBone *ebone;
|
||||
|
||||
/* thresh is always relative to current length */
|
||||
const float len_min = actBone->length / (1.0f + thresh);
|
||||
const float len_max = actBone->length * (1.0f + thresh);
|
||||
const float len_min = ebone_act->length / (1.0f + thresh);
|
||||
const float len_max = ebone_act->length * (1.0f + thresh);
|
||||
|
||||
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
|
||||
if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_UNSELECTABLE) == 0) {
|
||||
@@ -4072,90 +4075,116 @@ static void select_similar_length(bArmature *arm, EditBone *actBone, const float
|
||||
}
|
||||
}
|
||||
|
||||
static void select_similar_layer(bArmature *arm, EditBone *actBone)
|
||||
static void select_similar_direction(bArmature *arm, EditBone *ebone_act, const float thresh)
|
||||
{
|
||||
EditBone *ebone;
|
||||
float dir_act[3];
|
||||
sub_v3_v3v3(dir_act, ebone_act->head, ebone_act->tail);
|
||||
|
||||
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
|
||||
if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_UNSELECTABLE) == 0) {
|
||||
if (ebone->layer & actBone->layer) {
|
||||
float dir[3];
|
||||
sub_v3_v3v3(dir, ebone->head, ebone->tail);
|
||||
|
||||
if (angle_v3v3(dir_act, dir) / M_PI < thresh) {
|
||||
ED_armature_edit_bone_select(ebone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void find_pre_or_suffix(char *outCompare, const char *name, int mode)
|
||||
static void select_similar_layer(bArmature *arm, EditBone *ebone_act)
|
||||
{
|
||||
int len = BLI_strnlen(name, MAX_VGROUP_NAME);
|
||||
EditBone *ebone;
|
||||
|
||||
if (len < 3)
|
||||
return;
|
||||
|
||||
if (mode == SIMEDBONE_SUFFIX) {
|
||||
if (BKE_deform_is_char_sep(name[len - 2])) {
|
||||
BLI_strncpy(outCompare, &name[len - 1], sizeof(outCompare));
|
||||
}
|
||||
}
|
||||
else if (mode == SIMEDBONE_PREFIX) {
|
||||
if (BKE_deform_is_char_sep(name[1])) {
|
||||
BLI_strncpy(outCompare, &name[0], sizeof(outCompare));
|
||||
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
|
||||
if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_UNSELECTABLE) == 0) {
|
||||
if (ebone->layer & ebone_act->layer) {
|
||||
ED_armature_edit_bone_select(ebone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void select_similar_name(bArmature *arm, EditBone *actBone, int mode)
|
||||
static void select_similar_prefix(bArmature *arm, EditBone *ebone_act)
|
||||
{
|
||||
EditBone *ebone;
|
||||
|
||||
char *name = actBone->name;
|
||||
char compare[MAX_VGROUP_NAME] = "";
|
||||
find_pre_or_suffix(compare, name, mode);
|
||||
char body_tmp[MAX_VGROUP_NAME];
|
||||
char prefix_act[MAX_VGROUP_NAME];
|
||||
|
||||
if (compare[0] == '\0')
|
||||
BKE_deform_split_prefix(ebone_act->name, prefix_act, body_tmp);
|
||||
|
||||
if (prefix_act[0] == '\0')
|
||||
return;
|
||||
|
||||
/* Find matches */
|
||||
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
|
||||
if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_UNSELECTABLE) == 0) {
|
||||
char tCompare[MAX_VGROUP_NAME] = "";
|
||||
find_pre_or_suffix(tCompare, ebone->name, mode);
|
||||
if (!strcmp(tCompare, compare)) {
|
||||
char prefix_other[MAX_VGROUP_NAME];
|
||||
BKE_deform_split_prefix(ebone->name, prefix_other, body_tmp);
|
||||
if (!strcmp(prefix_act, prefix_other)) {
|
||||
ED_armature_edit_bone_select(ebone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void select_similar_suffix(bArmature *arm, EditBone *ebone_act)
|
||||
{
|
||||
EditBone *ebone;
|
||||
|
||||
char body_tmp[MAX_VGROUP_NAME];
|
||||
char suffix_act[MAX_VGROUP_NAME];
|
||||
|
||||
BKE_deform_split_suffix(ebone_act->name, body_tmp, suffix_act);
|
||||
|
||||
if (suffix_act[0] == '\0')
|
||||
return;
|
||||
|
||||
/* Find matches */
|
||||
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
|
||||
if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_UNSELECTABLE) == 0) {
|
||||
char suffix_other[MAX_VGROUP_NAME];
|
||||
BKE_deform_split_suffix(ebone->name, body_tmp, suffix_other);
|
||||
if (!strcmp(suffix_act, suffix_other)) {
|
||||
ED_armature_edit_bone_select(ebone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int armature_select_similar_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *obedit = CTX_data_edit_object(C);
|
||||
bArmature *arm = obedit->data;
|
||||
EditBone *actBone = CTX_data_active_bone(C);
|
||||
EditBone *ebone_act = CTX_data_active_bone(C);
|
||||
|
||||
/* Get props */
|
||||
int type = RNA_enum_get(op->ptr, "type");
|
||||
float thresh = RNA_float_get(op->ptr, "threshold");
|
||||
|
||||
/* Check for active bone */
|
||||
if (actBone == NULL) {
|
||||
if (ebone_act == NULL) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Operation requires an Active Bone");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case SIMEDBONE_LENGTH:
|
||||
select_similar_length(arm, actBone, thresh);
|
||||
select_similar_length(arm, ebone_act, thresh);
|
||||
break;
|
||||
case SIMEDBONE_DIRECTION:
|
||||
select_similar_direction(arm, ebone_act, thresh);
|
||||
break;
|
||||
case SIMEDBONE_PREFIX:
|
||||
select_similar_name(arm, actBone, SIMEDBONE_PREFIX);
|
||||
select_similar_prefix(arm, ebone_act);
|
||||
break;
|
||||
case SIMEDBONE_SUFFIX:
|
||||
select_similar_name(arm, actBone, SIMEDBONE_SUFFIX);
|
||||
select_similar_suffix(arm, ebone_act);
|
||||
break;
|
||||
case SIMEDBONE_LAYER:
|
||||
select_similar_layer(arm, actBone);
|
||||
select_similar_layer(arm, ebone_act);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -47,6 +47,7 @@
|
||||
#include "DNA_speaker_types.h"
|
||||
#include "DNA_world_types.h"
|
||||
#include "DNA_armature_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_blenlib.h"
|
||||
|
@@ -47,7 +47,6 @@
|
||||
#include "BKE_curve.h"
|
||||
#include "BKE_constraint.h" // for the get_constraint_target function
|
||||
#include "BKE_DerivedMesh.h"
|
||||
#include "BKE_deform.h"
|
||||
#include "BKE_displist.h"
|
||||
#include "BKE_effect.h"
|
||||
#include "BKE_font.h"
|
||||
|
@@ -35,6 +35,7 @@
|
||||
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "BLI_kdtree.h"
|
||||
#include "BLI_rand.h"
|
||||
|
@@ -29,6 +29,9 @@
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_string.h"
|
||||
@@ -39,9 +42,6 @@
|
||||
#include "BKE_texture.h"
|
||||
#include "BKE_colortools.h"
|
||||
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
|
||||
#include "depsgraph_private.h"
|
||||
|
||||
#include "RE_shader_ext.h"
|
||||
|
@@ -34,6 +34,7 @@
|
||||
|
||||
#include "../mathutils/mathutils.h"
|
||||
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
Reference in New Issue
Block a user