Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_convert.c
| Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
| #include "DNA_gpencil_types.h" | #include "DNA_gpencil_types.h" | ||||
| #include "DNA_node_types.h" | #include "DNA_node_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "DNA_space_types.h" | #include "DNA_space_types.h" | ||||
| #include "DNA_view3d_types.h" | #include "DNA_view3d_types.h" | ||||
| #include "BKE_animsys.h" | |||||
| #include "BKE_collection.h" | #include "BKE_collection.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_fcurve.h" | #include "BKE_fcurve.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| ▲ Show 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | static void gp_stroke_path_animation_preprocess_gaps(tGpTimingData *gtd, | ||||
| if (gtd->gap_randomness > 0.0f) { | if (gtd->gap_randomness > 0.0f) { | ||||
| BLI_rng_srandom(rng, gtd->seed); | BLI_rng_srandom(rng, gtd->seed); | ||||
| } | } | ||||
| } | } | ||||
| static void gp_stroke_path_animation_add_keyframes(ReportList *reports, | static void gp_stroke_path_animation_add_keyframes(ReportList *reports, | ||||
| PointerRNA ptr, | PointerRNA ptr, | ||||
| PropertyRNA *prop, | PropertyRNA *prop, | ||||
| Depsgraph *depsgraph, | |||||
| FCurve *fcu, | FCurve *fcu, | ||||
| Curve *cu, | Curve *cu, | ||||
| tGpTimingData *gtd, | tGpTimingData *gtd, | ||||
| RNG *rng, | RNG *rng, | ||||
| const float time_range, | const float time_range, | ||||
| const int nbr_gaps, | const int nbr_gaps, | ||||
| const float tot_gaps_time) | const float tot_gaps_time) | ||||
| { | { | ||||
| Show All 38 Lines | if (i == start_stroke_idx) { | ||||
| * that the end point of the stroke is far enough! | * that the end point of the stroke is far enough! | ||||
| * In case it is not, we keep the end point... | * In case it is not, we keep the end point... | ||||
| * Note that with CustomGaps mode, this is here we set the actual gap timing! | * Note that with CustomGaps mode, this is here we set the actual gap timing! | ||||
| */ | */ | ||||
| if ((end_stroke_time - last_valid_time) > MIN_TIME_DELTA * 2) { | if ((end_stroke_time - last_valid_time) > MIN_TIME_DELTA * 2) { | ||||
| if ((cfra - last_valid_time) < MIN_TIME_DELTA) { | if ((cfra - last_valid_time) < MIN_TIME_DELTA) { | ||||
| cfra = last_valid_time + MIN_TIME_DELTA; | cfra = last_valid_time + MIN_TIME_DELTA; | ||||
| } | } | ||||
| insert_keyframe_direct( | const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context(depsgraph, cfra); | ||||
| reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); | insert_keyframe_direct(reports, | ||||
| ptr, | |||||
| prop, | |||||
| fcu, | |||||
| &anim_eval_context, | |||||
| BEZT_KEYTYPE_KEYFRAME, | |||||
| NULL, | |||||
| INSERTKEY_FAST); | |||||
| last_valid_time = cfra; | last_valid_time = cfra; | ||||
| } | } | ||||
| else if (G.debug & G_DEBUG) { | else if (G.debug & G_DEBUG) { | ||||
| printf("\t Skipping start point %d, too close from end point %d\n", i, end_stroke_idx); | printf("\t Skipping start point %d, too close from end point %d\n", i, end_stroke_idx); | ||||
| } | } | ||||
| } | } | ||||
| else if (i == end_stroke_idx) { | else if (i == end_stroke_idx) { | ||||
| /* Always try to insert end point of a curve (should be safe enough, anyway...) */ | /* Always try to insert end point of a curve (should be safe enough, anyway...) */ | ||||
| if ((cfra - last_valid_time) < MIN_TIME_DELTA) { | if ((cfra - last_valid_time) < MIN_TIME_DELTA) { | ||||
| cfra = last_valid_time + MIN_TIME_DELTA; | cfra = last_valid_time + MIN_TIME_DELTA; | ||||
| } | } | ||||
| insert_keyframe_direct( | const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context(depsgraph, cfra); | ||||
| reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); | insert_keyframe_direct(reports, | ||||
| ptr, | |||||
| prop, | |||||
| fcu, | |||||
| &anim_eval_context, | |||||
| BEZT_KEYTYPE_KEYFRAME, | |||||
| NULL, | |||||
| INSERTKEY_FAST); | |||||
| last_valid_time = cfra; | last_valid_time = cfra; | ||||
| } | } | ||||
| else { | else { | ||||
| /* Else ("middle" point), we only insert it if it's far enough from last keyframe, | /* Else ("middle" point), we only insert it if it's far enough from last keyframe, | ||||
| * and also far enough from (not yet added!) end_stroke keyframe! | * and also far enough from (not yet added!) end_stroke keyframe! | ||||
| */ | */ | ||||
| if ((cfra - last_valid_time) > MIN_TIME_DELTA && (end_stroke_time - cfra) > MIN_TIME_DELTA) { | if ((cfra - last_valid_time) > MIN_TIME_DELTA && (end_stroke_time - cfra) > MIN_TIME_DELTA) { | ||||
| insert_keyframe_direct( | const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context(depsgraph, cfra); | ||||
| reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_BREAKDOWN, NULL, INSERTKEY_FAST); | insert_keyframe_direct(reports, | ||||
| ptr, | |||||
| prop, | |||||
| fcu, | |||||
| &anim_eval_context, | |||||
| BEZT_KEYTYPE_BREAKDOWN, | |||||
| NULL, | |||||
| INSERTKEY_FAST); | |||||
| last_valid_time = cfra; | last_valid_time = cfra; | ||||
| } | } | ||||
| else if (G.debug & G_DEBUG) { | else if (G.debug & G_DEBUG) { | ||||
| printf( | printf( | ||||
| "\t Skipping \"middle\" point %d, too close from last added point or end point %d\n", | "\t Skipping \"middle\" point %d, too close from last added point or end point %d\n", | ||||
| i, | i, | ||||
| end_stroke_idx); | end_stroke_idx); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void gp_stroke_path_animation(bContext *C, | static void gp_stroke_path_animation(bContext *C, | ||||
| ReportList *reports, | ReportList *reports, | ||||
| Curve *cu, | Curve *cu, | ||||
| tGpTimingData *gtd) | tGpTimingData *gtd) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| bAction *act; | bAction *act; | ||||
| FCurve *fcu; | FCurve *fcu; | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop = NULL; | PropertyRNA *prop = NULL; | ||||
| int nbr_gaps = 0, i; | int nbr_gaps = 0, i; | ||||
| if (gtd->mode == GP_STROKECONVERT_TIMING_NONE) { | if (gtd->mode == GP_STROKECONVERT_TIMING_NONE) { | ||||
| return; | return; | ||||
| Show All 25 Lines | static void gp_stroke_path_animation(bContext *C, | ||||
| if (gtd->mode == GP_STROKECONVERT_TIMING_LINEAR) { | if (gtd->mode == GP_STROKECONVERT_TIMING_LINEAR) { | ||||
| float cfra; | float cfra; | ||||
| /* Linear extrapolation! */ | /* Linear extrapolation! */ | ||||
| fcu->extend = FCURVE_EXTRAPOLATE_LINEAR; | fcu->extend = FCURVE_EXTRAPOLATE_LINEAR; | ||||
| cu->ctime = 0.0f; | cu->ctime = 0.0f; | ||||
| cfra = (float)gtd->start_frame; | cfra = (float)gtd->start_frame; | ||||
| insert_keyframe_direct( | AnimationEvalContext anim_eval_context_start = BKE_animsys_eval_context(depsgraph, cfra); | ||||
| reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); | insert_keyframe_direct(reports, | ||||
| ptr, | |||||
| prop, | |||||
| fcu, | |||||
| &anim_eval_context_start, | |||||
| BEZT_KEYTYPE_KEYFRAME, | |||||
| NULL, | |||||
| INSERTKEY_FAST); | |||||
| cu->ctime = cu->pathlen; | cu->ctime = cu->pathlen; | ||||
| if (gtd->realtime) { | if (gtd->realtime) { | ||||
| cfra += (float)TIME2FRA(gtd->tot_time); /* Seconds to frames */ | cfra += (float)TIME2FRA(gtd->tot_time); /* Seconds to frames */ | ||||
| } | } | ||||
| else { | else { | ||||
| cfra = (float)gtd->end_frame; | cfra = (float)gtd->end_frame; | ||||
| } | } | ||||
| insert_keyframe_direct( | AnimationEvalContext anim_eval_context_end = BKE_animsys_eval_context(depsgraph, cfra); | ||||
| reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); | insert_keyframe_direct(reports, | ||||
| ptr, | |||||
| prop, | |||||
| fcu, | |||||
| &anim_eval_context_end, | |||||
| BEZT_KEYTYPE_KEYFRAME, | |||||
| NULL, | |||||
| INSERTKEY_FAST); | |||||
| } | } | ||||
| else { | else { | ||||
| /* Use actual recorded timing! */ | /* Use actual recorded timing! */ | ||||
| RNG *rng = BLI_rng_new(0); | RNG *rng = BLI_rng_new(0); | ||||
| float time_range; | float time_range; | ||||
| /* CustomGaps specific */ | /* CustomGaps specific */ | ||||
| float tot_gaps_time = 0.0f; | float tot_gaps_time = 0.0f; | ||||
| Show All 10 Lines | else { | ||||
| time_range = (float)(gtd->end_frame - gtd->start_frame); | time_range = (float)(gtd->end_frame - gtd->start_frame); | ||||
| } | } | ||||
| if (G.debug & G_DEBUG) { | if (G.debug & G_DEBUG) { | ||||
| printf("GP Stroke Path Conversion: Starting keying!\n"); | printf("GP Stroke Path Conversion: Starting keying!\n"); | ||||
| } | } | ||||
| gp_stroke_path_animation_add_keyframes( | gp_stroke_path_animation_add_keyframes( | ||||
| reports, ptr, prop, fcu, cu, gtd, rng, time_range, nbr_gaps, tot_gaps_time); | reports, ptr, prop, depsgraph, fcu, cu, gtd, rng, time_range, nbr_gaps, tot_gaps_time); | ||||
| BLI_rng_free(rng); | BLI_rng_free(rng); | ||||
| } | } | ||||
| /* As we used INSERTKEY_FAST mode, we need to recompute all curve's handles now */ | /* As we used INSERTKEY_FAST mode, we need to recompute all curve's handles now */ | ||||
| calchandles_fcurve(fcu); | calchandles_fcurve(fcu); | ||||
| if (G.debug & G_DEBUG) { | if (G.debug & G_DEBUG) { | ||||
| ▲ Show 20 Lines • Show All 1,274 Lines • Show Last 20 Lines | |||||