diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-08-30 10:39:12 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-08-30 11:53:19 +0300 |
commit | 12bc34b0b81b11186e3814f8a255f1226f0588c3 (patch) | |
tree | 3d18bb58c9f0973753e70931a73ebf7a270fbf02 /source/blender/editors/object/object_edit.c | |
parent | 1a623c183f32fb913f4cadd63d2a667087df7637 (diff) |
Object: add ED_object_array_in_mode_or_selected
Use this utility function for render-shading & weight paint modes.
This adds support for edit-mode & pose-mode where all objects in the
mode are used in this case instead of the selected objects.
Diffstat (limited to 'source/blender/editors/object/object_edit.c')
-rw-r--r-- | source/blender/editors/object/object_edit.c | 66 |
1 files changed, 66 insertions, 0 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; +} + /** \} */ /* -------------------------------------------------------------------- */ |