Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/mesh/meshtools.c
| Show First 20 Lines • Show All 1,008 Lines • ▼ Show 20 Lines | |||||
| /* returns 0 if not found, otherwise 1 */ | /* returns 0 if not found, otherwise 1 */ | ||||
| /** | /** | ||||
| * Face selection in object mode, | * Face selection in object mode, | ||||
| * currently only weight-paint and vertex-paint use this. | * currently only weight-paint and vertex-paint use this. | ||||
| * | * | ||||
| * \return boolean true == Found | * \return boolean true == Found | ||||
| */ | */ | ||||
| bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size) | bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], unsigned int *index, int dist_px) | ||||
| { | { | ||||
| ViewContext vc; | ViewContext vc; | ||||
| Mesh *me = ob->data; | Mesh *me = ob->data; | ||||
| BLI_assert(me && GS(me->id.name) == ID_ME); | BLI_assert(me && GS(me->id.name) == ID_ME); | ||||
| if (!me || me->totpoly == 0) | if (!me || me->totpoly == 0) | ||||
| return false; | return false; | ||||
| ED_view3d_viewcontext_init(C, &vc); | ED_view3d_viewcontext_init(C, &vc); | ||||
| if (size) { | if (dist_px) { | ||||
| /* sample rect to increase chances of selecting, so that when clicking | /* sample rect to increase chances of selecting, so that when clicking | ||||
| * on an edge in the backbuf, we can still select a face */ | * on an edge in the backbuf, we can still select a face */ | ||||
| float dummy_dist; | ED_view3d_select_id_validate(&vc); | ||||
| *index = ED_view3d_backbuf_sample_rect(&vc, mval, size, 1, me->totpoly + 1, &dummy_dist); | |||||
| *index = ED_view3d_select_id_read_nearest( | |||||
| &vc, mval, 1, me->totpoly + 1, &dist_px); | |||||
| } | } | ||||
| else { | else { | ||||
| /* sample only on the exact position */ | /* sample only on the exact position */ | ||||
| *index = ED_view3d_backbuf_sample(&vc, mval[0], mval[1]); | *index = ED_view3d_select_id_sample(&vc, mval[0], mval[1]); | ||||
| } | } | ||||
| if ((*index) == 0 || (*index) > (unsigned int)me->totpoly) | if ((*index) == 0 || (*index) > (unsigned int)me->totpoly) | ||||
| return false; | return false; | ||||
| (*index)--; | (*index)--; | ||||
| return true; | return true; | ||||
| } | } | ||||
| static void ed_mesh_pick_face_vert__mpoly_find( | static void ed_mesh_pick_face_vert__mpoly_find( | ||||
| /* context */ | /* context */ | ||||
| struct ARegion *ar, const float mval[2], | struct ARegion *ar, const float mval[2], | ||||
| /* mesh data (evaluated) */ | /* mesh data (evaluated) */ | ||||
| const MPoly *mp, | const MPoly *mp, | ||||
| const MVert *mvert, const MLoop *mloop, | const MVert *mvert, const MLoop *mloop, | ||||
| /* return values */ | /* return values */ | ||||
| float *r_len_best, int *r_v_idx_best) | float *r_len_best, int *r_v_idx_best) | ||||
| Show All 12 Lines | if (ED_view3d_project_float_object(ar, co, sco, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Use when the back buffer stores face index values. but we want a vert. | * Use when the back buffer stores face index values. but we want a vert. | ||||
| * This gets the face then finds the closest vertex to mval. | * This gets the face then finds the closest vertex to mval. | ||||
| */ | */ | ||||
| bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size) | bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int dist_px) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_depsgraph(C); | ||||
| unsigned int poly_index; | unsigned int poly_index; | ||||
| Mesh *me = ob->data; | Mesh *me = ob->data; | ||||
| BLI_assert(me && GS(me->id.name) == ID_ME); | BLI_assert(me && GS(me->id.name) == ID_ME); | ||||
| if (ED_mesh_pick_face(C, ob, mval, &poly_index, size)) { | if (ED_mesh_pick_face(C, ob, mval, &poly_index, dist_px)) { | ||||
| Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); | Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); | ||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | ||||
| struct ARegion *ar = CTX_wm_region(C); | struct ARegion *ar = CTX_wm_region(C); | ||||
| /* derived mesh to find deformed locations */ | /* derived mesh to find deformed locations */ | ||||
| Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH_ORIGINDEX); | Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH_ORIGINDEX); | ||||
| int v_idx_best = ORIGINDEX_NONE; | int v_idx_best = ORIGINDEX_NONE; | ||||
| ▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | if (ED_view3d_project_float_object(data->ar, co, sco, V3D_PROJ_TEST_CLIP_DEFAULT) == V3D_PROJ_RET_OK) { | ||||
| const float len = len_manhattan_v2v2(data->mval_f, sco); | const float len = len_manhattan_v2v2(data->mval_f, sco); | ||||
| if (len < data->len_best) { | if (len < data->len_best) { | ||||
| data->len_best = len; | data->len_best = len; | ||||
| data->v_idx_best = index; | data->v_idx_best = index; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size, bool use_zbuf) | bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int dist_px, bool use_zbuf) | ||||
| { | { | ||||
| ViewContext vc; | ViewContext vc; | ||||
| Mesh *me = ob->data; | Mesh *me = ob->data; | ||||
| BLI_assert(me && GS(me->id.name) == ID_ME); | BLI_assert(me && GS(me->id.name) == ID_ME); | ||||
| if (!me || me->totvert == 0) | if (!me || me->totvert == 0) | ||||
| return false; | return false; | ||||
| ED_view3d_viewcontext_init(C, &vc); | ED_view3d_viewcontext_init(C, &vc); | ||||
| if (use_zbuf) { | if (use_zbuf) { | ||||
| if (size > 0) { | if (dist_px > 0) { | ||||
| /* sample rect to increase chances of selecting, so that when clicking | /* sample rect to increase chances of selecting, so that when clicking | ||||
| * on an face in the backbuf, we can still select a vert */ | * on an face in the backbuf, we can still select a vert */ | ||||
| float dummy_dist; | ED_view3d_select_id_validate(&vc); | ||||
| *index = ED_view3d_backbuf_sample_rect(&vc, mval, size, 1, me->totvert + 1, &dummy_dist); | |||||
| *index = ED_view3d_select_id_read_nearest( | |||||
| &vc, mval, 1, me->totvert + 1, &dist_px); | |||||
| } | } | ||||
| else { | else { | ||||
| /* sample only on the exact position */ | /* sample only on the exact position */ | ||||
| *index = ED_view3d_backbuf_sample(&vc, mval[0], mval[1]); | *index = ED_view3d_select_id_sample(&vc, mval[0], mval[1]); | ||||
| } | } | ||||
| if ((*index) == 0 || (*index) > (unsigned int)me->totvert) | if ((*index) == 0 || (*index) > (unsigned int)me->totvert) | ||||
| return false; | return false; | ||||
| (*index)--; | (*index)--; | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines | |||||