diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-09-10 08:42:40 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-09-10 09:02:12 +0300 |
commit | 549ac6ddebef8113f8a84a945a40280f6fe9d565 (patch) | |
tree | 3e1793410b9279c3640c4d64f46bc8b2d44b8d6a /source/blender/editors/space_view3d | |
parent | fc06bd723617bb57e38c9cd1db247267246a07dc (diff) |
Edit Mesh: pass Base array to picking functions
In some cases we need to use this array afterwards,
so this gives control over which objects are used for picking.
Also use an index argument as return argument
so callers that need to know the index in the array
don't need to calculate it afterwards.
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c | 108 |
1 files changed, 53 insertions, 55 deletions
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c b/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c index 0692c803904..6cd94830fe9 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c @@ -62,9 +62,9 @@ typedef struct MeshElemGizmo3D { wmGizmo gizmo; - Object **objects; - uint objects_len; - int object_index; + Base **bases; + uint bases_len; + int base_index; int vert_index; int edge_index; int face_index; @@ -74,8 +74,8 @@ typedef struct MeshElemGizmo3D { static void gizmo_preselect_elem_draw(const bContext *UNUSED(C), wmGizmo *gz) { MeshElemGizmo3D *gz_ele = (MeshElemGizmo3D *)gz; - if (gz_ele->object_index != -1) { - Object *ob = gz_ele->objects[gz_ele->object_index]; + if (gz_ele->base_index != -1) { + Object *ob = gz_ele->bases[gz_ele->base_index]->object; EDBM_preselect_elem_draw(gz_ele->psel, ob->obmat); } } @@ -88,18 +88,18 @@ static int gizmo_preselect_elem_test_select( Object *ob; BMElem *ele; float dist; - int ob_index; + int base_index; } best = { .dist = ED_view3d_select_dist_px(), }; struct { - int object_index; + int base_index; int vert_index; int edge_index; int face_index; } prev = { - .object_index = gz_ele->object_index, + .base_index = gz_ele->base_index, .vert_index = gz_ele->vert_index, .edge_index = gz_ele->edge_index, .face_index = gz_ele->face_index, @@ -107,11 +107,12 @@ static int gizmo_preselect_elem_test_select( { ViewLayer *view_layer = CTX_data_view_layer(C); - if (((gz_ele->objects)) == NULL || - (gz_ele->objects[0] != OBEDIT_FROM_VIEW_LAYER(view_layer))) + if (((gz_ele->bases)) == NULL || + (gz_ele->bases[0] != view_layer->basact)) { - gz_ele->objects = BKE_view_layer_array_from_objects_in_edit_mode( - view_layer, &gz_ele->objects_len); + MEM_SAFE_FREE(gz_ele->bases); + gz_ele->bases = BKE_view_layer_array_from_bases_in_edit_mode( + view_layer, &gz_ele->bases_len); } } @@ -121,11 +122,15 @@ static int gizmo_preselect_elem_test_select( { /* TODO: support faces. */ - Base *base = NULL; + int base_index = -1; BMVert *eve_test; BMEdge *eed_test; - if (EDBM_unified_findnearest_from_raycast(&vc, true, &base, &eve_test, &eed_test, NULL)) { + if (EDBM_unified_findnearest_from_raycast( + &vc, gz_ele->bases, gz_ele->bases_len, + true, &base_index, &eve_test, &eed_test, NULL)) + { + Base *base = gz_ele->bases[base_index]; best.ob = base->object; if (eve_test) { best.ele = (BMElem *)eve_test; @@ -136,30 +141,22 @@ static int gizmo_preselect_elem_test_select( else { BLI_assert(0); } - best.ob_index = -1; - /* weak, we could ensure the arrays are aligned, - * or allow EDBM_unified_findnearest_from_raycast to take an array arg. */ - for (int ob_index = 0; ob_index < gz_ele->objects_len; ob_index++) { - if (best.ob == gz_ele->objects[ob_index]) { - best.ob_index = ob_index; - break; - } - } + best.base_index = base_index; /* Check above should never fail, if it does it's an internal error. */ - BLI_assert(best.ob_index != -1); + BLI_assert(best.base_index != -1); } } BMesh *bm = NULL; - gz_ele->object_index = -1; + gz_ele->base_index = -1; gz_ele->vert_index = -1; gz_ele->edge_index = -1; gz_ele->face_index = -1; if (best.ele) { - gz_ele->object_index = best.ob_index; - bm = BKE_editmesh_from_object(gz_ele->objects[gz_ele->object_index])->bm; + gz_ele->base_index = best.base_index; + bm = BKE_editmesh_from_object(gz_ele->bases[gz_ele->base_index]->object)->bm; BM_mesh_elem_index_ensure(bm, best.ele->head.htype); if (best.ele->head.htype == BM_VERT) { @@ -173,7 +170,7 @@ static int gizmo_preselect_elem_test_select( } } - if ((prev.object_index == gz_ele->object_index) && + if ((prev.base_index == gz_ele->base_index) && (prev.vert_index == gz_ele->vert_index) && (prev.edge_index == gz_ele->edge_index) && (prev.face_index == gz_ele->face_index)) @@ -184,7 +181,7 @@ static int gizmo_preselect_elem_test_select( if (best.ele) { const float (*coords)[3] = NULL; { - Object *ob = gz_ele->objects[gz_ele->object_index]; + Object *ob = gz_ele->bases[gz_ele->base_index]->object; Depsgraph *depsgraph = CTX_data_depsgraph(C); Mesh *me_eval = (Mesh *)DEG_get_evaluated_id(depsgraph, ob->data); if (me_eval->runtime.edit_data) { @@ -197,7 +194,7 @@ static int gizmo_preselect_elem_test_select( EDBM_preselect_elem_clear(gz_ele->psel); } - RNA_int_set(gz->ptr, "object_index", gz_ele->object_index); + RNA_int_set(gz->ptr, "object_index", gz_ele->base_index); RNA_int_set(gz->ptr, "vert_index", gz_ele->vert_index); RNA_int_set(gz->ptr, "edge_index", gz_ele->edge_index); RNA_int_set(gz->ptr, "face_index", gz_ele->face_index); @@ -216,7 +213,7 @@ static void gizmo_preselect_elem_setup(wmGizmo *gz) if (gz_ele->psel == NULL) { gz_ele->psel = EDBM_preselect_elem_create(); } - gz_ele->object_index = -1; + gz_ele->base_index = -1; } static void gizmo_preselect_elem_free(wmGizmo *gz) @@ -224,7 +221,7 @@ static void gizmo_preselect_elem_free(wmGizmo *gz) MeshElemGizmo3D *gz_ele = (MeshElemGizmo3D *)gz; EDBM_preselect_elem_destroy(gz_ele->psel); gz_ele->psel = NULL; - MEM_SAFE_FREE(gz_ele->objects); + MEM_SAFE_FREE(gz_ele->bases); } static int gizmo_preselect_elem_invoke( @@ -262,9 +259,9 @@ static void GIZMO_GT_mesh_preselect_elem_3d(wmGizmoType *gzt) typedef struct MeshEdgeRingGizmo3D { wmGizmo gizmo; - Object **objects; - uint objects_len; - int object_index; + Base **bases; + uint bases_len; + int base_index; int edge_index; struct EditMesh_PreSelEdgeRing *psel; } MeshEdgeRingGizmo3D; @@ -272,8 +269,8 @@ typedef struct MeshEdgeRingGizmo3D { static void gizmo_preselect_edgering_draw(const bContext *UNUSED(C), wmGizmo *gz) { MeshEdgeRingGizmo3D *gz_ring = (MeshEdgeRingGizmo3D *)gz; - if (gz_ring->object_index != -1) { - Object *ob = gz_ring->objects[gz_ring->object_index]; + if (gz_ring->base_index != -1) { + Object *ob = gz_ring->bases[gz_ring->base_index]->object; EDBM_preselect_edgering_draw(gz_ring->psel, ob->obmat); } } @@ -286,26 +283,27 @@ static int gizmo_preselect_edgering_test_select( Object *ob; BMEdge *eed; float dist; - int ob_index; + int base_index; } best = { .dist = ED_view3d_select_dist_px(), }; struct { - int object_index; + int base_index; int edge_index; } prev = { - .object_index = gz_ring->object_index, + .base_index = gz_ring->base_index, .edge_index = gz_ring->edge_index, }; { ViewLayer *view_layer = CTX_data_view_layer(C); - if (((gz_ring->objects)) == NULL || - (gz_ring->objects[0] != OBEDIT_FROM_VIEW_LAYER(view_layer))) + if (((gz_ring->bases)) == NULL || + (gz_ring->bases[0] != view_layer->basact)) { - gz_ring->objects = BKE_view_layer_array_from_objects_in_edit_mode( - view_layer, &gz_ring->objects_len); + MEM_SAFE_FREE(gz_ring->bases); + gz_ring->bases = BKE_view_layer_array_from_bases_in_edit_mode( + view_layer, &gz_ring->bases_len); } } @@ -313,31 +311,31 @@ static int gizmo_preselect_edgering_test_select( em_setup_viewcontext(C, &vc); copy_v2_v2_int(vc.mval, mval); - for (uint ob_index = 0; ob_index < gz_ring->objects_len; ob_index++) { - Object *ob_iter = gz_ring->objects[ob_index]; + for (uint base_index = 0; base_index < gz_ring->bases_len; base_index++) { + Object *ob_iter = gz_ring->bases[base_index]->object; ED_view3d_viewcontext_init_object(&vc, ob_iter); BMEdge *eed_test = EDBM_edge_find_nearest_ex(&vc, &best.dist, NULL, false, false, NULL); if (eed_test) { best.ob = ob_iter; best.eed = eed_test; - best.ob_index = ob_index; + best.base_index = base_index; } } BMesh *bm = NULL; if (best.eed) { - gz_ring->object_index = best.ob_index; - bm = BKE_editmesh_from_object(gz_ring->objects[gz_ring->object_index])->bm; + gz_ring->base_index = best.base_index; + bm = BKE_editmesh_from_object(gz_ring->bases[gz_ring->base_index]->object)->bm; BM_mesh_elem_index_ensure(bm, BM_EDGE); gz_ring->edge_index = BM_elem_index_get(best.eed); } else { - gz_ring->object_index = -1; + gz_ring->base_index = -1; gz_ring->edge_index = -1; } - if ((prev.object_index == gz_ring->object_index) && + if ((prev.base_index == gz_ring->base_index) && (prev.edge_index == gz_ring->edge_index)) { /* pass (only recalculate on change) */ @@ -346,7 +344,7 @@ static int gizmo_preselect_edgering_test_select( if (best.eed) { const float (*coords)[3] = NULL; { - Object *ob = gz_ring->objects[gz_ring->object_index]; + Object *ob = gz_ring->bases[gz_ring->base_index]->object; Depsgraph *depsgraph = CTX_data_depsgraph(C); Mesh *me_eval = (Mesh *)DEG_get_evaluated_id(depsgraph, ob->data); if (me_eval->runtime.edit_data) { @@ -359,7 +357,7 @@ static int gizmo_preselect_edgering_test_select( EDBM_preselect_edgering_clear(gz_ring->psel); } - RNA_int_set(gz->ptr, "object_index", gz_ring->object_index); + RNA_int_set(gz->ptr, "object_index", gz_ring->base_index); RNA_int_set(gz->ptr, "edge_index", gz_ring->edge_index); ARegion *ar = CTX_wm_region(C); @@ -376,7 +374,7 @@ static void gizmo_preselect_edgering_setup(wmGizmo *gz) if (gz_ring->psel == NULL) { gz_ring->psel = EDBM_preselect_edgering_create(); } - gz_ring->object_index = -1; + gz_ring->base_index = -1; } static void gizmo_preselect_edgering_free(wmGizmo *gz) @@ -384,7 +382,7 @@ static void gizmo_preselect_edgering_free(wmGizmo *gz) MeshEdgeRingGizmo3D *gz_ring = (MeshEdgeRingGizmo3D *)gz; EDBM_preselect_edgering_destroy(gz_ring->psel); gz_ring->psel = NULL; - MEM_SAFE_FREE(gz_ring->objects); + MEM_SAFE_FREE(gz_ring->bases); } static int gizmo_preselect_edgering_invoke( |