Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_edit.c
| Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | |||||
| /** \name Internal Utilities | /** \name Internal Utilities | ||||
| * \{ */ | * \{ */ | ||||
| Object *ED_object_context(const bContext *C) | Object *ED_object_context(const bContext *C) | ||||
| { | { | ||||
| return CTX_data_pointer_get_type(C, "object", &RNA_Object).data; | return CTX_data_pointer_get_type(C, "object", &RNA_Object).data; | ||||
| } | } | ||||
| /* Find the correct active object per context. | |||||
| * NOTE: context can be NULL when called from a enum with #PROP_ENUM_NO_CONTEXT. */ | |||||
| Object *ED_object_active_context(const bContext *C) | Object *ED_object_active_context(const bContext *C) | ||||
| { | { | ||||
| Object *ob = NULL; | Object *ob = NULL; | ||||
| if (C) { | if (C) { | ||||
| ob = ED_object_context(C); | ob = ED_object_context(C); | ||||
| if (!ob) { | if (!ob) { | ||||
| ob = CTX_data_active_object(C); | ob = CTX_data_active_object(C); | ||||
| } | } | ||||
| } | } | ||||
| return ob; | return ob; | ||||
| } | } | ||||
| /** | |||||
| * Return an array of objects: | |||||
| * - When in the property space, return the pinned or active object. | |||||
| * - When in edit-mode/pose-mode, return an array of objects in the mode. | |||||
| * - Otherwise return selected objects, | |||||
| * the callers \a filter_fn needs to check of they are editable | |||||
| * (assuming they need to be modified). | |||||
| */ | |||||
| Object **ED_object_array_in_mode_or_selected(bContext *C, | Object **ED_object_array_in_mode_or_selected(bContext *C, | ||||
| bool (*filter_fn)(const Object *ob, void *user_data), | bool (*filter_fn)(const Object *ob, void *user_data), | ||||
| void *filter_user_data, | void *filter_user_data, | ||||
| uint *r_objects_len) | uint *r_objects_len) | ||||
| { | { | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| Object *ob_active = OBACT(view_layer); | Object *ob_active = OBACT(view_layer); | ||||
| ▲ Show 20 Lines • Show All 497 Lines • ▼ Show 20 Lines | static bool ED_object_editmode_load_free_ex(Main *bmain, | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool ED_object_editmode_load(Main *bmain, Object *obedit) | bool ED_object_editmode_load(Main *bmain, Object *obedit) | ||||
| { | { | ||||
| return ED_object_editmode_load_free_ex(bmain, obedit, true, false); | return ED_object_editmode_load_free_ex(bmain, obedit, true, false); | ||||
| } | } | ||||
| /** | |||||
| * \param flag: | |||||
| * - If #EM_FREEDATA isn't in the flag, use ED_object_editmode_load directly. | |||||
| */ | |||||
| bool ED_object_editmode_exit_ex(Main *bmain, Scene *scene, Object *obedit, int flag) | bool ED_object_editmode_exit_ex(Main *bmain, Scene *scene, Object *obedit, int flag) | ||||
| { | { | ||||
| const bool free_data = (flag & EM_FREEDATA) != 0; | const bool free_data = (flag & EM_FREEDATA) != 0; | ||||
| if (ED_object_editmode_load_free_ex(bmain, obedit, true, free_data) == false) { | if (ED_object_editmode_load_free_ex(bmain, obedit, true, free_data) == false) { | ||||
| /* in rare cases (background mode) its possible active object | /* in rare cases (background mode) its possible active object | ||||
| * is flagged for editmode, without 'obedit' being set T35489. */ | * is flagged for editmode, without 'obedit' being set T35489. */ | ||||
| if (UNLIKELY(obedit && obedit->mode & OB_MODE_EDIT)) { | if (UNLIKELY(obedit && obedit->mode & OB_MODE_EDIT)) { | ||||
| Show All 34 Lines | |||||
| bool ED_object_editmode_exit(bContext *C, int flag) | bool ED_object_editmode_exit(bContext *C, int flag) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| return ED_object_editmode_exit_ex(bmain, scene, obedit, flag); | return ED_object_editmode_exit_ex(bmain, scene, obedit, flag); | ||||
| } | } | ||||
| /** | |||||
| * Support freeing edit-mode data without flushing it back to the object. | |||||
| * | |||||
| * \return true if data was freed. | |||||
| */ | |||||
| bool ED_object_editmode_free_ex(Main *bmain, Object *obedit) | bool ED_object_editmode_free_ex(Main *bmain, Object *obedit) | ||||
| { | { | ||||
| return ED_object_editmode_load_free_ex(bmain, obedit, false, true); | return ED_object_editmode_load_free_ex(bmain, obedit, false, true); | ||||
| } | } | ||||
| bool ED_object_editmode_exit_multi_ex(Main *bmain, Scene *scene, ViewLayer *view_layer, int flag) | bool ED_object_editmode_exit_multi_ex(Main *bmain, Scene *scene, ViewLayer *view_layer, int flag) | ||||
| { | { | ||||
| Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); | Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); | ||||
| ▲ Show 20 Lines • Show All 417 Lines • ▼ Show 20 Lines | static bool has_object_motion_paths(Object *ob) | ||||
| return (ob->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) != 0; | return (ob->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) != 0; | ||||
| } | } | ||||
| static bool has_pose_motion_paths(Object *ob) | static bool has_pose_motion_paths(Object *ob) | ||||
| { | { | ||||
| return ob->pose && (ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) != 0; | return ob->pose && (ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) != 0; | ||||
| } | } | ||||
| /* For the objects with animation: update paths for those that have got them | |||||
| * This should selectively update paths that exist... | |||||
| * | |||||
| * To be called from various tools that do incremental updates | |||||
| */ | |||||
| void ED_objects_recalculate_paths(bContext *C, | void ED_objects_recalculate_paths(bContext *C, | ||||
| Scene *scene, | Scene *scene, | ||||
| eObjectPathCalcRange range, | eObjectPathCalcRange range, | ||||
| ListBase *ld_objects) | ListBase *ld_objects) | ||||
| { | { | ||||
| /* 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; | ||||
| ▲ Show 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | if (ob->mpath) { | ||||
| ob->mpath = NULL; | ob->mpath = NULL; | ||||
| ob->avs.path_bakeflag &= ~MOTIONPATH_BAKE_HAS_PATHS; | ob->avs.path_bakeflag &= ~MOTIONPATH_BAKE_HAS_PATHS; | ||||
| /* tag object for copy on write - so removed paths don't still show */ | /* tag object for copy on write - so removed paths don't still show */ | ||||
| DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); | DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); | ||||
| } | } | ||||
| } | } | ||||
| /* Clear motion paths for all objects */ | |||||
| void ED_objects_clear_paths(bContext *C, bool only_selected) | void ED_objects_clear_paths(bContext *C, bool only_selected) | ||||
| { | { | ||||
| if (only_selected) { | if (only_selected) { | ||||
| /* Loop over all selected + editable objects in scene. */ | /* Loop over all selected + editable objects in scene. */ | ||||
| CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { | CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { | ||||
| object_clear_mpath(ob); | object_clear_mpath(ob); | ||||
| } | } | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| ▲ Show 20 Lines • Show All 747 Lines • Show Last 20 Lines | |||||