diff options
Diffstat (limited to 'source/blender/editors/object')
-rw-r--r-- | source/blender/editors/object/object_edit.c | 66 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 50 |
2 files changed, 67 insertions, 49 deletions
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 04113f70e52..966aeed75ab 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -145,6 +145,72 @@ Object *ED_object_active_context(const bContext *C) 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, + bool (*filter_fn)(Object *ob, void *user_data), + void *filter_user_data, + uint *r_objects_len) +{ + ScrArea *area = CTX_wm_area(C); + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob_active = OBACT(view_layer); + Object **objects; + + Object *ob = NULL; + bool use_ob = true; + if (area && (area->spacetype == SPACE_PROPERTIES)) { + /* May return pinned object. */ + ob = ED_object_context(C); + } + else if (ob_active && (ob_active->mode & + (OB_MODE_ALL_PAINT | OB_MODE_ALL_SCULPT | OB_MODE_ALL_PAINT_GPENCIL))) { + /* When painting, limit to active. */ + ob = ob_active; + } + else { + /* Otherwise use full selection. */ + use_ob = false; + } + + if (use_ob) { + if ((ob != NULL) && !filter_fn(ob, filter_user_data)) { + ob = NULL; + } + *r_objects_len = (ob != NULL) ? 1 : 0; + objects = MEM_mallocN(sizeof(*objects) * *r_objects_len, __func__); + if (ob != NULL) { + objects[0] = ob; + } + } + else { + const View3D *v3d = (area && area->spacetype == SPACE_VIEW3D) ? area->spacedata.first : NULL; + /* When in a mode that supports multiple active objects, use "objects in mode" + * instead of the object's selection. */ + if ((ob_active != NULL) && (ob_active->mode & (OB_MODE_EDIT | OB_MODE_POSE))) { + objects = BKE_view_layer_array_from_objects_in_mode( + view_layer, + v3d, + r_objects_len, + {.no_dup_data = true, .filter_fn = filter_fn, .filter_userdata = filter_user_data}); + } + else { + objects = BKE_view_layer_array_selected_objects( + view_layer, + v3d, + r_objects_len, + {.no_dup_data = true, .filter_fn = filter_fn, .filter_userdata = filter_user_data}); + } + } + return objects; +} + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 41541288e07..a144632fc5f 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -84,54 +84,6 @@ static bool vertex_group_supported_poll_ex(bContext *C, const Object *ob); /** \name Local Utility Functions * \{ */ -static Object **object_array_for_wpaint_impl(bContext *C, - bool (*filter_fn)(struct Object *ob, void *user_data), - void *filter_user_data, - uint *r_objects_len) -{ - Object **objects; - - Object *ob = NULL; - bool use_ob = true; - if (CTX_wm_space_properties(C)) { - /* May return pinned object. */ - ob = ED_object_context(C); - } - else if (CTX_data_mode_enum(C) == CTX_MODE_PAINT_WEIGHT) { - /* When painting, limit to active. */ - ob = CTX_data_active_object(C); - } - else { - /* Otherwise use full selection. */ - use_ob = false; - } - - if (use_ob) { - if (!filter_fn(ob, filter_user_data)) { - ob = NULL; - } - *r_objects_len = (ob != NULL) ? 1 : 0; - objects = MEM_mallocN(sizeof(*objects) * *r_objects_len, __func__); - if (ob != NULL) { - objects[0] = ob; - } - } - else { - ViewLayer *view_layer = CTX_data_view_layer(C); - const View3D *v3d = CTX_wm_view3d(C); /* may be NULL. */ - objects = BKE_view_layer_array_selected_objects_params( - view_layer, - v3d, - r_objects_len, - &((const struct ObjectsInViewLayerParams){ - .no_dup_data = true, - .filter_fn = filter_fn, - .filter_userdata = filter_user_data, - })); - } - return objects; -} - static bool object_array_for_wpaint_filter(Object *ob, void *user_data) { bContext *C = user_data; @@ -143,7 +95,7 @@ static bool object_array_for_wpaint_filter(Object *ob, void *user_data) static Object **object_array_for_wpaint(bContext *C, uint *r_objects_len) { - return object_array_for_wpaint_impl(C, object_array_for_wpaint_filter, C, r_objects_len); + return ED_object_array_in_mode_or_selected(C, object_array_for_wpaint_filter, C, r_objects_len); } static bool vertex_group_use_vert_sel(Object *ob) |