[Bf-blender-cvs] [e7b4e4a94a1] temp-object-multi-mode: Add array utilities for getting objects in mode

Campbell Barton noreply at git.blender.org
Tue Mar 13 13:45:53 CET 2018


Commit: e7b4e4a94a1ba0638ecd30cc6cd18df284f3795c
Author: Campbell Barton
Date:   Tue Mar 13 20:23:22 2018 +1100
Branches: temp-object-multi-mode
https://developer.blender.org/rBe7b4e4a94a1ba0638ecd30cc6cd18df284f3795c

Add array utilities for getting objects in mode

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

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

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

diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
index f69575efdbd..2091da79dbb 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -346,6 +346,33 @@ struct ObjectsRenderableIteratorData {
 	ITER_END;                                                                 \
 } ((void)0)
 
+
+/* Array utilities. */
+
+struct ObjectsInModeParams {
+	int object_mode;
+	uint no_dupe_data : 1;
+};
+
+Base **BKE_view_layer_array_from_bases_in_mode_params(
+        struct ViewLayer *view_layer, uint *r_len,
+        const struct ObjectsInModeParams *params);
+
+struct Object **BKE_view_layer_array_from_objects_in_mode_params(
+        struct ViewLayer *view_layer, uint *len,
+        const struct ObjectsInModeParams *params);
+
+#define BKE_view_layer_array_from_objects_in_mode(view_layer, r_len, ...) \
+	BKE_view_layer_array_from_objects_in_mode_params( \
+	        view_layer, r_len, \
+	        &(const struct ObjectsInModeParams){__VA_ARGS__})
+
+
+#define BKE_view_layer_array_from_objects_in_edit_mode(view_layer, r_len, ...) \
+	BKE_view_layer_array_from_objects_in_mode_params( \
+	        view_layer, r_len, \
+	        &(const struct ObjectsInModeParams){ .object_mode = OB_MODE_EDIT, __VA_ARGS__})
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index cceefb4897f..9b420127110 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -26,6 +26,7 @@
 
 #include <string.h>
 
+#include "BLI_array.h"
 #include "BLI_listbase.h"
 #include "BLI_string.h"
 #include "BLI_string_utf8.h"
@@ -2408,6 +2409,59 @@ void BKE_layer_eval_layer_collection_post(const struct EvaluationContext *UNUSED
 	}
 }
 
+
+Base **BKE_view_layer_array_from_bases_in_mode_params(
+        ViewLayer *view_layer, uint *r_len,
+        const struct ObjectsInModeParams *params)
+{
+	if (params->no_dupe_data) {
+		FOREACH_BASE_IN_MODE_BEGIN(view_layer, params->object_mode, base_iter) {
+			ID *id = base_iter->object->data;
+			if (id) {
+				id->tag |= LIB_TAG_DOIT;
+			}
+		} FOREACH_BASE_IN_MODE_END;
+	}
+
+	Base **base_array = NULL;
+	BLI_array_declare(base_array);
+
+	FOREACH_BASE_IN_MODE_BEGIN(view_layer, params->object_mode, base_iter) {
+		if (params->no_dupe_data) {
+			ID *id = base_iter->object->data;
+			if (id) {
+				if (id->tag & LIB_TAG_DOIT) {
+					id->tag &= ~LIB_TAG_DOIT;
+				}
+				else {
+					continue;
+				}
+			}
+		}
+		BLI_array_append(base_array, base_iter);
+	} FOREACH_BASE_IN_MODE_END;
+
+	if (base_array != NULL) {
+		base_array = MEM_reallocN(base_array, sizeof(*base_array) * BLI_array_count(base_array));
+	}
+	*r_len = BLI_array_count(base_array);
+	return base_array;
+}
+
+Object **BKE_view_layer_array_from_objects_in_mode_params(
+        ViewLayer *view_layer, uint *r_len,
+        const struct ObjectsInModeParams *params)
+{
+	Base **base_array = BKE_view_layer_array_from_bases_in_mode_params(
+	        view_layer, r_len, params);
+	if (base_array != NULL) {
+		for (uint i = 0; i < *r_len; i++) {
+			((Object **)base_array)[i] = base_array[i]->object;
+		}
+	}
+	return (Object **)base_array;
+}
+
 /**
  * Free any static allocated memory.
  */



More information about the Bf-blender-cvs mailing list