Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/animation/anim_motion_paths.c
| Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | typedef struct MPathTarget { | ||||
| /* "Evaluated" Copies (these come from the background COW copy | /* "Evaluated" Copies (these come from the background COW copy | ||||
| * that provide all the coordinates we want to save off). */ | * that provide all the coordinates we want to save off). */ | ||||
| Object *ob_eval; /* evaluated object */ | Object *ob_eval; /* evaluated object */ | ||||
| } MPathTarget; | } MPathTarget; | ||||
| /* ........ */ | /* ........ */ | ||||
| /* update scene for current frame */ | /* update scene for current frame */ | ||||
| static void motionpaths_calc_update_scene(Main *bmain, struct Depsgraph *depsgraph) | static void motionpaths_calc_update_scene(struct Depsgraph *depsgraph) | ||||
| { | { | ||||
| BKE_scene_graph_update_for_newframe(depsgraph, bmain); | BKE_scene_graph_update_for_newframe(depsgraph); | ||||
| } | } | ||||
| Depsgraph *animviz_depsgraph_build(Main *bmain, | Depsgraph *animviz_depsgraph_build(Main *bmain, | ||||
| Scene *scene, | Scene *scene, | ||||
| ViewLayer *view_layer, | ViewLayer *view_layer, | ||||
| ListBase *targets) | ListBase *targets) | ||||
| { | { | ||||
| /* Allocate dependency graph. */ | /* Allocate dependency graph. */ | ||||
| Depsgraph *depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_VIEWPORT); | Depsgraph *depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_VIEWPORT); | ||||
| /* Make a flat array of IDs for the DEG API. */ | /* Make a flat array of IDs for the DEG API. */ | ||||
| const int num_ids = BLI_listbase_count(targets); | const int num_ids = BLI_listbase_count(targets); | ||||
| ID **ids = MEM_malloc_arrayN(sizeof(ID *), num_ids, "animviz IDS"); | ID **ids = MEM_malloc_arrayN(sizeof(ID *), num_ids, "animviz IDS"); | ||||
| int current_id_index = 0; | int current_id_index = 0; | ||||
| for (MPathTarget *mpt = targets->first; mpt != NULL; mpt = mpt->next) { | for (MPathTarget *mpt = targets->first; mpt != NULL; mpt = mpt->next) { | ||||
| ids[current_id_index++] = &mpt->ob->id; | ids[current_id_index++] = &mpt->ob->id; | ||||
| } | } | ||||
| /* Build graph from all requested IDs. */ | /* Build graph from all requested IDs. */ | ||||
| DEG_graph_build_from_ids(depsgraph, bmain, scene, view_layer, ids, num_ids); | DEG_graph_build_from_ids(depsgraph, bmain, scene, view_layer, ids, num_ids); | ||||
| MEM_freeN(ids); | MEM_freeN(ids); | ||||
| /* Update once so we can access pointers of evaluated animation data. */ | /* Update once so we can access pointers of evaluated animation data. */ | ||||
| motionpaths_calc_update_scene(bmain, depsgraph); | motionpaths_calc_update_scene(depsgraph); | ||||
| return depsgraph; | return depsgraph; | ||||
| } | } | ||||
| /* get list of motion paths to be baked for the given object | /* get list of motion paths to be baked for the given object | ||||
| * - assumes the given list is ready to be used | * - assumes the given list is ready to be used | ||||
| */ | */ | ||||
| /* TODO: it would be nice in future to be able to update objects dependent on these bones too? */ | /* TODO: it would be nice in future to be able to update objects dependent on these bones too? */ | ||||
| void animviz_get_object_motionpaths(Object *ob, ListBase *targets) | void animviz_get_object_motionpaths(Object *ob, ListBase *targets) | ||||
| ▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | CLOG_INFO(&LOG, | ||||
| efra - sfra + 1); | efra - sfra + 1); | ||||
| for (CFRA = sfra; CFRA <= efra; CFRA++) { | for (CFRA = sfra; CFRA <= efra; CFRA++) { | ||||
| if (range == ANIMVIZ_CALC_RANGE_CURRENT_FRAME) { | if (range == ANIMVIZ_CALC_RANGE_CURRENT_FRAME) { | ||||
| /* For current frame, only update tagged. */ | /* For current frame, only update tagged. */ | ||||
| BKE_scene_graph_update_tagged(depsgraph, bmain); | BKE_scene_graph_update_tagged(depsgraph, bmain); | ||||
| } | } | ||||
| else { | else { | ||||
| /* Update relevant data for new frame. */ | /* Update relevant data for new frame. */ | ||||
| motionpaths_calc_update_scene(bmain, depsgraph); | motionpaths_calc_update_scene(depsgraph); | ||||
| } | } | ||||
| /* perform baking for targets */ | /* perform baking for targets */ | ||||
| motionpaths_calc_bake_targets(targets, CFRA); | motionpaths_calc_bake_targets(targets, CFRA); | ||||
| } | } | ||||
| /* reset original environment */ | /* reset original environment */ | ||||
| /* NOTE: We don't always need to reevaluate the main scene, as the depsgraph | /* NOTE: We don't always need to reevaluate the main scene, as the depsgraph | ||||
| * may be a temporary one that works on a subset of the data. | * may be a temporary one that works on a subset of the data. | ||||
| * We always have to restore the current frame though. */ | * We always have to restore the current frame though. */ | ||||
| CFRA = cfra; | CFRA = cfra; | ||||
| if (range != ANIMVIZ_CALC_RANGE_CURRENT_FRAME && restore) { | if (range != ANIMVIZ_CALC_RANGE_CURRENT_FRAME && restore) { | ||||
| motionpaths_calc_update_scene(bmain, depsgraph); | motionpaths_calc_update_scene(depsgraph); | ||||
| } | } | ||||
| if (is_active_depsgraph) { | if (is_active_depsgraph) { | ||||
| DEG_make_active(depsgraph); | DEG_make_active(depsgraph); | ||||
| } | } | ||||
| /* clear recalc flags from targets */ | /* clear recalc flags from targets */ | ||||
| LISTBASE_FOREACH (MPathTarget *, mpt, targets) { | LISTBASE_FOREACH (MPathTarget *, mpt, targets) { | ||||
| Show All 17 Lines | |||||