diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-07-09 12:27:31 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-07-09 12:28:40 +0400 |
commit | 08eac0c3675ff4baff4ad3d0aae4d5ab10a8a133 (patch) | |
tree | 491addec2ce6b240d86a2e70aecf5dcb32a252f2 /source/blender/blenkernel | |
parent | 02eb03f8687c30f598147082857a3b1d5dd1f007 (diff) |
Add bone_groups.new() and bone_groups.remove() methods to RNA.
To do so, matching BKE 'API' was also refactored a bit:
* Get Pose data instead of Object, as parameter;
* Removed some sanity checks not needed at such a low level (callers are supposed to do that);
* You can now remove an arbitrary bone group, not only the active one.
Based on patch by pkrime (Paolo Acampora), with own edits.
Reviewers: #python, pkrime, aligorith
Reviewed By: aligorith
Differential Revision: https://developer.blender.org/D522
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_action.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/action.c | 76 |
2 files changed, 49 insertions, 35 deletions
diff --git a/source/blender/blenkernel/BKE_action.h b/source/blender/blenkernel/BKE_action.h index 517c0f7d58b..57ba6fd55ca 100644 --- a/source/blender/blenkernel/BKE_action.h +++ b/source/blender/blenkernel/BKE_action.h @@ -180,10 +180,12 @@ void framechange_poses_clear_unkeyed(void); /* Bone Groups API --------------------- */ /* Adds a new bone-group */ -void BKE_pose_add_group(struct Object *ob); +struct bActionGroup *BKE_pose_add_group(struct bPose *pose, const char *name); -/* Remove the active bone-group */ -void BKE_pose_remove_group(struct Object *ob); +/* Remove a bone-group */ +void BKE_pose_remove_group(struct bPose *pose, struct bActionGroup *grp, const int index); +/* Remove the matching bone-group from its index */ +void BKE_pose_remove_group_index(struct bPose *pose, const int index); /* Assorted Evaluation ----------------- */ diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 3219219bee5..8f1382dacc3 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -952,52 +952,52 @@ void framechange_poses_clear_unkeyed(void) /* ************************** Bone Groups ************************** */ -/* Adds a new bone-group */ -void BKE_pose_add_group(Object *ob) +/* Adds a new bone-group (name may be NULL) */ +bActionGroup *BKE_pose_add_group(bPose *pose, const char *name) { - bPose *pose = (ob) ? ob->pose : NULL; bActionGroup *grp; - if (ELEM(NULL, ob, ob->pose)) - return; + if (!name) { + name = DATA_("Group"); + } grp = MEM_callocN(sizeof(bActionGroup), "PoseGroup"); - BLI_strncpy(grp->name, DATA_("Group"), sizeof(grp->name)); + BLI_strncpy(grp->name, name, sizeof(grp->name)); BLI_addtail(&pose->agroups, grp); - BLI_uniquename(&pose->agroups, grp, DATA_("Group"), '.', offsetof(bActionGroup, name), sizeof(grp->name)); + BLI_uniquename(&pose->agroups, grp, name, '.', offsetof(bActionGroup, name), sizeof(grp->name)); pose->active_group = BLI_countlist(&pose->agroups); + + return grp; } -/* Remove the active bone-group */ -void BKE_pose_remove_group(Object *ob) +/* Remove the given bone-group (expects 'virtual' index (+1 one, used by active_group etc.)) + * index might be invalid ( < 1), in which case it will be find from grp. */ +void BKE_pose_remove_group(bPose *pose, bActionGroup *grp, const int index) { - bPose *pose = (ob) ? ob->pose : NULL; - bActionGroup *grp = NULL; bPoseChannel *pchan; + int idx = index; - /* sanity checks */ - if (ELEM(NULL, ob, pose)) - return; - if (pose->active_group <= 0) - return; + if (idx < 1) { + idx = BLI_findindex(&pose->agroups, grp) + 1; + } - /* get group to remove */ - grp = BLI_findlink(&pose->agroups, pose->active_group - 1); - if (grp) { - /* adjust group references (the trouble of using indices!): - * - firstly, make sure nothing references it - * - also, make sure that those after this item get corrected - */ - for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { - if (pchan->agrp_index == pose->active_group) - pchan->agrp_index = 0; - else if (pchan->agrp_index > pose->active_group) - pchan->agrp_index--; - } - - /* now, remove it from the pose */ - BLI_freelinkN(&pose->agroups, grp); + BLI_assert(idx > 0); + + /* adjust group references (the trouble of using indices!): + * - firstly, make sure nothing references it + * - also, make sure that those after this item get corrected + */ + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { + if (pchan->agrp_index == idx) + pchan->agrp_index = 0; + else if (pchan->agrp_index > idx) + pchan->agrp_index--; + } + + /* now, remove it from the pose */ + BLI_freelinkN(&pose->agroups, grp); + if (pose->active_group >= idx) { pose->active_group--; if (pose->active_group < 0 || BLI_listbase_is_empty(&pose->agroups)) { pose->active_group = 0; @@ -1005,6 +1005,18 @@ void BKE_pose_remove_group(Object *ob) } } +/* Remove the indexed bone-group (expects 'virtual' index (+1 one, used by active_group etc.)) */ +void BKE_pose_remove_group_index(bPose *pose, const int index) +{ + bActionGroup *grp = NULL; + + /* get group to remove */ + grp = BLI_findlink(&pose->agroups, index - 1); + if (grp) { + BKE_pose_remove_group(pose, grp, index); + } +} + /* ************** F-Curve Utilities for Actions ****************** */ /* Check if the given action has any keyframes */ |