code cleanup: armature functions

- added BKE_pose_channel_get_mirrored (matching editmode function ED_armature_bone_get_mirrored)
- editbone_name_exists -> ED_armature_bone_find_name
This commit is contained in:
Campbell Barton 2013-11-17 04:30:36 +11:00
parent e62cdbb474
commit 4fd66d7c0c
9 changed files with 44 additions and 27 deletions

View File

@ -146,6 +146,7 @@ void BKE_pose_channel_copy_data(struct bPoseChannel *pchan, cons
struct bPoseChannel *BKE_pose_channel_find_name(const struct bPose *pose, const char *name);
struct bPoseChannel *BKE_pose_channel_active(struct Object *ob);
struct bPoseChannel *BKE_pose_channel_verify(struct bPose *pose, const char *name);
struct bPoseChannel *BKE_pose_channel_get_mirrored(const struct bPose *pose, const char *name);
#ifndef NDEBUG
bool BKE_pose_channels_is_valid(const struct bPose *pose);

View File

@ -53,6 +53,7 @@
#include "BKE_anim.h"
#include "BKE_animsys.h"
#include "BKE_constraint.h"
#include "BKE_deform.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
@ -539,6 +540,22 @@ bPoseChannel *BKE_pose_channel_active(Object *ob)
return NULL;
}
/**
* \see #ED_armature_bone_get_mirrored (edit-mode, matching function)
*/
bPoseChannel *BKE_pose_channel_get_mirrored(const bPose *pose, const char *name)
{
char name_flip[MAXBONENAME];
BKE_deform_flip_side_name(name_flip, name, false);
if (!STREQ(name_flip, name)) {
return BKE_pose_channel_find_name(pose, name_flip);
}
return NULL;
}
const char *BKE_pose_ikparam_get_name(bPose *pose)
{
if (pose) {

View File

@ -1127,7 +1127,7 @@ static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op))
bPoseChannel *pchan, *pchan_next;
for (pchan = obedit->pose->chanbase.first; pchan; pchan = pchan_next) {
pchan_next = pchan->next;
curBone = editbone_name_exists(arm->edbo, pchan->name);
curBone = ED_armature_bone_find_name(arm->edbo, pchan->name);
if (curBone && (curBone->flag & BONE_SELECTED) && (arm->layer & curBone->layer)) {
BKE_pose_channel_free(pchan);
@ -1146,7 +1146,7 @@ static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op))
for (ct = targets.first; ct; ct = ct->next) {
if (ct->tar == obedit) {
if (ct->subtarget[0]) {
curBone = editbone_name_exists(arm->edbo, ct->subtarget);
curBone = ED_armature_bone_find_name(arm->edbo, ct->subtarget);
if (curBone && (curBone->flag & BONE_SELECTED) && (arm->layer & curBone->layer)) {
con->flag |= CONSTRAINT_DISABLE;
ct->subtarget[0] = 0;

View File

@ -229,9 +229,6 @@ struct EditBone *duplicateEditBoneObjects(struct EditBone *curBone, const char *
/* editbones is the source list */
void updateDuplicateSubtargetObjects(struct EditBone *dupBone, struct ListBase *editbones, struct Object *src_ob, struct Object *dst_ob);
EditBone *editbone_name_exists(struct ListBase *edbo, const char *name);
EditBone *add_points_bone(struct Object *obedit, float head[3], float tail[3]);
void bone_free(struct bArmature *arm, struct EditBone *bone);

View File

@ -67,17 +67,11 @@
/* ************************************************** */
/* EditBone Names */
/* checks if an EditBone with a matching name already, returning the matching bone if it exists */
EditBone *editbone_name_exists(ListBase *edbo, const char *name)
{
return BLI_findstring(edbo, name, offsetof(EditBone, name));
}
/* note: there's a unique_bone_name() too! */
static bool editbone_unique_check(void *arg, const char *name)
{
struct {ListBase *lb; void *bone; } *data = arg;
EditBone *dupli = editbone_name_exists(data->lb, name);
EditBone *dupli = ED_armature_bone_find_name(data->lb, name);
return dupli && dupli != data->bone;
}
@ -155,7 +149,7 @@ void ED_armature_bone_rename(bArmature *arm, const char *oldnamep, const char *n
/* now check if we're in editmode, we need to find the unique name */
if (arm->edbo) {
EditBone *eBone = editbone_name_exists(arm->edbo, oldname);
EditBone *eBone = ED_armature_bone_find_name(arm->edbo, oldname);
if (eBone) {
unique_editbone_name(arm->edbo, newname, NULL);

View File

@ -230,7 +230,7 @@ int join_armature_exec(bContext *C, wmOperator *op)
/* Copy bones and posechannels from the object to the edit armature */
for (pchan = opose->chanbase.first; pchan; pchan = pchann) {
pchann = pchan->next;
curbone = editbone_name_exists(curarm->edbo, pchan->name);
curbone = ED_armature_bone_find_name(curarm->edbo, pchan->name);
/* Get new name */
unique_editbone_name(arm->edbo, curbone->name, NULL);
@ -414,7 +414,7 @@ static void separate_armature_bones(Object *ob, short sel)
/* go through pose-channels, checking if a bone should be removed */
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchann) {
pchann = pchan->next;
curbone = editbone_name_exists(arm->edbo, pchan->name);
curbone = ED_armature_bone_find_name(arm->edbo, pchan->name);
/* check if bone needs to be removed */
if ( (sel && (curbone->flag & BONE_SELECTED)) ||

View File

@ -175,28 +175,35 @@ void ED_armature_ebone_to_mat4(EditBone *ebone, float mat[4][4])
copy_v3_v3(mat[3], ebone->head);
}
/**
* Return a pointer to the bone of the given name
*/
EditBone *ED_armature_bone_find_name(const ListBase *edbo, const char *name)
{
return BLI_findstring(edbo, name, offsetof(EditBone, name));
}
/* *************************************************************** */
/* Mirroring */
/* context: editmode armature */
EditBone *ED_armature_bone_get_mirrored(ListBase *edbo, EditBone *ebo)
/**
* \see #BKE_pose_channel_get_mirrored (pose-mode, matching function)
*/
EditBone *ED_armature_bone_get_mirrored(const ListBase *edbo, EditBone *ebo)
{
EditBone *eboflip = NULL;
char name_flip[MAXBONENAME];
if (ebo == NULL)
return NULL;
BKE_deform_flip_side_name(name_flip, ebo->name, false);
for (eboflip = edbo->first; eboflip; eboflip = eboflip->next) {
if (ebo != eboflip) {
if (!strcmp(name_flip, eboflip->name))
break;
}
if (!STREQ(name_flip, ebo->name)) {
return ED_armature_bone_find_name(edbo, name_flip);
}
return eboflip;
return NULL;
}
/* ------------------------------------- */

View File

@ -118,7 +118,7 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op)
pose = ob->pose;
for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
curbone = editbone_name_exists(arm->edbo, pchan->name);
curbone = ED_armature_bone_find_name(arm->edbo, pchan->name);
/* simply copy the head/tail values from pchan over to curbone */
copy_v3_v3(curbone->head, pchan->pose_head);

View File

@ -128,7 +128,8 @@ bool mouse_armature(struct bContext *C, const int mval[2], bool extend, bool des
int join_armature_exec(struct bContext *C, struct wmOperator *op);
struct Bone *get_indexed_bone(struct Object *ob, int index);
float ED_rollBoneToVector(EditBone *bone, const float new_up_axis[3], const short axis_only);
EditBone *ED_armature_bone_get_mirrored(struct ListBase *edbo, EditBone *ebo); // XXX this is needed for populating the context iterators
EditBone *ED_armature_bone_find_name(const ListBase *edbo, const char *name);
EditBone *ED_armature_bone_get_mirrored(const struct ListBase *edbo, EditBone *ebo);
void ED_armature_sync_selection(struct ListBase *edbo);
void ED_armature_validate_active(struct bArmature *arm);