3D View: move pre-select mesh element access into gizmo API
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
/* ********* exports for space_view3d/ module ********** */
|
||||
struct ARegion;
|
||||
struct BMEdge;
|
||||
struct BMElem;
|
||||
struct BMFace;
|
||||
struct BMVert;
|
||||
struct BPoint;
|
||||
@@ -60,10 +61,12 @@ struct bPoseChannel;
|
||||
struct bScreen;
|
||||
struct rctf;
|
||||
struct rcti;
|
||||
struct wmGizmo;
|
||||
struct wmOperator;
|
||||
struct wmOperatorType;
|
||||
struct wmWindow;
|
||||
struct wmWindowManager;
|
||||
|
||||
enum eGPUFXFlags;
|
||||
|
||||
/* for derivedmesh drawing callbacks, for view3d_select, .... */
|
||||
@@ -551,4 +554,9 @@ void ED_view3d_draw_bgpic_test(
|
||||
struct ARegion *ar, struct View3D *v3d,
|
||||
const bool do_foreground, const bool do_camera_frame);
|
||||
|
||||
/* view3d_gizmo_preselect_type.c */
|
||||
void ED_view3d_gizmo_mesh_preselect_get_active(
|
||||
struct bContext *C, struct wmGizmo *gz,
|
||||
struct Base **r_base, struct BMElem **r_ele);
|
||||
|
||||
#endif /* __ED_VIEW3D_H__ */
|
||||
|
||||
@@ -89,48 +89,15 @@ static bool edbm_preselect_or_active(
|
||||
Base **r_base,
|
||||
BMElem **r_ele)
|
||||
{
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
ARegion *ar = CTX_wm_region(C);
|
||||
wmGizmoMap *gzmap = ar->gizmo_map;
|
||||
wmGizmoGroup *gzgroup = gzmap ? WM_gizmomap_group_find(gzmap, "VIEW3D_GGT_mesh_preselect_elem") : NULL;
|
||||
if (gzgroup != NULL) {
|
||||
wmGizmo *gz = gzgroup->gizmos.first;
|
||||
const int object_index = RNA_int_get(gz->ptr, "object_index");
|
||||
|
||||
/* weak, allocate an array just to access the index. */
|
||||
Base *base = NULL;
|
||||
Object *obedit = NULL;
|
||||
{
|
||||
uint bases_len;
|
||||
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(view_layer, CTX_wm_view3d(C), &bases_len);
|
||||
if (object_index < bases_len) {
|
||||
base = bases[object_index];
|
||||
obedit = base->object;
|
||||
}
|
||||
MEM_freeN(bases);
|
||||
}
|
||||
|
||||
*r_base = base;
|
||||
*r_ele = NULL;
|
||||
|
||||
if (obedit) {
|
||||
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
||||
BMesh *bm = em->bm;
|
||||
const int vert_index = RNA_int_get(gz->ptr, "vert_index");
|
||||
const int edge_index = RNA_int_get(gz->ptr, "edge_index");
|
||||
const int face_index = RNA_int_get(gz->ptr, "face_index");
|
||||
if (vert_index != -1) {
|
||||
*r_ele = (BMElem *)BM_vert_at_index_find(bm, vert_index);
|
||||
}
|
||||
else if (edge_index != -1) {
|
||||
*r_ele = (BMElem *)BM_edge_at_index_find(bm, edge_index);
|
||||
}
|
||||
else if (face_index != -1) {
|
||||
*r_ele = (BMElem *)BM_face_at_index_find(bm, face_index);
|
||||
}
|
||||
}
|
||||
ED_view3d_gizmo_mesh_preselect_get_active(C, gz, r_base, r_ele);
|
||||
}
|
||||
else {
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
Base *base = view_layer->basact;
|
||||
Object *obedit = base->object;
|
||||
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
||||
|
||||
@@ -423,3 +423,62 @@ void ED_gizmotypes_preselect_3d(void)
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Gizmo Accessors
|
||||
*
|
||||
* This avoids each user of the gizmo needing to write their own look-ups to access
|
||||
* the information from this gizmo.
|
||||
* \{ */
|
||||
|
||||
void ED_view3d_gizmo_mesh_preselect_get_active(
|
||||
bContext *C, wmGizmo *gz,
|
||||
Base **r_base, BMElem **r_ele)
|
||||
{
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
|
||||
const int object_index = RNA_int_get(gz->ptr, "object_index");
|
||||
|
||||
/* weak, allocate an array just to access the index. */
|
||||
Base *base = NULL;
|
||||
Object *obedit = NULL;
|
||||
{
|
||||
uint bases_len;
|
||||
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(view_layer, CTX_wm_view3d(C), &bases_len);
|
||||
if (object_index < bases_len) {
|
||||
base = bases[object_index];
|
||||
obedit = base->object;
|
||||
}
|
||||
MEM_freeN(bases);
|
||||
}
|
||||
|
||||
*r_base = base;
|
||||
*r_ele = NULL;
|
||||
|
||||
if (obedit) {
|
||||
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
||||
BMesh *bm = em->bm;
|
||||
PropertyRNA *prop;
|
||||
|
||||
/* Ring select only defines edge, check properties exist first. */
|
||||
prop = RNA_struct_find_property(gz->ptr, "vert_index");
|
||||
const int vert_index = prop ? RNA_property_int_get(gz->ptr, prop) : -1;
|
||||
prop = RNA_struct_find_property(gz->ptr, "edge_index");
|
||||
const int edge_index = prop ? RNA_property_int_get(gz->ptr, prop) : -1;
|
||||
prop = RNA_struct_find_property(gz->ptr, "face_index");
|
||||
const int face_index = prop ? RNA_property_int_get(gz->ptr, prop) : -1;
|
||||
|
||||
if (vert_index != -1) {
|
||||
*r_ele = (BMElem *)BM_vert_at_index_find(bm, vert_index);
|
||||
}
|
||||
else if (edge_index != -1) {
|
||||
*r_ele = (BMElem *)BM_edge_at_index_find(bm, edge_index);
|
||||
}
|
||||
else if (face_index != -1) {
|
||||
*r_ele = (BMElem *)BM_face_at_index_find(bm, face_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
Reference in New Issue
Block a user