[Bf-blender-cvs] [4f6e2528055] master: Fix T54686: objects don't occlude each other for edit-mesh select (part 2)
Campbell Barton
noreply at git.blender.org
Sat May 18 15:59:01 CEST 2019
Commit: 4f6e25280558c46ad49381d41e385e9c8e06bc83
Author: Campbell Barton
Date: Sat May 18 23:12:47 2019 +1000
Branches: master
https://developer.blender.org/rB4f6e25280558c46ad49381d41e385e9c8e06bc83
Fix T54686: objects don't occlude each other for edit-mesh select (part 2)
The previous fix 8a6414ed46f66, resolved selection picking but didn't
work for box/circle/lasso select.
- Add ED_select_buffer_utils.h for general select-buffer operations
unrelated to edit-mesh.
- Circle select still needs to cache select-id's for each update.
===================================================================
M source/blender/draw/intern/draw_manager.c
M source/blender/editors/include/ED_mesh.h
A source/blender/editors/include/ED_select_buffer_utils.h
M source/blender/editors/include/ED_view3d.h
M source/blender/editors/mesh/editmesh_select.c
M source/blender/editors/space_view3d/view3d_draw_legacy.c
M source/blender/editors/space_view3d/view3d_select.c
M source/blender/editors/util/CMakeLists.txt
A source/blender/editors/util/select_buffer_utils.c
===================================================================
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 5c9f49e4ee5..ce37145ea85 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -2779,7 +2779,7 @@ void DRW_draw_select_id_object(Scene *scene,
world_clip_planes = rv3d->clip_local;
}
- initial_offset += 1;
+ BLI_assert(initial_offset > 0);
switch (ob->type) {
case OB_MESH:
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index 4e6bf7d4df5..75e0f05d088 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -152,6 +152,12 @@ struct BMElem *EDBM_select_id_bm_elem_get(struct EDBMSelectID_Context *sel_id_ct
const uint sel_id,
uint *r_base_index);
+uint EDBM_select_id_context_offset_for_object_elem(const struct EDBMSelectID_Context *sel_id_ctx,
+ int base_index,
+ char htype);
+
+uint EDBM_select_id_context_elem_len(const struct EDBMSelectID_Context *sel_id_ctx);
+
void EDBM_select_mirrored(
struct BMEditMesh *em, const int axis, const bool extend, int *r_totmirr, int *r_totfail);
void EDBM_automerge(struct Scene *scene, struct Object *ob, bool update, const char hflag);
diff --git a/source/blender/editors/include/ED_select_buffer_utils.h b/source/blender/editors/include/ED_select_buffer_utils.h
new file mode 100644
index 00000000000..54e4cdb6e4f
--- /dev/null
+++ b/source/blender/editors/include/ED_select_buffer_utils.h
@@ -0,0 +1,35 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup editors
+ */
+
+#ifndef __ED_SELECT_BUFFER_UTILS_H__
+#define __ED_SELECT_BUFFER_UTILS_H__
+
+struct rcti;
+
+uint *ED_select_buffer_bitmap_from_rect(const uint bitmap_len, const struct rcti *rect);
+uint *ED_select_buffer_bitmap_from_circle(const uint bitmap_len,
+ const int center[2],
+ const int radius);
+uint *ED_select_buffer_bitmap_from_poly(const uint bitmap_len,
+ const int poly[][2],
+ const int poly_len,
+ const rcti *rect);
+
+#endif /* __ED_SELECT_BUFFER_UTILS_H__ */
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 2b8f926fc2c..61d1670b88d 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -42,6 +42,7 @@ struct GPUFX;
struct GPUFXSettings;
struct GPUOffScreen;
struct GPUViewport;
+struct ID;
struct ImBuf;
struct MVert;
struct Main;
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index 372ff42f1c3..d6a32a6bd70 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -199,8 +199,19 @@ void EDBM_automerge(Scene *scene, Object *obedit, bool update, const char hflag)
* \{ */
struct EDBMBaseOffset {
- uint face;
- uint edge;
+ /* For convenience only. */
+ union {
+ uint offset;
+ uint face_start;
+ };
+ union {
+ uint face;
+ uint edge_start;
+ };
+ union {
+ uint edge;
+ uint vert_start;
+ };
uint vert;
};
@@ -209,6 +220,8 @@ struct EDBMSelectID_Context {
/** Borrow from caller (not freed). */
struct Base **bases;
uint bases_len;
+ /** Total number of items `base_array_index_offsets[bases_len - 1].vert`. */
+ uint base_array_index_len;
};
static bool check_ob_drawface_dot(short select_mode, const View3D *v3d, char dt)
@@ -234,7 +247,7 @@ static void edbm_select_pick_draw_bases(struct EDBMSelectID_Context *sel_id_ctx,
Scene *scene_eval = (Scene *)DEG_get_evaluated_id(vc->depsgraph, &vc->scene->id);
DRW_framebuffer_select_id_setup(vc->ar, true);
- uint offset = 0;
+ uint offset = 1;
for (uint base_index = 0; base_index < sel_id_ctx->bases_len; base_index++) {
Object *ob_eval = DEG_get_evaluated_object(vc->depsgraph,
sel_id_ctx->bases[base_index]->object);
@@ -252,9 +265,12 @@ static void edbm_select_pick_draw_bases(struct EDBMSelectID_Context *sel_id_ctx,
&base_ofs->edge,
&base_ofs->face);
+ base_ofs->offset = offset;
offset = base_ofs->vert;
}
+ sel_id_ctx->base_array_index_len = offset;
+
DRW_framebuffer_select_id_release(vc->ar);
}
@@ -306,6 +322,29 @@ BMElem *EDBM_select_id_bm_elem_get(struct EDBMSelectID_Context *sel_id_ctx,
}
}
+uint EDBM_select_id_context_offset_for_object_elem(const struct EDBMSelectID_Context *sel_id_ctx,
+ int base_index,
+ char htype)
+{
+ struct EDBMBaseOffset *base_ofs = &sel_id_ctx->base_array_index_offsets[base_index];
+ if (htype == BM_VERT) {
+ return base_ofs->vert_start - 1;
+ }
+ if (htype == BM_EDGE) {
+ return base_ofs->edge_start - 1;
+ }
+ if (htype == BM_FACE) {
+ return base_ofs->face_start - 1;
+ }
+ BLI_assert(0);
+ return 0;
+}
+
+uint EDBM_select_id_context_elem_len(const struct EDBMSelectID_Context *sel_id_ctx)
+{
+ return sel_id_ctx->base_array_index_len;
+}
+
struct EDBMSelectID_Context *EDBM_select_id_context_create(ViewContext *vc,
Base **bases,
uint bases_len,
diff --git a/source/blender/editors/space_view3d/view3d_draw_legacy.c b/source/blender/editors/space_view3d/view3d_draw_legacy.c
index 3443f333234..c17eb5cef81 100644
--- a/source/blender/editors/space_view3d/view3d_draw_legacy.c
+++ b/source/blender/editors/space_view3d/view3d_draw_legacy.c
@@ -214,7 +214,7 @@ static void validate_object_select_id(struct Depsgraph *depsgraph,
obact_eval,
select_mode,
false,
- 0,
+ 1,
&bm_vertoffs,
&bm_wireoffs,
&bm_solidoffs);
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index a93c14fa1ef..4ea175985b9 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -41,6 +41,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_array.h"
+#include "BLI_bitmap.h"
#include "BLI_math.h"
#include "BLI_lasso_2d.h"
#include "BLI_rect.h"
@@ -88,6 +89,7 @@
#include "ED_mesh.h"
#include "ED_object.h"
#include "ED_screen.h"
+#include "ED_select_buffer_utils.h"
#include "ED_select_utils.h"
#include "ED_sculpt.h"
#include "ED_mball.h"
@@ -178,21 +180,67 @@ static bool object_deselect_all_except(ViewLayer *view_layer, Base *b)
/** \} */
+/* -------------------------------------------------------------------- */
+/** \name Internal Edit-Mesh Select Buffer Wrapper
+ *
+ * Avoid duplicate code when using edit-mode selection,
+ * actual logic is handled outside of this function.
+ *
+ * \note Currently this #EDBMSelectID_Context which is mesh specific
+ * however the logic could also be used for non-meshes too.
+ *
+ * \{ */
+
+struct EditSelectBuf_Cache {
+ Base **bases;
+ uint bases_len;
+ struct EDBMSelectID_Context *sel_id_ctx;
+ BLI_bitmap *select_bitmap;
+};
+
+static void editselect_buf_cache_init(struct EditSelectBuf_Cache *esel, ViewContext *vc)
+{
+ esel->bases = BKE_view_layer_array_from_bases_in_edit_mode(
+ vc->view_layer, vc->v3d, &esel->bases_len);
+ esel->sel_id_ctx = EDBM_select_id_context_create(
+ vc, esel->bases, esel->bases_len, vc->scene->toolsettings->selectmode);
+ for (int i = 0; i < esel->bases_len; i++) {
+ esel->bases[i]->object->runtime.select_id = i;
+ }
+}
+
+static void editselect_buf_cache_free(struct EditSelectBuf_Cache *esel)
+{
+ if (esel->sel_id_ctx) {
+ EDBM_select_id_context_destroy(esel->sel_id_ctx);
+ }
+ MEM_SAFE_FREE(esel->select_bitmap);
+ MEM_SAFE_FREE(esel->bases);
+}
+
+/** \} */
+
/* -------------------------------------------------------------------- */
/** \name Internal Edit-Mesh Utilities
* \{ */
-static bool edbm_backbuf_check_and_select_verts(BMEditMesh *em, const eSelectOp sel_op)
+static bool edbm_backbuf_check_and_select_verts(struct EditSelectBuf_Cache *esel,
+ Object *ob,
+ BMEditMesh *em,
+ const eSelectOp sel_op)
{
BMVert *eve;
BMIter iter;
- uint index = bm_wireoffs;
bool changed = false;
+ const BLI_bitmap *select_bitmap = esel->select_bitmap;
+ uint index = EDBM_select_id_context_offset_for_object_elem(
+ esel->sel_id_ctx, ob->runtime.select_id, BM_VERT);
+
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
const bool is_select = BM_elem_flag_test(eve, BM_ELEM_SELECT);
- const bool is_inside = EDBM_backbuf_check(index);
+ const bool is_inside = BLI_BITMAP_TEST_BOOL(select_bitmap, index);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list