Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2020-09-01 20:35:14 +0300
committerHans Goudey <h.goudey@me.com>2020-09-01 20:38:05 +0300
commitbaca8611e5fe4b3dcd6f5065fb125bc0a9d65934 (patch)
treebb1230387cd53b15f9621f10c4d0e5e2050b5580 /source/blender/editors/object/object_edit.c
parent31705201dddebf7e3be5c4533b89f380aad1ede1 (diff)
parent2930d4fcea405985f2212c5f28c061af7c4849f8 (diff)
Merge branch 'master' into active-fcurve-keyframeactive-fcurve-keyframe
Diffstat (limited to 'source/blender/editors/object/object_edit.c')
-rw-r--r--source/blender/editors/object/object_edit.c66
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;
+}
+
/** \} */
/* -------------------------------------------------------------------- */