Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/action.c
| Show First 20 Lines • Show All 946 Lines • ▼ Show 20 Lines | if ((pose = ob->pose)) { | ||||
| pchan->bone->flag &= ~BONE_UNKEYED; | pchan->bone->flag &= ~BONE_UNKEYED; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* ************************** Bone Groups ************************** */ | /* ************************** Bone Groups ************************** */ | ||||
| /* Adds a new bone-group */ | /* Adds a new bone-group (name may be NULL) */ | ||||
| void BKE_pose_add_group(Object *ob) | bActionGroup *BKE_pose_add_group(bPose *pose, const char *name) | ||||
| { | { | ||||
| bPose *pose = (ob) ? ob->pose : NULL; | |||||
| bActionGroup *grp; | bActionGroup *grp; | ||||
| if (ELEM(NULL, ob, ob->pose)) | if (!name) { | ||||
| return; | name = DATA_("Group"); | ||||
| } | |||||
| grp = MEM_callocN(sizeof(bActionGroup), "PoseGroup"); | 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_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); | pose->active_group = BLI_countlist(&pose->agroups); | ||||
| return grp; | |||||
| } | } | ||||
| /* Remove the active bone-group */ | /* Remove the given bone-group (expects 'virtual' index (+1 one, used by active_group etc.)) */ | ||||
| void BKE_pose_remove_group(Object *ob) | void BKE_pose_remove_group(bPose *pose, bActionGroup *grp, const int index) | ||||
| { | { | ||||
| bPose *pose = (ob) ? ob->pose : NULL; | |||||
| bActionGroup *grp = NULL; | |||||
| bPoseChannel *pchan; | bPoseChannel *pchan; | ||||
| /* sanity checks */ | |||||
| if (ELEM(NULL, ob, pose)) | |||||
| return; | |||||
| if (pose->active_group <= 0) | |||||
| return; | |||||
| /* get group to remove */ | |||||
| grp = BLI_findlink(&pose->agroups, pose->active_group - 1); | |||||
| if (grp) { | |||||
| /* adjust group references (the trouble of using indices!): | /* adjust group references (the trouble of using indices!): | ||||
| * - firstly, make sure nothing references it | * - firstly, make sure nothing references it | ||||
| * - also, make sure that those after this item get corrected | * - also, make sure that those after this item get corrected | ||||
| */ | */ | ||||
| for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { | for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { | ||||
| if (pchan->agrp_index == pose->active_group) | if (pchan->agrp_index == index) | ||||
| pchan->agrp_index = 0; | pchan->agrp_index = 0; | ||||
| else if (pchan->agrp_index > pose->active_group) | else if (pchan->agrp_index > index) | ||||
| pchan->agrp_index--; | pchan->agrp_index--; | ||||
| } | } | ||||
| /* now, remove it from the pose */ | /* now, remove it from the pose */ | ||||
| BLI_freelinkN(&pose->agroups, grp); | BLI_freelinkN(&pose->agroups, grp); | ||||
| if (pose->active_group >= index) { | |||||
| pose->active_group--; | pose->active_group--; | ||||
| if (pose->active_group < 0 || BLI_listbase_is_empty(&pose->agroups)) { | if (pose->active_group < 0 || BLI_listbase_is_empty(&pose->agroups)) { | ||||
| pose->active_group = 0; | pose->active_group = 0; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* 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 ****************** */ | /* ************** F-Curve Utilities for Actions ****************** */ | ||||
| /* Check if the given action has any keyframes */ | /* Check if the given action has any keyframes */ | ||||
| bool action_has_motion(const bAction *act) | bool action_has_motion(const bAction *act) | ||||
| { | { | ||||
| FCurve *fcu; | FCurve *fcu; | ||||
| /* return on the first F-Curve that has some keyframes/samples defined */ | /* return on the first F-Curve that has some keyframes/samples defined */ | ||||
| ▲ Show 20 Lines • Show All 337 Lines • Show Last 20 Lines | |||||