Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/armature/pose_lib.c
| Show First 20 Lines • Show All 1,026 Lines • ▼ Show 20 Lines | |||||
| /* ---------------------------- */ | /* ---------------------------- */ | ||||
| /* Applies the appropriate stored pose from the pose-library to the current pose | /* Applies the appropriate stored pose from the pose-library to the current pose | ||||
| * - assumes that a valid object, with a poselib has been supplied | * - assumes that a valid object, with a poselib has been supplied | ||||
| * - gets the string to print in the header | * - gets the string to print in the header | ||||
| * - this code is based on the code for extract_pose_from_action in blenkernel/action.c | * - this code is based on the code for extract_pose_from_action in blenkernel/action.c | ||||
| */ | */ | ||||
| static void poselib_apply_pose(tPoseLib_PreviewData *pld) | static void poselib_apply_pose(tPoseLib_PreviewData *pld, | ||||
| const AnimationEvalContext *anim_eval_context) | |||||
| { | { | ||||
| PointerRNA *ptr = &pld->rna_ptr; | PointerRNA *ptr = &pld->rna_ptr; | ||||
| bArmature *arm = pld->arm; | bArmature *arm = pld->arm; | ||||
| bPose *pose = pld->pose; | bPose *pose = pld->pose; | ||||
| bPoseChannel *pchan; | bPoseChannel *pchan; | ||||
| bAction *act = pld->act; | bAction *act = pld->act; | ||||
| bActionGroup *agrp; | bActionGroup *agrp; | ||||
| Show All 9 Lines | static void poselib_apply_pose(tPoseLib_PreviewData *pld, | ||||
| else { | else { | ||||
| return; | return; | ||||
| } | } | ||||
| /* init settings for testing groups for keyframes */ | /* init settings for testing groups for keyframes */ | ||||
| group_ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE); | group_ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE); | ||||
| ked.f1 = ((float)frame) - 0.5f; | ked.f1 = ((float)frame) - 0.5f; | ||||
| ked.f2 = ((float)frame) + 0.5f; | ked.f2 = ((float)frame) + 0.5f; | ||||
| AnimationEvalContext anim_context_at_frame = BKE_animsys_eval_context_at(anim_eval_context, | |||||
| frame); | |||||
| /* start applying - only those channels which have a key at this point in time! */ | /* start applying - only those channels which have a key at this point in time! */ | ||||
| for (agrp = act->groups.first; agrp; agrp = agrp->next) { | for (agrp = act->groups.first; agrp; agrp = agrp->next) { | ||||
| /* check if group has any keyframes */ | /* check if group has any keyframes */ | ||||
| if (ANIM_animchanneldata_keyframes_loop( | if (ANIM_animchanneldata_keyframes_loop( | ||||
| &ked, NULL, agrp, ALE_GROUP, NULL, group_ok_cb, NULL)) { | &ked, NULL, agrp, ALE_GROUP, NULL, group_ok_cb, NULL)) { | ||||
| /* has keyframe on this frame, so try to get a PoseChannel with this name */ | /* has keyframe on this frame, so try to get a PoseChannel with this name */ | ||||
| pchan = BKE_pose_channel_find_name(pose, agrp->name); | pchan = BKE_pose_channel_find_name(pose, agrp->name); | ||||
| Show All 10 Lines | if (ANIM_animchanneldata_keyframes_loop( | ||||
| /* only ok if bone is visible and selected */ | /* only ok if bone is visible and selected */ | ||||
| if ((pchan->bone->flag & BONE_SELECTED) && (pchan->bone->flag & BONE_HIDDEN_P) == 0 && | if ((pchan->bone->flag & BONE_SELECTED) && (pchan->bone->flag & BONE_HIDDEN_P) == 0 && | ||||
| (pchan->bone->layer & arm->layer)) { | (pchan->bone->layer & arm->layer)) { | ||||
| ok = 1; | ok = 1; | ||||
| } | } | ||||
| } | } | ||||
| if (ok) { | if (ok) { | ||||
| animsys_evaluate_action_group(ptr, act, agrp, (float)frame); | animsys_evaluate_action_group(ptr, act, agrp, &anim_context_at_frame); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Auto-keys/tags bones affected by the pose used from the poselib */ | /* Auto-keys/tags bones affected by the pose used from the poselib */ | ||||
| static void poselib_keytag_pose(bContext *C, Scene *scene, tPoseLib_PreviewData *pld) | static void poselib_keytag_pose(bContext *C, Scene *scene, tPoseLib_PreviewData *pld) | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if (pld->redraw == PL_PREVIEW_REDRAWALL) { | ||||
| } | } | ||||
| else { | else { | ||||
| pld->flag &= ~PL_PREVIEW_FIRSTTIME; | pld->flag &= ~PL_PREVIEW_FIRSTTIME; | ||||
| } | } | ||||
| /* pose should be the right one to draw (unless we're temporarily not showing it) */ | /* pose should be the right one to draw (unless we're temporarily not showing it) */ | ||||
| if ((pld->flag & PL_PREVIEW_SHOWORIGINAL) == 0) { | if ((pld->flag & PL_PREVIEW_SHOWORIGINAL) == 0) { | ||||
| RNA_int_set(op->ptr, "pose_index", BLI_findindex(&pld->act->markers, pld->marker)); | RNA_int_set(op->ptr, "pose_index", BLI_findindex(&pld->act->markers, pld->marker)); | ||||
| poselib_apply_pose(pld); | struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | ||||
| const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context( | |||||
| depsgraph, 0.0f /* poselib_apply_pose() determines its own evaluation time. */); | |||||
| poselib_apply_pose(pld, &anim_eval_context); | |||||
| } | } | ||||
| else { | else { | ||||
| RNA_int_set(op->ptr, "pose_index", -2); /* -2 means don't apply any pose */ | RNA_int_set(op->ptr, "pose_index", -2); /* -2 means don't apply any pose */ | ||||
| } | } | ||||
| DEG_id_tag_update(&pld->ob->id, ID_RECALC_GEOMETRY); | DEG_id_tag_update(&pld->ob->id, ID_RECALC_GEOMETRY); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 746 Lines • Show Last 20 Lines | |||||