[Bf-blender-cvs] [2778937fb6b] master: BKE_layer: add BKE_view_layer_array_selected_objects_params

Campbell Barton noreply at git.blender.org
Sun Aug 30 05:50:44 CEST 2020


Commit: 2778937fb6b965d4c428f87551cccb2eafd56bf1
Author: Campbell Barton
Date:   Sun Aug 30 13:19:50 2020 +1000
Branches: master
https://developer.blender.org/rB2778937fb6b965d4c428f87551cccb2eafd56bf1

BKE_layer: add BKE_view_layer_array_selected_objects_params

Useful for similar situations as BKE_view_layer_array_from_bases_in_mode_params
without depending on the active objects mode.

===================================================================

M	source/blender/blenkernel/BKE_layer.h
M	source/blender/blenkernel/intern/layer_utils.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
index 1976509543d..6c9b41b835e 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -352,6 +352,19 @@ void BKE_view_layer_visible_bases_iterator_end(BLI_Iterator *iter);
 
 /* layer_utils.c */
 
+struct ObjectsInViewLayerParams {
+  uint no_dup_data : 1;
+
+  bool (*filter_fn)(struct Object *ob, void *user_data);
+  void *filter_userdata;
+};
+
+struct Object **BKE_view_layer_array_selected_objects_params(
+    struct ViewLayer *view_layer,
+    const struct View3D *v3d,
+    uint *r_len,
+    const struct ObjectsInViewLayerParams *params);
+
 struct ObjectsInModeParams {
   int object_mode;
   uint no_dup_data : 1;
diff --git a/source/blender/blenkernel/intern/layer_utils.c b/source/blender/blenkernel/intern/layer_utils.c
index 20ad0cb6af1..513bc9e1420 100644
--- a/source/blender/blenkernel/intern/layer_utils.c
+++ b/source/blender/blenkernel/intern/layer_utils.c
@@ -34,6 +34,63 @@
 
 #include "MEM_guardedalloc.h"
 
+/* -------------------------------------------------------------------- */
+/** \name Selected Object Array
+ * \{ */
+
+Object **BKE_view_layer_array_selected_objects_params(
+    struct ViewLayer *view_layer,
+    const struct View3D *v3d,
+    uint *r_len,
+    const struct ObjectsInViewLayerParams *params)
+{
+  if (params->no_dup_data) {
+    FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob_iter) {
+      ID *id = ob_iter->data;
+      if (id) {
+        id->tag |= LIB_TAG_DOIT;
+      }
+    }
+    FOREACH_SELECTED_OBJECT_END;
+  }
+
+  Object **object_array = NULL;
+  BLI_array_declare(object_array);
+
+  FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob_iter) {
+    if (params->filter_fn) {
+      if (!params->filter_fn(ob_iter, params->filter_userdata)) {
+        continue;
+      }
+    }
+
+    if (params->no_dup_data) {
+      ID *id = ob_iter->data;
+      if (id) {
+        if (id->tag & LIB_TAG_DOIT) {
+          id->tag &= ~LIB_TAG_DOIT;
+        }
+        else {
+          continue;
+        }
+      }
+    }
+
+    BLI_array_append(object_array, ob_iter);
+  }
+  FOREACH_SELECTED_OBJECT_END;
+
+  object_array = MEM_reallocN(object_array, sizeof(*object_array) * BLI_array_len(object_array));
+  /* We always need a valid allocation (prevent crash on free). */
+  if (object_array == NULL) {
+    object_array = MEM_mallocN(0, __func__);
+  }
+  *r_len = BLI_array_len(object_array);
+  return object_array;
+}
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name Objects in Mode Array
  * \{ */



More information about the Bf-blender-cvs mailing list