Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_edit.c
| Show First 20 Lines • Show All 904 Lines • ▼ Show 20 Lines | void OBJECT_OT_forcefield_toggle(wmOperatorType *ot) | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| } | } | ||||
| /* ********************************************** */ | /* ********************************************** */ | ||||
| /* Motion Paths */ | /* Motion Paths */ | ||||
| static eAnimvizCalcRange object_path_convert_range(eObjectPathCalcRange range) | |||||
| { | |||||
| switch (range) { | |||||
| case OBJECT_PATH_CALC_RANGE_CURRENT_FRAME: | |||||
| return ANIMVIZ_CALC_RANGE_CURRENT_FRAME; | |||||
| case OBJECT_PATH_CALC_RANGE_CHANGED: | |||||
| return ANIMVIZ_CALC_RANGE_CHANGED; | |||||
| case OBJECT_PATH_CALC_RANGE_FULL: | |||||
| return ANIMVIZ_CALC_RANGE_FULL; | |||||
| } | |||||
| return ANIMVIZ_CALC_RANGE_FULL; | |||||
| } | |||||
| /* For the objects with animation: update paths for those that have got them | /* For the objects with animation: 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_objects_recalculate_paths(bContext *C, Scene *scene, bool current_frame_only) | void ED_objects_recalculate_paths(bContext *C, Scene *scene, eObjectPathCalcRange 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); | |||||
| ListBase targets = {NULL, NULL}; | |||||
| ListBase targets = {NULL, NULL}; | |||||
| /* loop over objects in scene */ | /* loop over objects in scene */ | ||||
| CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { | CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { | ||||
| /* set flag to force recalc, then grab path(s) from object */ | /* set flag to force recalc, then grab path(s) from object */ | ||||
| ob->avs.recalc |= ANIMVIZ_RECALC_PATHS; | ob->avs.recalc |= ANIMVIZ_RECALC_PATHS; | ||||
| animviz_get_object_motionpaths(ob, &targets); | animviz_get_object_motionpaths(ob, &targets); | ||||
| } | } | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| Depsgraph *depsgraph; | |||||
| bool free_depsgraph = false; | |||||
| /* 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 == OBJECT_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; | |||||
| } | |||||
| /* recalculate paths, then free */ | /* recalculate paths, then free */ | ||||
| animviz_calc_motionpaths(depsgraph, bmain, scene, &targets, true, current_frame_only); | animviz_calc_motionpaths( | ||||
| depsgraph, bmain, scene, &targets, object_path_convert_range(range), true); | |||||
| BLI_freelistN(&targets); | BLI_freelistN(&targets); | ||||
| if (!current_frame_only) { | if (range != OBJECT_PATH_CALC_RANGE_CURRENT_FRAME) { | ||||
| /* Tag objects for copy on write - so paths will draw/redraw | /* Tag objects 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. */ | ||||
| CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { | CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { | ||||
| if (ob->mpath) { | if (ob->mpath) { | ||||
| DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); | DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); | ||||
| } | } | ||||
| } | } | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| } | } | ||||
| /* Free temporary depsgraph. */ | |||||
| if (free_depsgraph) { | |||||
| DEG_graph_free(depsgraph); | |||||
| } | |||||
| } | } | ||||
| /* show popup to determine settings */ | /* show popup to determine settings */ | ||||
| static int object_calculate_paths_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | static int object_calculate_paths_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| if (ob == NULL) { | if (ob == NULL) { | ||||
| Show All 29 Lines | CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { | ||||
| avs->path_ef = end; | avs->path_ef = end; | ||||
| /* verify that the selected object has the appropriate settings */ | /* verify that the selected object has the appropriate settings */ | ||||
| animviz_verify_motionpaths(op->reports, scene, ob, NULL); | animviz_verify_motionpaths(op->reports, scene, ob, NULL); | ||||
| } | } | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| /* calculate the paths for objects that have them (and are tagged to get refreshed) */ | /* calculate the paths for objects that have them (and are tagged to get refreshed) */ | ||||
| ED_objects_recalculate_paths(C, scene, false); | ED_objects_recalculate_paths(C, scene, OBJECT_PATH_CALC_RANGE_FULL); | ||||
| /* notifiers for updates */ | /* notifiers for updates */ | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); | WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void OBJECT_OT_paths_calculate(wmOperatorType *ot) | void OBJECT_OT_paths_calculate(wmOperatorType *ot) | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| if (scene == NULL) { | if (scene == NULL) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* calculate the paths for objects that have them (and are tagged to get refreshed) */ | /* calculate the paths for objects that have them (and are tagged to get refreshed) */ | ||||
| ED_objects_recalculate_paths(C, scene, false); | ED_objects_recalculate_paths(C, scene, OBJECT_PATH_CALC_RANGE_FULL); | ||||
| /* notifiers for updates */ | /* notifiers for updates */ | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); | WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void OBJECT_OT_paths_update(wmOperatorType *ot) | void OBJECT_OT_paths_update(wmOperatorType *ot) | ||||
| ▲ Show 20 Lines • Show All 737 Lines • Show Last 20 Lines | |||||