[Bf-blender-cvs] [9a2a76a] soc-2016-layer_manager: Add/use macro for circular base iterations
Julian Eisel
noreply at git.blender.org
Fri Aug 12 17:02:52 CEST 2016
Commit: 9a2a76a45b0ceb2e7229b4d1a7ce9563c4eaa855
Author: Julian Eisel
Date: Fri Aug 12 16:59:46 2016 +0200
Branches: soc-2016-layer_manager
https://developer.blender.org/rB9a2a76a45b0ceb2e7229b4d1a7ce9563c4eaa855
Add/use macro for circular base iterations
===================================================================
M source/blender/blenkernel/BKE_object.h
M source/blender/editors/space_view3d/view3d_select.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 2b940bf..e9a4b1c 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -291,6 +291,16 @@ bool BKE_object_modifier_update_subframe(struct Scene *scene, struct Object *ob,
#define BKE_BASES_ITER_START(scene, base_name) \
BKE_BASES_ITER_START_EX(scene, base_name, false)
+#define BKE_BASES_ITER_CIRCULAR_START(scene, base_name, base_start, skip_hidden) \
+ for (Base *base_name = base_start, *base_name##_next = NULL; base_name != base_start; base = base_name##_next) { \
+ base_name##_next = BKE_objectlayer_base_next_find(base_name, skip_hidden); \
+ if (!base_name##_next) { \
+ /* continue with first base in layer tree */ \
+ base_name##_next = BKE_objectlayer_base_first_find(scene->object_layers); \
+ } \
+ if (skip_hidden && (base_name->object->restrictflag & OB_RESTRICT_VIEW)) \
+ continue;
+
/* Version of BKE_BASES_ITER_START that skips invisible layers and
* invisible objects. Doesn't do layer visibility-bit check.*/
#define BKE_BASES_ITER_VISIBLE_START(scene, base_name) \
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index de67607..169da0e 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -1322,82 +1322,25 @@ static Base *mouse_select_eval_buffer(ViewContext *vc, unsigned int *buffer, int
BKE_BASES_ITER_END;
}
else {
- const int max_layidx = BKE_layertree_get_totitems(scene->object_layers) - 1;
- bool found_startbase = false;
- bool done = false;
-
-#define ENSURE_CYCLIC_ITER \
- if (j == (oblayer->tot_bases - 1)) { \
- /* at the end of object iterator, back to first object in layer */ \
- j = -1; \
- if (i == max_layidx) { \
- /* at the end of layer iterator, back to first layer */ \
- i = -1; \
- } \
- }
-
- /* iterate over bases starting with startbase, need more control so not just using BKE_BASES_ITER_START */
- BKE_LAYERTREE_ITER_START(scene->object_layers, startbase->layer->index, i, litem)
+ BKE_BASES_ITER_CIRCULAR_START(scene, base, startbase, true)
{
- LayerTypeObject *oblayer = (LayerTypeObject *)litem;
- if (litem->type->type != LAYER_ITEMTYPE_LAYER) {
- /* at the end of iterator, back to start */
- if (i == max_layidx) {
- i = -1;
- }
- continue;
- }
-
- BKE_OBJECTLAYER_BASES_ITER_START(oblayer, j, base)
- {
- /* skip objects with select restriction, to prevent prematurely ending this loop
- * with an un-selectable choice */
- if (base->object->restrictflag & OB_RESTRICT_SELECT) {
- ENSURE_CYCLIC_ITER;
- continue;
- }
-
- if (base == startbase) {
- /* already found startbase but we're back to it, meaning
- * we've checked all bases, nothing more to do */
- if (found_startbase) {
- done = true;
- break;
- }
- else {
- found_startbase = true;
- }
- }
- else if (!found_startbase) {
- continue;
- }
-
- if (BASE_SELECTABLE(v3d, base)) {
- for (a = 0; a < hits; a++) {
- if (has_bones) {
- /* skip non-bone objects */
- if ((buffer[4 * a + 3] & 0xFFFF0000)) {
- if (base->selcol == (buffer[(4 * a) + 3] & 0xFFFF))
- basact = base;
- }
- }
- else {
+ if (BASE_SELECTABLE(v3d, base)) {
+ for (a = 0; a < hits; a++) {
+ if (has_bones) {
+ /* skip non-bone objects */
+ if ((buffer[4 * a + 3] & 0xFFFF0000)) {
if (base->selcol == (buffer[(4 * a) + 3] & 0xFFFF))
basact = base;
}
}
+ else {
+ if (base->selcol == (buffer[(4 * a) + 3] & 0xFFFF))
+ basact = base;
+ }
}
-
- if (basact) {
- done = true;
+ if (basact)
break;
- }
- ENSURE_CYCLIC_ITER;
}
- BKE_OBJECTLAYER_BASES_ITER_END;
-
- if (done)
- break;
}
BKE_LAYERTREE_ITER_END;
}
@@ -1487,63 +1430,24 @@ static bool ed_object_select_pick(
basact = object_mouse_select_menu(C, &vc, NULL, 0, mval, toggle);
}
else {
- const int max_layidx = BKE_layertree_get_totitems(scene->object_layers);
- bool found_startbase = false;
- bool done = false;
-
- BKE_LAYERTREE_ITER_START(scene->object_layers, startbase->layer->index, i, litem)
+ BKE_BASES_ITER_CIRCULAR_START(scene, base, startbase, true)
{
- if ((litem->type->type != LAYER_ITEMTYPE_LAYER) || !BKE_layeritem_is_visible(litem))
- continue;
- LayerTypeObject *oblayer = (LayerTypeObject *)litem;
-
- BKE_OBJECTLAYER_BASES_ITER_START(oblayer, j, base)
- {
- if (base == startbase) {
- /* already found startbase but we're back to it, meaning
- * we've checked all bases, nothing more to do */
- if (found_startbase) {
- done = true;
- break;
- }
- else {
- found_startbase = true;
- }
- }
- else if (!found_startbase) {
- continue;
- }
-
- if (BASE_SELECTABLE(v3d, base)) {
- eV3DProjTest flag = (V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR);
- float screen_co[2];
- if (ED_view3d_project_float_global(
- ar, base->object->obmat[3], screen_co, flag) == V3D_PROJ_RET_OK)
- {
- float dist_temp = len_manhattan_v2v2(mval_fl, screen_co);
- if (base == BASACT) dist_temp += 10.0f;
- if (dist_temp < dist) {
- dist = dist_temp;
- basact = base;
- }
- }
- }
-
- if (j == (oblayer->tot_bases - 1)) {
- /* at the end of object iterator, back to first object in layer */
- j = -1;
- if (i == max_layidx) {
- /* at the end of layer iterator, back to first layer */
- i = -1;
+ if (BASE_SELECTABLE(v3d, base)) {
+ eV3DProjTest flag = (V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR);
+ float screen_co[2];
+ if (ED_view3d_project_float_global(
+ ar, base->object->obmat[3], screen_co, flag) == V3D_PROJ_RET_OK)
+ {
+ float dist_temp = len_manhattan_v2v2(mval_fl, screen_co);
+ if (base == BASACT) dist_temp += 10.0f;
+ if (dist_temp < dist) {
+ dist = dist_temp;
+ basact = base;
}
}
}
- BKE_OBJECTLAYER_BASES_ITER_END;
-
- if (done)
- break;
}
- BKE_LAYERTREE_ITER_END;
+ BKE_BASES_ITER_END;
}
}
else {
More information about the Bf-blender-cvs
mailing list