Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/armature/pose_edit.c
| Show First 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | static bool pose_has_protected_selected(Object *ob, short warn) | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* ********************************************** */ | /* ********************************************** */ | ||||
| /* Motion Paths */ | /* Motion Paths */ | ||||
| static eAnimvizCalcRange pose_path_convert_range(ePosePathCalcRange range) | |||||
| { | |||||
| switch (range) { | |||||
| case POSE_PATH_CALC_RANGE_CURRENT_FRAME: | |||||
| return ANIMVIZ_CALC_RANGE_CURRENT_FRAME; | |||||
| case POSE_PATH_CALC_RANGE_CHANGED: | |||||
| return ANIMVIZ_CALC_RANGE_CHANGED; | |||||
| case POSE_PATH_CALC_RANGE_FULL: | |||||
| return ANIMVIZ_CALC_RANGE_FULL; | |||||
| } | |||||
| return ANIMVIZ_CALC_RANGE_FULL; | |||||
| } | |||||
| /* For the object with pose/action: update paths for those that have got them | /* For the object with pose/action: update paths for those that have got them | ||||
| * This should selectively update paths that exist... | * This should selectively update paths that exist... | ||||
| * | * | ||||
| * To be called from various tools that do incremental updates | * To be called from various tools that do incremental updates | ||||
| */ | */ | ||||
| void ED_pose_recalculate_paths(bContext *C, Scene *scene, Object *ob, bool current_frame_only) | void ED_pose_recalculate_paths(bContext *C, Scene *scene, Object *ob, ePosePathCalcRange range) | ||||
| { | { | ||||
| /* Transform doesn't always have context available to do update. */ | /* Transform doesn't always have context available to do update. */ | ||||
| if (C == NULL) { | if (C == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| /* NOTE: Dependency graph will be evaluated at all the frames, but we first need to access some | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| * nested pointers, like animation data. */ | |||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | Depsgraph *depsgraph; | ||||
| ListBase targets = {NULL, NULL}; | |||||
| bool free_depsgraph = false; | bool free_depsgraph = false; | ||||
| ListBase targets = {NULL, NULL}; | |||||
| /* set flag to force recalc, then grab the relevant bones to target */ | /* set flag to force recalc, then grab the relevant bones to target */ | ||||
| ob->pose->avs.recalc |= ANIMVIZ_RECALC_PATHS; | ob->pose->avs.recalc |= ANIMVIZ_RECALC_PATHS; | ||||
| animviz_get_object_motionpaths(ob, &targets); | animviz_get_object_motionpaths(ob, &targets); | ||||
| /* recalculate paths, then free */ | /* recalculate paths, then free */ | ||||
| #ifdef DEBUG_TIME | #ifdef DEBUG_TIME | ||||
| TIMEIT_START(pose_path_calc); | TIMEIT_START(pose_path_calc); | ||||
| #endif | #endif | ||||
| animviz_calc_motionpaths(depsgraph, bmain, scene, &targets, !free_depsgraph, current_frame_only); | /* For a single frame update it's faster to re-use existing dependency graph and avoid overhead | ||||
| * of building all the relations and so on for a temporary one. */ | |||||
| if (range == POSE_PATH_CALC_RANGE_CURRENT_FRAME) { | |||||
| /* NOTE: Dependency graph will be evaluated at all the frames, but we first need to access some | |||||
| * nested pointers, like animation data. */ | |||||
| depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | |||||
| free_depsgraph = false; | |||||
| } | |||||
| else { | |||||
| depsgraph = animviz_depsgraph_build(bmain, scene, view_layer, &targets); | |||||
| free_depsgraph = true; | |||||
| } | |||||
| animviz_calc_motionpaths( | |||||
| depsgraph, bmain, scene, &targets, pose_path_convert_range(range), !free_depsgraph); | |||||
| #ifdef DEBUG_TIME | #ifdef DEBUG_TIME | ||||
| TIMEIT_END(pose_path_calc); | TIMEIT_END(pose_path_calc); | ||||
| #endif | #endif | ||||
| BLI_freelistN(&targets); | BLI_freelistN(&targets); | ||||
| if (!current_frame_only) { | if (range != POSE_PATH_CALC_RANGE_CURRENT_FRAME) { | ||||
| /* Tag armature object for copy on write - so paths will draw/redraw. | /* Tag armature object for copy on write - so paths will draw/redraw. | ||||
| * For currently frame only we update evaluated object directly. */ | * For currently frame only we update evaluated object directly. */ | ||||
| DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); | DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); | ||||
| } | } | ||||
| /* Free temporary depsgraph instance */ | /* Free temporary depsgraph. */ | ||||
| if (free_depsgraph) { | if (free_depsgraph) { | ||||
| DEG_graph_free(depsgraph); | DEG_graph_free(depsgraph); | ||||
| } | } | ||||
| } | } | ||||
| /* show popup to determine settings */ | /* show popup to determine settings */ | ||||
| static int pose_calculate_paths_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | static int pose_calculate_paths_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | static int pose_calculate_paths_exec(bContext *C, wmOperator *op) | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| #ifdef DEBUG_TIME | #ifdef DEBUG_TIME | ||||
| TIMEIT_START(recalc_pose_paths); | TIMEIT_START(recalc_pose_paths); | ||||
| #endif | #endif | ||||
| /* calculate the bones that now have motionpaths... */ | /* calculate the bones that now have motionpaths... */ | ||||
| /* TODO: only make for the selected bones? */ | /* TODO: only make for the selected bones? */ | ||||
| ED_pose_recalculate_paths(C, scene, ob, false); | ED_pose_recalculate_paths(C, scene, ob, POSE_PATH_CALC_RANGE_FULL); | ||||
| #ifdef DEBUG_TIME | #ifdef DEBUG_TIME | ||||
| TIMEIT_END(recalc_pose_paths); | TIMEIT_END(recalc_pose_paths); | ||||
| #endif | #endif | ||||
| /* notifiers for updates */ | /* notifiers for updates */ | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob); | WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob); | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | static int pose_update_paths_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| if (ELEM(NULL, ob, scene)) { | if (ELEM(NULL, ob, scene)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* calculate the bones that now have motionpaths... */ | /* calculate the bones that now have motionpaths... */ | ||||
| /* TODO: only make for the selected bones? */ | /* TODO: only make for the selected bones? */ | ||||
| ED_pose_recalculate_paths(C, scene, ob, false); | ED_pose_recalculate_paths(C, scene, ob, POSE_PATH_CALC_RANGE_FULL); | ||||
| /* notifiers for updates */ | /* notifiers for updates */ | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob); | WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void POSE_OT_paths_update(wmOperatorType *ot) | void POSE_OT_paths_update(wmOperatorType *ot) | ||||
| ▲ Show 20 Lines • Show All 790 Lines • Show Last 20 Lines | |||||