From ad33e6834861041d3e2660ae150a0a1903b27bcb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 23 May 2022 12:43:28 +1000 Subject: Cleanup: remove "texture" from ED_mesh_uv_texture_* funcitons This name made sense when UV's and textures were stored in the same layer (MTFace & TFace). --- source/blender/editors/mesh/editmesh_add.c | 18 +++++++-------- source/blender/editors/mesh/editmesh_add_gizmo.c | 2 +- source/blender/editors/mesh/mesh_data.cc | 28 +++++++++++------------- 3 files changed, 23 insertions(+), 25 deletions(-) (limited to 'source/blender/editors/mesh') diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index b2f33428b21..57e0d04727c 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -113,7 +113,7 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op) em = BKE_editmesh_from_object(obedit); if (calc_uvs) { - ED_mesh_uv_texture_ensure(obedit->data, NULL); + ED_mesh_uv_ensure(obedit->data, NULL); } if (!EDBM_op_call_and_selectf( @@ -178,7 +178,7 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op) em = BKE_editmesh_from_object(obedit); if (calc_uvs) { - ED_mesh_uv_texture_ensure(obedit->data, NULL); + ED_mesh_uv_ensure(obedit->data, NULL); } if (!EDBM_op_call_and_selectf(em, @@ -252,7 +252,7 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op) em = BKE_editmesh_from_object(obedit); if (calc_uvs) { - ED_mesh_uv_texture_ensure(obedit->data, NULL); + ED_mesh_uv_ensure(obedit->data, NULL); } if (!EDBM_op_call_and_selectf( @@ -324,7 +324,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op) em = BKE_editmesh_from_object(obedit); if (calc_uvs) { - ED_mesh_uv_texture_ensure(obedit->data, NULL); + ED_mesh_uv_ensure(obedit->data, NULL); } if (!EDBM_op_call_and_selectf(em, @@ -400,7 +400,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op) em = BKE_editmesh_from_object(obedit); if (calc_uvs) { - ED_mesh_uv_texture_ensure(obedit->data, NULL); + ED_mesh_uv_ensure(obedit->data, NULL); } if (!EDBM_op_call_and_selectf(em, @@ -476,7 +476,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op) em = BKE_editmesh_from_object(obedit); if (calc_uvs) { - ED_mesh_uv_texture_ensure(obedit->data, NULL); + ED_mesh_uv_ensure(obedit->data, NULL); } if (!EDBM_op_call_and_selectf( @@ -553,7 +553,7 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op) em = BKE_editmesh_from_object(obedit); if (calc_uvs) { - ED_mesh_uv_texture_ensure(obedit->data, NULL); + ED_mesh_uv_ensure(obedit->data, NULL); } if (!EDBM_op_call_and_selectf(em, @@ -614,7 +614,7 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op) em = BKE_editmesh_from_object(obedit); if (calc_uvs) { - ED_mesh_uv_texture_ensure(obedit->data, NULL); + ED_mesh_uv_ensure(obedit->data, NULL); } if (!EDBM_op_call_and_selectf( @@ -682,7 +682,7 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op) em = BKE_editmesh_from_object(obedit); if (calc_uvs) { - ED_mesh_uv_texture_ensure(obedit->data, NULL); + ED_mesh_uv_ensure(obedit->data, NULL); } if (!EDBM_op_call_and_selectf( diff --git a/source/blender/editors/mesh/editmesh_add_gizmo.c b/source/blender/editors/mesh/editmesh_add_gizmo.c index d0f37314661..f5090c0143d 100644 --- a/source/blender/editors/mesh/editmesh_add_gizmo.c +++ b/source/blender/editors/mesh/editmesh_add_gizmo.c @@ -328,7 +328,7 @@ static int add_primitive_cube_gizmo_exec(bContext *C, wmOperator *op) const bool calc_uvs = RNA_boolean_get(op->ptr, "calc_uvs"); if (calc_uvs) { - ED_mesh_uv_texture_ensure(obedit->data, NULL); + ED_mesh_uv_ensure(obedit->data, NULL); } if (!EDBM_op_call_and_selectf(em, diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc index ae06cf4c3bd..67834bf05ce 100644 --- a/source/blender/editors/mesh/mesh_data.cc +++ b/source/blender/editors/mesh/mesh_data.cc @@ -241,7 +241,7 @@ void ED_mesh_uv_loop_reset(bContext *C, Mesh *me) WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); } -int ED_mesh_uv_texture_add( +int ED_mesh_uv_add( Mesh *me, const char *name, const bool active_set, const bool do_init, ReportList *reports) { /* NOTE: keep in sync with #ED_mesh_color_add. */ @@ -307,7 +307,7 @@ int ED_mesh_uv_texture_add( return layernum_dst; } -void ED_mesh_uv_texture_ensure(Mesh *me, const char *name) +void ED_mesh_uv_ensure(Mesh *me, const char *name) { BMEditMesh *em; int layernum_dst; @@ -317,18 +317,18 @@ void ED_mesh_uv_texture_ensure(Mesh *me, const char *name) layernum_dst = CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPUV); if (layernum_dst == 0) { - ED_mesh_uv_texture_add(me, name, true, true, nullptr); + ED_mesh_uv_add(me, name, true, true, nullptr); } } else { layernum_dst = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); if (layernum_dst == 0) { - ED_mesh_uv_texture_add(me, name, true, true, nullptr); + ED_mesh_uv_add(me, name, true, true, nullptr); } } } -bool ED_mesh_uv_texture_remove_index(Mesh *me, const int n) +bool ED_mesh_uv_remove_index(Mesh *me, const int n) { CustomData *ldata = GET_CD_DATA(me, ldata); CustomDataLayer *cdlu; @@ -348,24 +348,22 @@ bool ED_mesh_uv_texture_remove_index(Mesh *me, const int n) return true; } -bool ED_mesh_uv_texture_remove_active(Mesh *me) +bool ED_mesh_uv_remove_active(Mesh *me) { - /* texpoly/uv are assumed to be in sync */ CustomData *ldata = GET_CD_DATA(me, ldata); const int n = CustomData_get_active_layer(ldata, CD_MLOOPUV); if (n != -1) { - return ED_mesh_uv_texture_remove_index(me, n); + return ED_mesh_uv_remove_index(me, n); } return false; } -bool ED_mesh_uv_texture_remove_named(Mesh *me, const char *name) +bool ED_mesh_uv_remove_named(Mesh *me, const char *name) { - /* texpoly/uv are assumed to be in sync */ CustomData *ldata = GET_CD_DATA(me, ldata); const int n = CustomData_get_named_layer(ldata, CD_MLOOPUV, name); if (n != -1) { - return ED_mesh_uv_texture_remove_index(me, n); + return ED_mesh_uv_remove_index(me, n); } return false; } @@ -373,7 +371,7 @@ bool ED_mesh_uv_texture_remove_named(Mesh *me, const char *name) int ED_mesh_color_add( Mesh *me, const char *name, const bool active_set, const bool do_init, ReportList *reports) { - /* NOTE: keep in sync with #ED_mesh_uv_texture_add. */ + /* NOTE: keep in sync with #ED_mesh_uv_add. */ BMEditMesh *em; int layernum; @@ -516,7 +514,7 @@ static bool sculpt_vertex_color_remove_poll(bContext *C) int ED_mesh_sculpt_color_add( Mesh *me, const char *name, const bool active_set, const bool do_init, ReportList *reports) { - /* NOTE: keep in sync with #ED_mesh_uv_texture_add. */ + /* NOTE: keep in sync with #ED_mesh_uv_add. */ BMEditMesh *em; int layernum; @@ -650,7 +648,7 @@ static int mesh_uv_texture_add_exec(bContext *C, wmOperator *op) Object *ob = ED_object_context(C); Mesh *me = static_cast(ob->data); - if (ED_mesh_uv_texture_add(me, nullptr, true, true, op->reports) == -1) { + if (ED_mesh_uv_add(me, nullptr, true, true, op->reports) == -1) { return OPERATOR_CANCELLED; } @@ -683,7 +681,7 @@ static int mesh_uv_texture_remove_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_context(C); Mesh *me = static_cast(ob->data); - if (!ED_mesh_uv_texture_remove_active(me)) { + if (!ED_mesh_uv_remove_active(me)) { return OPERATOR_CANCELLED; } -- cgit v1.2.3 From ceff1c2f65459b9eb6b12c3baff5f7af360ae738 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 May 2022 12:46:55 +1000 Subject: Cleanup: spelling, unbalanced doxy sections --- source/blender/editors/mesh/meshtools.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/mesh') diff --git a/source/blender/editors/mesh/meshtools.cc b/source/blender/editors/mesh/meshtools.cc index fafccf68f03..9e28e1bafdd 100644 --- a/source/blender/editors/mesh/meshtools.cc +++ b/source/blender/editors/mesh/meshtools.cc @@ -418,7 +418,7 @@ int ED_mesh_join_objects_exec(bContext *C, wmOperator *op) } totcol = ob->totcol; - /* obact materials in new main array, is nicer start! */ + /* Active object materials in new main array, is nicer start! */ for (a = 0; a < ob->totcol; a++) { matar[a] = BKE_object_material_get(ob, a + 1); id_us_plus((ID *)matar[a]); -- cgit v1.2.3 From 26c6ec559414126988b2d758c37768638136e801 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 May 2022 17:16:23 +1000 Subject: Cleanup: remove context argument from EDBM_mesh_knife Added in [0] but isn't needed as all needed variables are in the ViewContext. Avoid passing in the context is it makes debugging issues with MESH_OT_knife_project more difficult to investigate since it's possible values written to the ViewContext are ignored. [0]: 6e77afe6ec7b6a73f218f1fef264758abcbc778a --- source/blender/editors/mesh/editmesh_knife.c | 61 ++++++++++------------ .../blender/editors/mesh/editmesh_knife_project.c | 2 +- source/blender/editors/mesh/mesh_intern.h | 3 +- 3 files changed, 31 insertions(+), 35 deletions(-) (limited to 'source/blender/editors/mesh') diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 5d8cf176b87..584642d12fc 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -3810,7 +3810,7 @@ static void knife_reset_snap_angle_input(KnifeTool_OpData *kcd) * If scene orientation is set to anything other than global it takes priority. * Otherwise kcd->constrain_axis_mode is used. */ -static void knife_constrain_axis(bContext *C, KnifeTool_OpData *kcd) +static void knife_constrain_axis(KnifeTool_OpData *kcd) { /* Obtain current mouse position in world space. */ float curr_cage_adjusted[3]; @@ -3819,7 +3819,7 @@ static void knife_constrain_axis(bContext *C, KnifeTool_OpData *kcd) /* Constrain axes. */ Scene *scene = kcd->scene; - ViewLayer *view_layer = CTX_data_view_layer(C); + ViewLayer *view_layer = kcd->vc.view_layer; Object *obedit = (kcd->prev.ob) ? kcd->prev.ob : kcd->vc.obedit; RegionView3D *rv3d = kcd->region->regiondata; const short scene_orientation = BKE_scene_orientation_get_index(scene, SCE_ORIENT_DEFAULT); @@ -3871,7 +3871,7 @@ static void knife_constrain_axis(bContext *C, KnifeTool_OpData *kcd) * In this case the selection-buffer is used to select the face, * then the closest `vert` or `edge` is set, and those will enable `is_co_set`. */ -static bool knife_snap_update_from_mval(bContext *C, KnifeTool_OpData *kcd, const float mval[2]) +static bool knife_snap_update_from_mval(KnifeTool_OpData *kcd, const float mval[2]) { knife_pos_data_clear(&kcd->curr); copy_v2_v2(kcd->curr.mval, mval); @@ -3894,7 +3894,7 @@ static bool knife_snap_update_from_mval(bContext *C, KnifeTool_OpData *kcd, cons } if (kcd->axis_constrained) { - knife_constrain_axis(C, kcd); + knife_constrain_axis(kcd); } } @@ -4075,8 +4075,7 @@ static void knife_init_colors(KnifeColors *colors) } /* called when modal loop selection gets set up... */ -static void knifetool_init(bContext *C, - ViewContext *vc, +static void knifetool_init(ViewContext *vc, KnifeTool_OpData *kcd, const bool only_select, const bool cut_through, @@ -4099,7 +4098,7 @@ static void knifetool_init(bContext *C, kcd->region = vc->region; kcd->objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( - CTX_data_view_layer(C), CTX_wm_view3d(C), &kcd->objects_len); + vc->view_layer, vc->v3d, &kcd->objects_len); Object *ob; BMEditMesh *em; @@ -4241,14 +4240,14 @@ static void knifetool_exit(wmOperator *op) /** \name Mouse-Moving Event Updates * \{ */ -/* Update active knife edge/vert pointers. */ -static int knife_update_active(bContext *C, KnifeTool_OpData *kcd) +/** Update active knife edge/vert pointers. */ +static int knife_update_active(KnifeTool_OpData *kcd) { /* If no hits are found this would normally default to (0, 0, 0) so instead * get a point at the mouse ray closest to the previous point. * Note that drawing lines in `free-space` isn't properly supported * but there's no guarantee (0, 0, 0) has any geometry either - campbell */ - if (!knife_snap_update_from_mval(C, kcd, kcd->mval)) { + if (!knife_snap_update_from_mval(kcd, kcd->mval)) { float origin[3]; float origin_ofs[3]; @@ -4269,20 +4268,20 @@ static int knife_update_active(bContext *C, KnifeTool_OpData *kcd) return 1; } -static void knifetool_update_mval(bContext *C, KnifeTool_OpData *kcd, const float mval[2]) +static void knifetool_update_mval(KnifeTool_OpData *kcd, const float mval[2]) { knife_recalc_ortho(kcd); copy_v2_v2(kcd->mval, mval); - if (knife_update_active(C, kcd)) { + if (knife_update_active(kcd)) { ED_region_tag_redraw(kcd->region); } } -static void knifetool_update_mval_i(bContext *C, KnifeTool_OpData *kcd, const int mval_i[2]) +static void knifetool_update_mval_i(KnifeTool_OpData *kcd, const int mval_i[2]) { const float mval[2] = {UNPACK2(mval_i)}; - knifetool_update_mval(C, kcd, mval); + knifetool_update_mval(kcd, mval); } /** \} */ @@ -4445,7 +4444,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event) snapping_increment_temp <= KNIFE_MAX_ANGLE_SNAPPING_INCREMENT) { kcd->angle_snapping_increment = snapping_increment_temp; } - knife_update_active(C, kcd); + knife_update_active(kcd); knife_update_header(C, op, kcd); ED_region_tag_redraw(kcd->region); return OPERATOR_RUNNING_MODAL; @@ -4486,7 +4485,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_CANCELLED; } knifetool_undo(kcd); - knife_update_active(C, kcd); + knife_update_active(kcd); ED_region_tag_redraw(kcd->region); handled = true; break; @@ -4494,7 +4493,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event) kcd->snap_midpoints = true; knife_recalc_ortho(kcd); - knife_update_active(C, kcd); + knife_update_active(kcd); knife_update_header(C, op, kcd); ED_region_tag_redraw(kcd->region); do_refresh = true; @@ -4504,7 +4503,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event) kcd->snap_midpoints = false; knife_recalc_ortho(kcd); - knife_update_active(C, kcd); + knife_update_active(kcd); knife_update_header(C, op, kcd); ED_region_tag_redraw(kcd->region); do_refresh = true; @@ -4538,7 +4537,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event) RNA_float_get(op->ptr, "angle_snapping_increment")); knifetool_disable_orientation_locking(kcd); knife_reset_snap_angle_input(kcd); - knife_update_active(C, kcd); + knife_update_active(kcd); knife_update_header(C, op, kcd); ED_region_tag_redraw(kcd->region); do_refresh = true; @@ -4623,7 +4622,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event) kcd->is_drag_undo = false; /* Needed because the last face 'hit' is ignored when dragging. */ - knifetool_update_mval(C, kcd, kcd->curr.mval); + knifetool_update_mval(kcd, kcd->curr.mval); } ED_region_tag_redraw(kcd->region); @@ -4636,14 +4635,14 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event) if (kcd->is_drag_hold) { kcd->is_drag_hold = false; kcd->is_drag_undo = false; - knifetool_update_mval(C, kcd, kcd->curr.mval); + knifetool_update_mval(kcd, kcd->curr.mval); } kcd->prev = kcd->curr; kcd->curr = kcd->init; knife_project_v2(kcd, kcd->curr.cage, kcd->curr.mval); - knifetool_update_mval(C, kcd, kcd->curr.mval); + knifetool_update_mval(kcd, kcd->curr.mval); knife_add_cut(kcd); @@ -4679,7 +4678,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_PASS_THROUGH; case MOUSEMOVE: /* Mouse moved somewhere to select another loop. */ if (kcd->mode != MODE_PANNING) { - knifetool_update_mval_i(C, kcd, event->mval); + knifetool_update_mval_i(kcd, event->mval); if (kcd->is_drag_hold) { if (kcd->totlinehit >= 2) { @@ -4706,7 +4705,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event) snapping_increment_temp <= KNIFE_MAX_ANGLE_SNAPPING_INCREMENT) { kcd->angle_snapping_increment = snapping_increment_temp; } - knife_update_active(C, kcd); + knife_update_active(kcd); knife_update_header(C, op, kcd); ED_region_tag_redraw(kcd->region); return OPERATOR_RUNNING_MODAL; @@ -4761,7 +4760,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event) if (do_refresh) { /* We don't really need to update mval, * but this happens to be the best way to refresh at the moment. */ - knifetool_update_mval_i(C, kcd, event->mval); + knifetool_update_mval_i(kcd, event->mval); } /* Keep going until the user confirms. */ @@ -4787,8 +4786,7 @@ static int knifetool_invoke(bContext *C, wmOperator *op, const wmEvent *event) /* alloc new customdata */ kcd = op->customdata = MEM_callocN(sizeof(KnifeTool_OpData), __func__); - knifetool_init(C, - &vc, + knifetool_init(&vc, kcd, only_select, cut_through, @@ -4824,7 +4822,7 @@ static int knifetool_invoke(bContext *C, wmOperator *op, const wmEvent *event) WM_cursor_modal_set(CTX_wm_window(C), WM_CURSOR_KNIFE); WM_event_add_modal_handler(C, op); - knifetool_update_mval_i(C, kcd, event->mval); + knifetool_update_mval_i(kcd, event->mval); if (wait_for_input == false) { /* Avoid copy-paste logic. */ @@ -4942,7 +4940,7 @@ static bool edbm_mesh_knife_point_isect(LinkNode *polys, const float cent_ss[2]) return false; } -void EDBM_mesh_knife(bContext *C, ViewContext *vc, LinkNode *polys, bool use_tag, bool cut_through) +void EDBM_mesh_knife(ViewContext *vc, LinkNode *polys, bool use_tag, bool cut_through) { KnifeTool_OpData *kcd; @@ -4957,8 +4955,7 @@ void EDBM_mesh_knife(bContext *C, ViewContext *vc, LinkNode *polys, bool use_tag kcd = MEM_callocN(sizeof(KnifeTool_OpData), __func__); - knifetool_init(C, - vc, + knifetool_init(vc, kcd, only_select, cut_through, @@ -4984,7 +4981,7 @@ void EDBM_mesh_knife(bContext *C, ViewContext *vc, LinkNode *polys, bool use_tag int i; for (i = 0; i < mval_tot; i++) { - knifetool_update_mval(C, kcd, mval_fl[i]); + knifetool_update_mval(kcd, mval_fl[i]); if (i == 0) { knife_start_cut(kcd); kcd->mode = MODE_DRAGGING; diff --git a/source/blender/editors/mesh/editmesh_knife_project.c b/source/blender/editors/mesh/editmesh_knife_project.c index bce46dd7cf7..c32b1fa99c0 100644 --- a/source/blender/editors/mesh/editmesh_knife_project.c +++ b/source/blender/editors/mesh/editmesh_knife_project.c @@ -142,7 +142,7 @@ static int knifeproject_exec(bContext *C, wmOperator *op) ED_view3d_viewcontext_init_object(&vc, obedit); BMEditMesh *em = BKE_editmesh_from_object(obedit); - EDBM_mesh_knife(C, &vc, polys, true, cut_through); + EDBM_mesh_knife(&vc, polys, true, cut_through); /* select only tagged faces */ BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, false); diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index b39a0b90f6d..5abbfc2cb14 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -170,8 +170,7 @@ void MESH_OT_knife_project(struct wmOperatorType *ot); /** * \param use_tag: When set, tag all faces inside the polylines. */ -void EDBM_mesh_knife(struct bContext *C, - struct ViewContext *vc, +void EDBM_mesh_knife(struct ViewContext *vc, struct LinkNode *polys, bool use_tag, bool cut_through); -- cgit v1.2.3 From aab947eb468c2e9ca068fabc9562562d3e0e739a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 May 2022 17:16:25 +1000 Subject: Fix T98349: Knife project resulting selection is wrong Regression in [0] which removed the call to BVH-tree recalculation before calculating the selection. Instead of recalculating the BVH-tree, postpone recalculating mesh data until after the selection has been calculated. [0]: 6e77afe6ec7b6a73f218f1fef264758abcbc778a --- source/blender/editors/mesh/editmesh_knife.c | 57 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 29 deletions(-) (limited to 'source/blender/editors/mesh') diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 584642d12fc..01276d7640d 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -1383,7 +1383,6 @@ static BMFace *knife_bvh_raycast(KnifeTool_OpData *kcd, uint *r_base_index) { BMFace *face; - BMLoop **ltri; BVHTreeRayHit hit; const float dist = r_dist ? *r_dist : FLT_MAX; hit.dist = dist; @@ -1397,8 +1396,9 @@ static BMFace *knife_bvh_raycast(KnifeTool_OpData *kcd, /* Hits returned in world space. */ if (r_hitout) { - ltri = kcd->bvh.looptris[hit.index]; - interp_v3_v3v3v3_uv(r_hitout, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co, kcd->bvh.uv); + float tri_cos[3][3]; + knife_bm_tri_cagecos_get_worldspace(kcd, kcd->bvh.base_index, hit.index, tri_cos); + interp_v3_v3v3v3_uv(r_hitout, UNPACK3(tri_cos), kcd->bvh.uv); if (r_cagehit) { copy_v3_v3(r_cagehit, hit.co); @@ -1434,7 +1434,6 @@ static BMFace *knife_bvh_raycast_filter(KnifeTool_OpData *kcd, kcd->bvh.filter_data = filter_userdata; BMFace *face; - BMLoop **ltri; BVHTreeRayHit hit; const float dist = r_dist ? *r_dist : FLT_MAX; hit.dist = dist; @@ -1451,8 +1450,9 @@ static BMFace *knife_bvh_raycast_filter(KnifeTool_OpData *kcd, /* Hits returned in world space. */ if (r_hitout) { - ltri = kcd->bvh.looptris[hit.index]; - interp_v3_v3v3v3_uv(r_hitout, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co, kcd->bvh.uv); + float tri_cos[3][3]; + knife_bm_tri_cagecos_get_worldspace(kcd, kcd->bvh.base_index, hit.index, tri_cos); + interp_v3_v3v3v3_uv(r_hitout, UNPACK3(tri_cos), kcd->bvh.uv); if (r_cagehit) { copy_v3_v3(r_cagehit, hit.co); @@ -4290,33 +4290,18 @@ static void knifetool_update_mval_i(KnifeTool_OpData *kcd, const int mval_i[2]) /** \name Finalization * \{ */ -/* Called on tool confirmation. */ -static void knifetool_finish_ex(KnifeTool_OpData *kcd) +static void knifetool_finish_single_pre(KnifeTool_OpData *kcd, Object *ob) { - Object *ob; - BMEditMesh *em; - for (uint b = 0; b < kcd->objects_len; b++) { - ob = kcd->objects[b]; - em = BKE_editmesh_from_object(ob); - - knife_make_cuts(kcd, ob); - - EDBM_selectmode_flush(em); - EDBM_update(ob->data, - &(const struct EDBMUpdate_Params){ - .calc_looptri = true, - .calc_normals = true, - .is_destructive = true, - }); - } + knife_make_cuts(kcd, ob); } -static void knifetool_finish_single_ex(KnifeTool_OpData *kcd, Object *ob, uint UNUSED(base_index)) +/** + * A post version is needed to to delay recalculating tessellation after making cuts. + * Without this, knife-project can't use the BVH tree to select geometry after a cut, see: T98349. + */ +static void knifetool_finish_single_post(KnifeTool_OpData *UNUSED(kcd), Object *ob) { - knife_make_cuts(kcd, ob); - BMEditMesh *em = BKE_editmesh_from_object(ob); - EDBM_selectmode_flush(em); EDBM_update(ob->data, &(const struct EDBMUpdate_Params){ @@ -4326,6 +4311,16 @@ static void knifetool_finish_single_ex(KnifeTool_OpData *kcd, Object *ob, uint U }); } +/* Called on tool confirmation. */ +static void knifetool_finish_ex(KnifeTool_OpData *kcd) +{ + for (uint b = 0; b < kcd->objects_len; b++) { + Object *ob = kcd->objects[b]; + knifetool_finish_single_pre(kcd, ob); + knifetool_finish_single_post(kcd, ob); + } +} + static void knifetool_finish(wmOperator *op) { KnifeTool_OpData *kcd = op->customdata; @@ -5009,7 +5004,7 @@ void EDBM_mesh_knife(ViewContext *vc, LinkNode *polys, bool use_tag, bool cut_th BM_mesh_elem_hflag_enable_all(em->bm, BM_EDGE, BM_ELEM_TAG, false); } - knifetool_finish_single_ex(kcd, ob, b); + knifetool_finish_single_pre(kcd, ob); /* Tag faces inside! */ if (use_tag) { @@ -5098,6 +5093,10 @@ void EDBM_mesh_knife(ViewContext *vc, LinkNode *polys, bool use_tag, bool cut_th #undef F_ISECT_SET_UNKNOWN #undef F_ISECT_SET_OUTSIDE } + + /* Defer freeing data until the BVH tree is finished with, see: #point_is_visible and + * the doc-string for #knifetool_finish_single_post. */ + knifetool_finish_single_post(kcd, ob); } knifetool_exit_ex(kcd); -- cgit v1.2.3 From adaf92b4abe54dfc5c920bfa721c1ffc30413676 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 May 2022 17:47:27 +1000 Subject: Cleanup: knife tool - Use early return and continue to reduce right-shift. - Rename `lv` to `tri_cos` for storing triangle coordinates. - Reduce variable scope. --- source/blender/editors/mesh/editmesh_knife.c | 368 ++++++++++++++------------- 1 file changed, 185 insertions(+), 183 deletions(-) (limited to 'source/blender/editors/mesh') diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 39d104cdcce..7972459e457 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -377,45 +377,45 @@ static void knifetool_raycast_planes(const KnifeTool_OpData *kcd, float r_v1[3], kcd->vc.rv3d->persmat, planes[2], planes[0], planes[1], planes[3], NULL, NULL); /* Ray-cast all planes. */ + float ray_dir[3]; + float ray_hit_best[2][3] = {{UNPACK3(kcd->prev.cage)}, {UNPACK3(kcd->curr.cage)}}; + float lambda_best[2] = {-FLT_MAX, FLT_MAX}; + int i; + { - float ray_dir[3]; - float ray_hit_best[2][3] = {{UNPACK3(kcd->prev.cage)}, {UNPACK3(kcd->curr.cage)}}; - float lambda_best[2] = {-FLT_MAX, FLT_MAX}; - int i; + float curr_cage_adjust[3]; + float co_depth[3]; - { - float curr_cage_adjust[3]; - float co_depth[3]; + copy_v3_v3(co_depth, kcd->prev.cage); + ED_view3d_win_to_3d(kcd->vc.v3d, kcd->region, co_depth, kcd->curr.mval, curr_cage_adjust); - copy_v3_v3(co_depth, kcd->prev.cage); - ED_view3d_win_to_3d(kcd->vc.v3d, kcd->region, co_depth, kcd->curr.mval, curr_cage_adjust); + sub_v3_v3v3(ray_dir, curr_cage_adjust, kcd->prev.cage); + } - sub_v3_v3v3(ray_dir, curr_cage_adjust, kcd->prev.cage); + for (i = 0; i < 4; i++) { + float ray_hit[3]; + float lambda_test; + if (!isect_ray_plane_v3(kcd->prev.cage, ray_dir, planes[i], &lambda_test, false)) { + continue; } - for (i = 0; i < 4; i++) { - float ray_hit[3]; - float lambda_test; - if (isect_ray_plane_v3(kcd->prev.cage, ray_dir, planes[i], &lambda_test, false)) { - madd_v3_v3v3fl(ray_hit, kcd->prev.cage, ray_dir, lambda_test); - if (lambda_test < 0.0f) { - if (lambda_test > lambda_best[0]) { - copy_v3_v3(ray_hit_best[0], ray_hit); - lambda_best[0] = lambda_test; - } - } - else { - if (lambda_test < lambda_best[1]) { - copy_v3_v3(ray_hit_best[1], ray_hit); - lambda_best[1] = lambda_test; - } - } + madd_v3_v3v3fl(ray_hit, kcd->prev.cage, ray_dir, lambda_test); + if (lambda_test < 0.0f) { + if (lambda_test > lambda_best[0]) { + copy_v3_v3(ray_hit_best[0], ray_hit); + lambda_best[0] = lambda_test; + } + } + else { + if (lambda_test < lambda_best[1]) { + copy_v3_v3(ray_hit_best[1], ray_hit); + lambda_best[1] = lambda_test; } } - - copy_v3_v3(r_v1, ray_hit_best[0]); - copy_v3_v3(r_v2, ray_hit_best[1]); } + + copy_v3_v3(r_v1, ray_hit_best[0]); + copy_v3_v3(r_v2, ray_hit_best[1]); } static void knifetool_draw_angle_snapping(const KnifeTool_OpData *kcd) @@ -440,43 +440,45 @@ static void knifetool_draw_angle_snapping(const KnifeTool_OpData *kcd) static void knifetool_draw_orientation_locking(const KnifeTool_OpData *kcd) { - if (!compare_v3v3(kcd->prev.cage, kcd->curr.cage, KNIFE_FLT_EPSBIG)) { - float v1[3], v2[3]; + if (compare_v3v3(kcd->prev.cage, kcd->curr.cage, KNIFE_FLT_EPSBIG)) { + return; + } - /* This is causing buggy behavior when `prev.cage` and `curr.cage` are too close together. */ - knifetool_raycast_planes(kcd, v1, v2); + float v1[3], v2[3]; - uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); + /* This is causing buggy behavior when `prev.cage` and `curr.cage` are too close together. */ + knifetool_raycast_planes(kcd, v1, v2); - switch (kcd->constrain_axis) { - case KNF_CONSTRAIN_AXIS_X: { - immUniformColor3ubv(kcd->colors.xaxis); - break; - } - case KNF_CONSTRAIN_AXIS_Y: { - immUniformColor3ubv(kcd->colors.yaxis); - break; - } - case KNF_CONSTRAIN_AXIS_Z: { - immUniformColor3ubv(kcd->colors.zaxis); - break; - } - default: { - immUniformColor3ubv(kcd->colors.axis_extra); - break; - } + uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); + + switch (kcd->constrain_axis) { + case KNF_CONSTRAIN_AXIS_X: { + immUniformColor3ubv(kcd->colors.xaxis); + break; + } + case KNF_CONSTRAIN_AXIS_Y: { + immUniformColor3ubv(kcd->colors.yaxis); + break; + } + case KNF_CONSTRAIN_AXIS_Z: { + immUniformColor3ubv(kcd->colors.zaxis); + break; } + default: { + immUniformColor3ubv(kcd->colors.axis_extra); + break; + } + } - GPU_line_width(2.0); + GPU_line_width(2.0); - immBegin(GPU_PRIM_LINES, 2); - immVertex3fv(pos, v1); - immVertex3fv(pos, v2); - immEnd(); + immBegin(GPU_PRIM_LINES, 2); + immVertex3fv(pos, v1); + immVertex3fv(pos, v2); + immEnd(); - immUnbindProgram(); - } + immUnbindProgram(); } static void knifetool_draw_visible_distances(const KnifeTool_OpData *kcd) @@ -1226,7 +1228,6 @@ static void knife_bvh_init(KnifeTool_OpData *kcd) } /* Construct BVH Tree. */ - float cos[3][3]; const float epsilon = FLT_EPSILON * 2.0f; int tottri = 0; int ob_tottri = 0; @@ -1283,8 +1284,10 @@ static void knife_bvh_init(KnifeTool_OpData *kcd) if (!test_fn_ret) { continue; } - knife_bm_tri_cagecos_get_worldspace(kcd, b, i, cos); - BLI_bvhtree_insert(kcd->bvh.tree, i + tottri, (float *)cos, 3); + + float tri_cos[3][3]; + knife_bm_tri_cagecos_get_worldspace(kcd, b, i, tri_cos); + BLI_bvhtree_insert(kcd->bvh.tree, i + tottri, &tri_cos[0][0], 3); } tottri += em->tottri; @@ -1307,6 +1310,10 @@ static void knife_bvh_raycast_cb(void *userdata, const BVHTreeRay *ray, BVHTreeRayHit *hit) { + if (index != -1) { + return; + } + KnifeTool_OpData *kcd = userdata; BMLoop **ltri; Object *ob; @@ -1315,60 +1322,49 @@ static void knife_bvh_raycast_cb(void *userdata, float dist, uv[2]; bool isect; int tottri; - float tri_cos[3][3]; - if (index != -1) { - tottri = 0; - uint b = 0; - for (; b < kcd->objects_len; b++) { - index -= tottri; - ob = kcd->objects[b]; - em = BKE_editmesh_from_object(ob); - tottri = em->tottri; - if (index < tottri) { - ltri = em->looptris[index]; - break; - } + tottri = 0; + uint b = 0; + for (; b < kcd->objects_len; b++) { + index -= tottri; + ob = kcd->objects[b]; + em = BKE_editmesh_from_object(ob); + tottri = em->tottri; + if (index < tottri) { + ltri = em->looptris[index]; + break; } + } - if (kcd->bvh.filter_cb) { - if (!kcd->bvh.filter_cb(ltri[0]->f, kcd->bvh.filter_data)) { - return; - } + if (kcd->bvh.filter_cb) { + if (!kcd->bvh.filter_cb(ltri[0]->f, kcd->bvh.filter_data)) { + return; } + } - knife_bm_tri_cagecos_get_worldspace(kcd, b, index, tri_cos); - - isect = - (ray->radius > 0.0f ? - isect_ray_tri_epsilon_v3(ray->origin, - ray->direction, - tri_cos[0], - tri_cos[1], - tri_cos[2], - &dist, - uv, - ray->radius) : + float tri_cos[3][3]; + knife_bm_tri_cagecos_get_worldspace(kcd, b, index, tri_cos); + isect = (ray->radius > 0.0f ? + isect_ray_tri_epsilon_v3( + ray->origin, ray->direction, UNPACK3(tri_cos), &dist, uv, ray->radius) : #ifdef USE_KDOPBVH_WATERTIGHT - isect_ray_tri_watertight_v3( - ray->origin, ray->isect_precalc, tri_cos[0], tri_cos[1], tri_cos[2], &dist, uv)); + isect_ray_tri_watertight_v3( + ray->origin, ray->isect_precalc, UNPACK3(tri_cos), &dist, uv)); #else - isect_ray_tri_v3( - ray->origin, ray->direction, tri_cos[0], tri_cos[1], tri_cos[2], &dist, uv)); + isect_ray_tri_v3(ray->origin, ray->direction, UNPACK3(tri_cos), &dist, uv); #endif - if (isect && dist < hit->dist) { - hit->dist = dist; - hit->index = index; + if (isect && dist < hit->dist) { + hit->dist = dist; + hit->index = index; - copy_v3_v3(hit->no, ltri[0]->f->no); + copy_v3_v3(hit->no, ltri[0]->f->no); - madd_v3_v3v3fl(hit->co, ray->origin, ray->direction, dist); + madd_v3_v3v3fl(hit->co, ray->origin, ray->direction, dist); - kcd->bvh.looptris = em->looptris; - copy_v2_v2(kcd->bvh.uv, uv); - kcd->bvh.base_index = b; - } + kcd->bvh.looptris = em->looptris; + copy_v2_v2(kcd->bvh.uv, uv); + kcd->bvh.base_index = b; } } @@ -1978,29 +1974,30 @@ static void prepare_linehits_for_cut(KnifeTool_OpData *kcd) * Also remove all but one of a series of vertex hits for the same vertex. */ for (int i = 0; i < n; i++) { KnifeLineHit *lhi = &linehits[i]; - if (lhi->v) { - for (int j = i - 1; j >= 0; j--) { - KnifeLineHit *lhj = &linehits[j]; - if (!lhj->kfe || fabsf(lhi->l - lhj->l) > KNIFE_FLT_EPSBIG || - fabsf(lhi->m - lhj->m) > KNIFE_FLT_EPSBIG) { - break; - } + if (lhi->v == NULL) { + continue; + } - if (lhi->kfe == lhj->kfe) { - lhj->l = -1.0f; - is_double = true; - } + for (int j = i - 1; j >= 0; j--) { + KnifeLineHit *lhj = &linehits[j]; + if (!lhj->kfe || fabsf(lhi->l - lhj->l) > KNIFE_FLT_EPSBIG || + fabsf(lhi->m - lhj->m) > KNIFE_FLT_EPSBIG) { + break; } - for (int j = i + 1; j < n; j++) { - KnifeLineHit *lhj = &linehits[j]; - if (fabsf(lhi->l - lhj->l) > KNIFE_FLT_EPSBIG || - fabsf(lhi->m - lhj->m) > KNIFE_FLT_EPSBIG) { - break; - } - if ((lhj->kfe && (lhi->kfe == lhj->kfe)) || (lhi->v == lhj->v)) { - lhj->l = -1.0f; - is_double = true; - } + + if (lhi->kfe == lhj->kfe) { + lhj->l = -1.0f; + is_double = true; + } + } + for (int j = i + 1; j < n; j++) { + KnifeLineHit *lhj = &linehits[j]; + if (fabsf(lhi->l - lhj->l) > KNIFE_FLT_EPSBIG || fabsf(lhi->m - lhj->m) > KNIFE_FLT_EPSBIG) { + break; + } + if ((lhj->kfe && (lhi->kfe == lhj->kfe)) || (lhi->v == lhj->v)) { + lhj->l = -1.0f; + is_double = true; } } } @@ -2272,11 +2269,12 @@ static void knife_make_face_cuts(KnifeTool_OpData *kcd, BMesh *bm, BMFace *f, Li /* Remove dangling edges, not essential - but nice for users. */ for (i = 0; i < edge_array_len_orig; i++) { - if (kfe_array[i]) { - if (BM_edge_is_wire(kfe_array[i]->e)) { - BM_edge_kill(bm, kfe_array[i]->e); - kfe_array[i]->e = NULL; - } + if (kfe_array[i] == NULL) { + continue; + } + if (BM_edge_is_wire(kfe_array[i]->e)) { + BM_edge_kill(bm, kfe_array[i]->e); + kfe_array[i]->e = NULL; } } @@ -2588,7 +2586,7 @@ static bool knife_ray_intersect_face(KnifeTool_OpData *kcd, BLI_assert(tri_i >= 0 && tri_i < tottri); for (; tri_i < tottri; tri_i++) { - float lv[3][3]; + float tri_cos[3][3]; float ray_tri_uv[2]; tri = em->looptris[tri_i]; @@ -2596,22 +2594,22 @@ static bool knife_ray_intersect_face(KnifeTool_OpData *kcd, break; } - knife_bm_tri_cagecos_get_worldspace(kcd, base_index, tri_i, lv); + knife_bm_tri_cagecos_get_worldspace(kcd, base_index, tri_i, tri_cos); /* Using epsilon test in case ray is directly through an internal * tessellation edge and might not hit either tessellation tri with * an exact test; * We will exclude hits near real edges by a later test. */ if (isect_ray_tri_epsilon_v3( - v1, raydir, lv[0], lv[1], lv[2], &lambda, ray_tri_uv, KNIFE_FLT_EPS)) { + v1, raydir, UNPACK3(tri_cos), &lambda, ray_tri_uv, KNIFE_FLT_EPS)) { /* Check if line coplanar with tri. */ - normal_tri_v3(tri_norm, lv[0], lv[1], lv[2]); - plane_from_point_normal_v3(tri_plane, lv[0], tri_norm); + normal_tri_v3(tri_norm, UNPACK3(tri_cos)); + plane_from_point_normal_v3(tri_plane, tri_cos[0], tri_norm); if ((dist_squared_to_plane_v3(v1, tri_plane) < KNIFE_FLT_EPS) && (dist_squared_to_plane_v3(v2, tri_plane) < KNIFE_FLT_EPS)) { return false; } - interp_v3_v3v3v3_uv(hit_cageco, lv[0], lv[1], lv[2], ray_tri_uv); + interp_v3_v3v3v3_uv(hit_cageco, UNPACK3(tri_cos), ray_tri_uv); /* Now check that far enough away from verts and edges. */ list = knife_get_face_kedges(kcd, ob, base_index, f); for (ref = list->first; ref; ref = ref->next) { @@ -5028,17 +5026,19 @@ void EDBM_mesh_knife(ViewContext *vc, LinkNode *polys, bool use_tag, bool cut_th /* Tag all faces linked to cut edges. */ BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { /* Check are we tagged?, then we are an original face. */ - if (BM_elem_flag_test(e, BM_ELEM_TAG) == false) { - BMFace *f; - BMIter fiter; - BM_ITER_ELEM (f, &fiter, e, BM_FACES_OF_EDGE) { - float cent[3], cent_ss[2]; - BM_face_calc_point_in_face(f, cent); - mul_m4_v3(ob->obmat, cent); - knife_project_v2(kcd, cent, cent_ss); - if (edbm_mesh_knife_point_isect(polys, cent_ss)) { - BM_elem_flag_enable(f, BM_ELEM_TAG); - } + if (BM_elem_flag_test(e, BM_ELEM_TAG)) { + continue; + } + + BMFace *f; + BMIter fiter; + BM_ITER_ELEM (f, &fiter, e, BM_FACES_OF_EDGE) { + float cent[3], cent_ss[2]; + BM_face_calc_point_in_face(f, cent); + mul_m4_v3(ob->obmat, cent); + knife_project_v2(kcd, cent, cent_ss); + if (edbm_mesh_knife_point_isect(polys, cent_ss)) { + BM_elem_flag_enable(f, BM_ELEM_TAG); } } } @@ -5048,43 +5048,45 @@ void EDBM_mesh_knife(ViewContext *vc, LinkNode *polys, bool use_tag, bool cut_th BMFace *f; keep_search = false; BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { - if (BM_elem_flag_test(f, BM_ELEM_TAG) == false && (F_ISECT_IS_UNKNOWN(f))) { - /* Am I connected to a tagged face via an un-tagged edge - * (ie, not across a cut)? */ - BMLoop *l_first = BM_FACE_FIRST_LOOP(f); - BMLoop *l_iter = l_first; - bool found = false; - - do { - if (BM_elem_flag_test(l_iter->e, BM_ELEM_TAG) != false) { - /* Now check if the adjacent faces is tagged. */ - BMLoop *l_radial_iter = l_iter->radial_next; - if (l_radial_iter != l_iter) { - do { - if (BM_elem_flag_test(l_radial_iter->f, BM_ELEM_TAG)) { - found = true; - } - } while ((l_radial_iter = l_radial_iter->radial_next) != l_iter && - (found == false)); - } - } - } while ((l_iter = l_iter->next) != l_first && (found == false)); - - if (found) { - float cent[3], cent_ss[2]; - BM_face_calc_point_in_face(f, cent); - mul_m4_v3(ob->obmat, cent); - knife_project_v2(kcd, cent, cent_ss); - if ((kcd->cut_through || point_is_visible(kcd, cent, cent_ss, (BMElem *)f)) && - edbm_mesh_knife_point_isect(polys, cent_ss)) { - BM_elem_flag_enable(f, BM_ELEM_TAG); - keep_search = true; - } - else { - /* Don't lose time on this face again, set it as outside. */ - F_ISECT_SET_OUTSIDE(f); + if (BM_elem_flag_test(f, BM_ELEM_TAG) || !F_ISECT_IS_UNKNOWN(f)) { + continue; + } + + /* Am I connected to a tagged face via an un-tagged edge + * (ie, not across a cut)? */ + BMLoop *l_first = BM_FACE_FIRST_LOOP(f); + BMLoop *l_iter = l_first; + bool found = false; + + do { + if (BM_elem_flag_test(l_iter->e, BM_ELEM_TAG) != false) { + /* Now check if the adjacent faces is tagged. */ + BMLoop *l_radial_iter = l_iter->radial_next; + if (l_radial_iter != l_iter) { + do { + if (BM_elem_flag_test(l_radial_iter->f, BM_ELEM_TAG)) { + found = true; + } + } while ((l_radial_iter = l_radial_iter->radial_next) != l_iter && + (found == false)); } } + } while ((l_iter = l_iter->next) != l_first && (found == false)); + + if (found) { + float cent[3], cent_ss[2]; + BM_face_calc_point_in_face(f, cent); + mul_m4_v3(ob->obmat, cent); + knife_project_v2(kcd, cent, cent_ss); + if ((kcd->cut_through || point_is_visible(kcd, cent, cent_ss, (BMElem *)f)) && + edbm_mesh_knife_point_isect(polys, cent_ss)) { + BM_elem_flag_enable(f, BM_ELEM_TAG); + keep_search = true; + } + else { + /* Don't lose time on this face again, set it as outside. */ + F_ISECT_SET_OUTSIDE(f); + } } } } while (keep_search); -- cgit v1.2.3 From 38a2576acef020566497f1d0c8c2c492de74b769 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 May 2022 21:15:57 +1000 Subject: Fix display error after sorting mesh elements Sorting faces caused the tessellation data to be outdated, making faces show the wrong materials. Re-calculate tessellation when re-ordering faces. --- source/blender/editors/mesh/editmesh_tools.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source/blender/editors/mesh') diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index cafcc4ec578..feecefdb7ea 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -7032,6 +7032,14 @@ static void sort_bmelem_flag(bContext *C, } BM_mesh_remap(em->bm, map[0], map[1], map[2]); + + EDBM_update(ob->data, + &(const struct EDBMUpdate_Params){ + .calc_looptri = (totelem[2] != 0), + .calc_normals = false, + .is_destructive = true, + }); + DEG_id_tag_update(ob->data, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); -- cgit v1.2.3