Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/fcurve.c
| Show First 20 Lines • Show All 1,140 Lines • ▼ Show 20 Lines | for (fpt--; keyframes_to_insert; cur_pos++, bezt++, keyframes_to_insert--) { | ||||
| init_unbaked_bezt_data(bezt); | init_unbaked_bezt_data(bezt); | ||||
| bezt->vec[1][0] = (float)cur_pos; | bezt->vec[1][0] = (float)cur_pos; | ||||
| bezt->vec[1][1] = fpt->vec[1]; | bezt->vec[1][1] = fpt->vec[1]; | ||||
| } | } | ||||
| MEM_SAFE_FREE(fcu->fpt); | MEM_SAFE_FREE(fcu->fpt); | ||||
| /* Not strictly needed since we use linear interpolation, but better be consistent here. */ | /* Not strictly needed since we use linear interpolation, but better be consistent here. */ | ||||
| calchandles_fcurve(fcu); | BKE_fcurve_handles_recalc(fcu); | ||||
| } | } | ||||
| /* ***************************** F-Curve Sanity ********************************* */ | /* ***************************** F-Curve Sanity ********************************* */ | ||||
| /* The functions here are used in various parts of Blender, usually after some editing | /* The functions here are used in various parts of Blender, usually after some editing | ||||
| * of keyframe data has occurred. They ensure that keyframe data is properly ordered and | * of keyframe data has occurred. They ensure that keyframe data is properly ordered and | ||||
| * that the handles are correct. | * that the handles are correct. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | static BezTriple *cycle_offset_triple( | ||||
| for (int i = 0; i < 3; i++) { | for (int i = 0; i < 3; i++) { | ||||
| add_v3_v3(out->vec[i], delta); | add_v3_v3(out->vec[i], delta); | ||||
| } | } | ||||
| return out; | return out; | ||||
| } | } | ||||
| void calchandles_fcurve_ex(FCurve *fcu, eBezTriple_Flag handle_sel_flag) | void BKE_fcurve_handles_recalc_ex(FCurve *fcu, eBezTriple_Flag handle_sel_flag) | ||||
| { | { | ||||
| BezTriple *bezt, *prev, *next; | BezTriple *bezt, *prev, *next; | ||||
| int a = fcu->totvert; | int a = fcu->totvert; | ||||
| /* Error checking: | /* Error checking: | ||||
| * - Need at least two points. | * - Need at least two points. | ||||
| * - Need bezier keys. | * - Need bezier keys. | ||||
| * - Only bezier-interpolation has handles (for now). | * - Only bezier-interpolation has handles (for now). | ||||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | void BKE_fcurve_handles_recalc_ex(FCurve *fcu, eBezTriple_Flag handle_sel_flag) | ||||
| } | } | ||||
| /* Do a second pass for auto handle: compute the handle to have 0 acceleration step. */ | /* Do a second pass for auto handle: compute the handle to have 0 acceleration step. */ | ||||
| if (fcu->auto_smoothing != FCURVE_SMOOTH_NONE) { | if (fcu->auto_smoothing != FCURVE_SMOOTH_NONE) { | ||||
| BKE_nurb_handle_smooth_fcurve(fcu->bezt, fcu->totvert, cycle); | BKE_nurb_handle_smooth_fcurve(fcu->bezt, fcu->totvert, cycle); | ||||
| } | } | ||||
| } | } | ||||
| void calchandles_fcurve(FCurve *fcu) | void BKE_fcurve_handles_recalc(FCurve *fcu) | ||||
| { | { | ||||
| calchandles_fcurve_ex(fcu, SELECT); | BKE_fcurve_handles_recalc_ex(fcu, SELECT); | ||||
| } | } | ||||
| void testhandles_fcurve(FCurve *fcu, eBezTriple_Flag sel_flag, const bool use_handle) | void testhandles_fcurve(FCurve *fcu, eBezTriple_Flag sel_flag, const bool use_handle) | ||||
| { | { | ||||
| BezTriple *bezt; | BezTriple *bezt; | ||||
| unsigned int a; | unsigned int a; | ||||
| /* Only beztriples have handles (bpoints don't though). */ | /* Only beztriples have handles (bpoints don't though). */ | ||||
| if (ELEM(NULL, fcu, fcu->bezt)) { | if (ELEM(NULL, fcu, fcu->bezt)) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Loop over beztriples. */ | /* Loop over beztriples. */ | ||||
| for (a = 0, bezt = fcu->bezt; a < fcu->totvert; a++, bezt++) { | for (a = 0, bezt = fcu->bezt; a < fcu->totvert; a++, bezt++) { | ||||
| BKE_nurb_bezt_handle_test(bezt, sel_flag, use_handle, false); | BKE_nurb_bezt_handle_test(bezt, sel_flag, use_handle, false); | ||||
| } | } | ||||
| /* Recalculate handles. */ | /* Recalculate handles. */ | ||||
| calchandles_fcurve_ex(fcu, sel_flag); | BKE_fcurve_handles_recalc_ex(fcu, sel_flag); | ||||
| } | } | ||||
| void sort_time_fcurve(FCurve *fcu) | void sort_time_fcurve(FCurve *fcu) | ||||
| { | { | ||||
| if (fcu->bezt == NULL) { | if (fcu->bezt == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | static void berekeny(float f1, float f2, float f3, float f4, float *o, int b) | ||||
| c3 = f4 - f1 + 3.0f * (f2 - f3); | c3 = f4 - f1 + 3.0f * (f2 - f3); | ||||
| for (a = 0; a < b; a++) { | for (a = 0; a < b; a++) { | ||||
| t = o[a]; | t = o[a]; | ||||
| o[a] = c0 + t * c1 + t * t * c2 + t * t * t * c3; | o[a] = c0 + t * c1 + t * t * c2 + t * t * t * c3; | ||||
| } | } | ||||
| } | } | ||||
| static void fcurve_bezt_free(FCurve *fcu) | |||||
| { | |||||
| MEM_SAFE_FREE(fcu->bezt); | |||||
| fcu->totvert = 0; | |||||
| } | |||||
| bool BKE_fcurve_bezt_subdivide_handles(struct BezTriple *bezt, | bool BKE_fcurve_bezt_subdivide_handles(struct BezTriple *bezt, | ||||
| struct BezTriple *prev, | struct BezTriple *prev, | ||||
| struct BezTriple *next, | struct BezTriple *next, | ||||
| float *r_pdelta) | float *r_pdelta) | ||||
| { | { | ||||
| /* The four points that make up this section of the Bezier curve. */ | /* The four points that make up this section of the Bezier curve. */ | ||||
| const float *prev_coords = prev->vec[1]; | const float *prev_coords = prev->vec[1]; | ||||
| float *prev_handle_right = prev->vec[2]; | float *prev_handle_right = prev->vec[2]; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | bool BKE_fcurve_bezt_subdivide_handles(struct BezTriple *bezt, | ||||
| sub_v2_v2v2(diff_coords, new_coords, split3); | sub_v2_v2v2(diff_coords, new_coords, split3); | ||||
| add_v2_v2v2(new_handle_left, split2[0], diff_coords); | add_v2_v2v2(new_handle_left, split2[0], diff_coords); | ||||
| add_v2_v2v2(new_handle_right, split2[1], diff_coords); | add_v2_v2v2(new_handle_right, split2[1], diff_coords); | ||||
| *r_pdelta = diff_coords[1]; | *r_pdelta = diff_coords[1]; | ||||
| return true; | return true; | ||||
| } | } | ||||
| void BKE_fcurve_delete_key(FCurve *fcu, int index) | |||||
| { | |||||
| /* sanity check */ | |||||
| if (fcu == NULL) { | |||||
| return; | |||||
| } | |||||
| /* verify the index: | |||||
| * 1) cannot be greater than the number of available keyframes | |||||
| * 2) negative indices are for specifying a value from the end of the array | |||||
| */ | |||||
| if (abs(index) >= fcu->totvert) { | |||||
| return; | |||||
| } | |||||
| if (index < 0) { | |||||
| index += fcu->totvert; | |||||
| } | |||||
| /* Delete this keyframe */ | |||||
| memmove( | |||||
| &fcu->bezt[index], &fcu->bezt[index + 1], sizeof(BezTriple) * (fcu->totvert - index - 1)); | |||||
| fcu->totvert--; | |||||
| /* Free the array of BezTriples if there are not keyframes */ | |||||
| if (fcu->totvert == 0) { | |||||
| fcurve_bezt_free(fcu); | |||||
| } | |||||
| } | |||||
| bool BKE_fcurve_delete_keys_selected(FCurve *fcu) | |||||
| { | |||||
| bool changed = false; | |||||
| if (fcu->bezt == NULL) { /* ignore baked curves */ | |||||
| return false; | |||||
| } | |||||
| /* Delete selected BezTriples */ | |||||
| for (int i = 0; i < fcu->totvert; i++) { | |||||
| if (fcu->bezt[i].f2 & SELECT) { | |||||
| if (i == fcu->active_keyframe_index) { | |||||
| BKE_fcurve_active_keyframe_set(fcu, NULL); | |||||
| } | |||||
| memmove(&fcu->bezt[i], &fcu->bezt[i + 1], sizeof(BezTriple) * (fcu->totvert - i - 1)); | |||||
| fcu->totvert--; | |||||
| i--; | |||||
| changed = true; | |||||
| } | |||||
| } | |||||
| /* Free the array of BezTriples if there are not keyframes */ | |||||
| if (fcu->totvert == 0) { | |||||
| fcurve_bezt_free(fcu); | |||||
| } | |||||
| return changed; | |||||
| } | |||||
| void BKE_fcurve_delete_keys_all(FCurve *fcu) | |||||
| { | |||||
| fcurve_bezt_free(fcu); | |||||
| } | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name F-Curve Evaluation | /** \name F-Curve Evaluation | ||||
| * \{ */ | * \{ */ | ||||
| static float fcurve_eval_keyframes_extrapolate( | static float fcurve_eval_keyframes_extrapolate( | ||||
| FCurve *fcu, BezTriple *bezts, float evaltime, int endpoint_offset, int direction_to_neighbor) | FCurve *fcu, BezTriple *bezts, float evaltime, int endpoint_offset, int direction_to_neighbor) | ||||
| ▲ Show 20 Lines • Show All 758 Lines • Show Last 20 Lines | |||||