Blender V5.3
editmesh_path.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_mesh_types.h"
10#include "DNA_object_types.h"
11#include "DNA_scene_types.h"
13
14#ifdef WITH_FREESTYLE
15# include "DNA_meshdata_types.h"
16#endif
17
18#include "BLI_linklist.hh"
19#include "BLI_math_vector_c.hh"
20
21#include "BKE_context.hh"
22#include "BKE_customdata.hh"
23#include "BKE_editmesh.hh"
24#include "BKE_layer.hh"
25#include "BKE_mesh_types.hh"
26#include "BKE_report.hh"
27
28#include "ED_mesh.hh"
29#include "ED_object.hh"
30#include "ED_screen.hh"
31#include "ED_select_utils.hh"
32#include "ED_uvedit.hh"
33#include "ED_view3d.hh"
34
35#include "RNA_access.hh"
36#include "RNA_define.hh"
37
38#include "WM_api.hh"
39#include "WM_types.hh"
40
41#include "bmesh.hh"
42#include "bmesh_tools.hh"
43
44#include "DEG_depsgraph.hh"
45
46#include "mesh_intern.hh" /* own include */
47
48namespace blender {
49
50/* -------------------------------------------------------------------- */
53
54enum {
61};
62
72
74{
75 static const EnumPropertyItem edge_tag_items[] = {
76 {EDGE_MODE_SELECT, "SELECT", 0, "Select", ""},
77 {EDGE_MODE_TAG_SEAM, "SEAM", 0, "Tag Seam", ""},
78 {EDGE_MODE_TAG_SHARP, "SHARP", 0, "Tag Sharp", ""},
79 {EDGE_MODE_TAG_CREASE, "CREASE", 0, "Tag Crease", ""},
80 {EDGE_MODE_TAG_BEVEL, "BEVEL", 0, "Tag Bevel", ""},
81 {EDGE_MODE_TAG_FREESTYLE, "FREESTYLE", 0, "Tag Freestyle Edge Mark", ""},
82 {0, nullptr, 0, nullptr, nullptr},
83 };
84
86 "edge_mode",
87 edge_tag_items,
89 "Edge Tag",
90 "The edge flag to tag when selecting the shortest path");
91
93 "use_face_step",
94 false,
95 "Face Stepping",
96 "Traverse connected faces (includes diagonals and edge-rings)");
98 "use_topology_distance",
99 false,
100 "Topology Distance",
101 "Find the minimum number of steps, ignoring spatial distance");
103 "use_fill",
104 false,
105 "Fill Region",
106 "Select all paths between the source/destination elements");
108}
109
111 ToolSettings *ts,
112 PathSelectParams *op_params)
113{
114 {
115 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "edge_mode");
116 if (RNA_property_is_set(op->ptr, prop)) {
117 op_params->edge_mode = RNA_property_enum_get(op->ptr, prop);
118 if (op->flag & OP_IS_INVOKE) {
119 ts->edge_mode = op_params->edge_mode;
120 }
121 }
122 else {
123 op_params->edge_mode = ts->edge_mode;
124 RNA_property_enum_set(op->ptr, prop, op_params->edge_mode);
125 }
126 }
127
128 op_params->track_active = false;
129 op_params->use_face_step = RNA_boolean_get(op->ptr, "use_face_step");
130 op_params->use_fill = RNA_boolean_get(op->ptr, "use_fill");
131 op_params->use_topology_distance = RNA_boolean_get(op->ptr, "use_topology_distance");
133}
134
136 wmOperator * /*op*/,
137 const PropertyRNA *prop)
138{
139 const char *prop_id = RNA_property_identifier(prop);
140 if (STREQ(prop_id, "edge_mode")) {
141 const Scene *scene = CTX_data_scene(C);
142 ToolSettings *ts = scene->toolsettings;
143 if ((ts->selectmode & SCE_SELECT_EDGE) == 0) {
144 return false;
145 }
146 }
147 return true;
148}
149
156
158
159/* -------------------------------------------------------------------- */
162
163/* callbacks */
164static bool verttag_filter_cb(BMVert *v, void * /*user_data_v*/)
165{
167}
168static bool verttag_test_cb(BMVert *v, void * /*user_data_v*/)
169{
171}
172static void verttag_set_cb(BMVert *v, bool val, void *user_data_v)
173{
174 UserData *user_data = static_cast<UserData *>(user_data_v);
175 BM_vert_select_set(user_data->bm, v, val);
176}
177
178static void mouse_mesh_shortest_path_vert(Scene * /*scene*/,
179 Object *obedit,
180 const PathSelectParams *op_params,
181 BMVert *v_act,
182 BMVert *v_dst)
183{
186
187 int cd_offset = -1;
188 switch (op_params->edge_mode) {
189 case EDGE_MODE_SELECT:
192#ifdef WITH_FREESTYLE
194#endif
195 break;
197 cd_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_FLOAT, "crease_edge");
198 break;
200 cd_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_FLOAT, "bevel_weight_edge");
201 break;
202 }
203
204 UserData user_data = {bm, id_cast<Mesh *>(obedit->data), cd_offset, op_params};
205 LinkNode *path = nullptr;
206 bool is_path_ordered = false;
207
208 if (v_act && (v_act != v_dst)) {
209 if (op_params->use_fill) {
211 reinterpret_cast<BMElem *>(v_act),
212 reinterpret_cast<BMElem *>(v_dst),
214 &user_data);
215 }
216 else {
217 is_path_ordered = true;
218 BMCalcPathParams params{};
220 params.use_step_face = op_params->use_face_step;
221 path = BM_mesh_calc_path_vert(bm, v_act, v_dst, &params, verttag_filter_cb, &user_data);
222 }
223
224 if (path) {
225 if (op_params->track_active) {
227 }
228 }
229 }
230
231 BMVert *v_dst_last = v_dst;
232
233 if (path) {
234 /* toggle the flag */
235 bool all_set = true;
236 LinkNode *node;
237
238 node = path;
239 do {
240 if (!verttag_test_cb(static_cast<BMVert *>(node->link), &user_data)) {
241 all_set = false;
242 break;
243 }
244 } while ((node = node->next));
245
246 int depth = -1;
247 node = path;
248 do {
249 if ((is_path_ordered == false) ||
251 {
252 verttag_set_cb(static_cast<BMVert *>(node->link), !all_set, &user_data);
253 if (is_path_ordered) {
254 v_dst_last = static_cast<BMVert *>(node->link);
255 }
256 }
257 } while ((void)depth++, (node = node->next));
258
259 BLI_linklist_free(path, nullptr);
260 }
261 else {
262 const bool is_act = !verttag_test_cb(v_dst, &user_data);
263 verttag_set_cb(v_dst, is_act, &user_data); /* switch the face option */
264 }
265
268
269 if (op_params->track_active) {
270 /* even if this is selected it may not be in the selection list */
271 if (BM_elem_flag_test(v_dst_last, BM_ELEM_SELECT) == 0) {
272 BM_select_history_remove(bm, v_dst_last);
273 }
274 else {
275 BM_select_history_store(bm, v_dst_last);
276 }
277 }
278
279 EDBMUpdate_Params params{};
280 params.calc_looptris = false;
281 params.calc_normals = false;
282 params.is_destructive = false;
283 EDBM_update(id_cast<Mesh *>(obedit->data), &params);
284}
285
287
288/* -------------------------------------------------------------------- */
291
292/* callbacks */
293static bool edgetag_filter_cb(BMEdge *e, void * /*user_data_v*/)
294{
296}
297static bool edgetag_test_cb(BMEdge *e, void *user_data_v)
298{
299 UserData *user_data = static_cast<UserData *>(user_data_v);
300 const char edge_mode = user_data->op_params->edge_mode;
301
302 switch (edge_mode) {
303 case EDGE_MODE_SELECT:
304 return BM_elem_flag_test(e, BM_ELEM_SELECT) ? true : false;
306 return BM_elem_flag_test(e, BM_ELEM_SEAM) ? true : false;
308 return BM_elem_flag_test(e, BM_ELEM_SMOOTH) ? false : true;
311 return BM_ELEM_CD_GET_FLOAT(e, user_data->cd_offset);
312#ifdef WITH_FREESTYLE
314 return BM_ELEM_CD_GET_BOOL(e, user_data->cd_offset);
315 }
316#endif
317 }
318 return false;
319}
320static void edgetag_set_cb(BMEdge *e, bool val, void *user_data_v)
321{
322 UserData *user_data = static_cast<UserData *>(user_data_v);
323 const char edge_mode = user_data->op_params->edge_mode;
324 BMesh *bm = user_data->bm;
325
326 switch (edge_mode) {
327 case EDGE_MODE_SELECT:
328 BM_edge_select_set(bm, e, val);
329 break;
332 break;
335 break;
338 BM_ELEM_CD_SET_FLOAT(e, user_data->cd_offset, (val) ? 1.0f : 0.0f);
339 break;
340#ifdef WITH_FREESTYLE
342 BM_ELEM_CD_SET_BOOL(e, user_data->cd_offset, val);
343 break;
344 }
345#endif
346 }
347}
348
349static void edgetag_ensure_cd_flag(Mesh *mesh, const char edge_mode)
350{
352
353 switch (edge_mode) {
355 if (!CustomData_has_layer_named(&bm->edata, CD_PROP_FLOAT, "crease_edge")) {
356 BM_data_layer_add_named(bm, &bm->edata, CD_PROP_FLOAT, "crease_edge");
357 }
358 break;
360 if (!CustomData_has_layer_named(&bm->edata, CD_PROP_FLOAT, "bevel_weight_edge")) {
361 BM_data_layer_add_named(bm, &bm->edata, CD_PROP_FLOAT, "bevel_weight_edge");
362 }
363 break;
364#ifdef WITH_FREESTYLE
366 if (!CustomData_has_layer_named(&bm->edata, CD_PROP_BOOL, "freestyle_edge")) {
367 BM_data_layer_add_named(bm, &bm->edata, CD_PROP_BOOL, "freestyle_edge");
368 }
369 break;
370#endif
371 default:
372 break;
373 }
374}
375
376/* Mesh shortest path select, uses previously-selected edge. */
377
378/* since you want to create paths with multiple selects, it doesn't have extend option */
380 Scene *scene, Object *obedit, const PathSelectParams *op_params, BMEdge *e_act, BMEdge *e_dst)
381{
384
385 edgetag_ensure_cd_flag(id_cast<Mesh *>(obedit->data), op_params->edge_mode);
386
387 int cd_offset = -1;
388 switch (op_params->edge_mode) {
389 case EDGE_MODE_SELECT:
392#ifdef WITH_FREESTYLE
394 cd_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_BOOL, "freestyle_edge");
395#endif
396 break;
398 cd_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_FLOAT, "crease_edge");
399 break;
401 cd_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_FLOAT, "bevel_weight_edge");
402 break;
403 }
404
405 UserData user_data = {bm, id_cast<Mesh *>(obedit->data), cd_offset, op_params};
406 LinkNode *path = nullptr;
407 bool is_path_ordered = false;
408
409 if (e_act && (e_act != e_dst)) {
410 if (op_params->use_fill) {
412 reinterpret_cast<BMElem *>(e_act),
413 reinterpret_cast<BMElem *>(e_dst),
415 &user_data);
416 }
417 else {
418 is_path_ordered = true;
419 BMCalcPathParams params{};
421 params.use_step_face = op_params->use_face_step;
422 path = BM_mesh_calc_path_edge(bm, e_act, e_dst, &params, edgetag_filter_cb, &user_data);
423 }
424
425 if (path) {
426 if (op_params->track_active) {
428 }
429 }
430 }
431
432 BMEdge *e_dst_last = e_dst;
433
434 if (path) {
435 /* toggle the flag */
436 bool all_set = true;
437 LinkNode *node;
438
439 node = path;
440 do {
441 if (!edgetag_test_cb(static_cast<BMEdge *>(node->link), &user_data)) {
442 all_set = false;
443 break;
444 }
445 } while ((node = node->next));
446
447 int depth = -1;
448 node = path;
449 do {
450 if ((is_path_ordered == false) ||
452 {
453 edgetag_set_cb(static_cast<BMEdge *>(node->link), !all_set, &user_data);
454 if (is_path_ordered) {
455 e_dst_last = static_cast<BMEdge *>(node->link);
456 }
457 }
458 } while ((void)depth++, (node = node->next));
459
460 BLI_linklist_free(path, nullptr);
461 }
462 else {
463 const bool is_act = !edgetag_test_cb(e_dst, &user_data);
464 edgetag_set_cb(e_dst, is_act, &user_data); /* switch the edge option */
465 }
466
467 if (op_params->edge_mode != EDGE_MODE_SELECT) {
468 if (op_params->track_active) {
469 /* simple rules - last edge is _always_ active and selected */
470 if (e_act) {
471 BM_edge_select_set(bm, e_act, false);
472 }
473 BM_edge_select_set(bm, e_dst_last, true);
474 BM_select_history_store(bm, e_dst_last);
475 }
476 }
477
480
481 if (op_params->track_active) {
482 /* even if this is selected it may not be in the selection list */
483 if (op_params->edge_mode == EDGE_MODE_SELECT) {
484 if (edgetag_test_cb(e_dst_last, &user_data) == 0) {
485 BM_select_history_remove(bm, e_dst_last);
486 }
487 else {
488 BM_select_history_store(bm, e_dst_last);
489 }
490 }
491 }
492
493 EDBMUpdate_Params params{};
494 params.calc_looptris = false;
495 params.calc_normals = false;
496 params.is_destructive = false;
497 EDBM_update(id_cast<Mesh *>(obedit->data), &params);
498
499 if (op_params->edge_mode == EDGE_MODE_TAG_SEAM) {
500 ED_uvedit_live_unwrap(scene, {obedit});
501 }
502}
503
505
506/* -------------------------------------------------------------------- */
509
510/* callbacks */
511static bool facetag_filter_cb(BMFace *f, void * /*user_data_v*/)
512{
514}
515// static bool facetag_test_cb(Scene * /*scene*/, BMesh * /*bm*/, BMFace *f)
516static bool facetag_test_cb(BMFace *f, void * /*user_data_v*/)
517{
519}
520// static void facetag_set_cb(BMesh *bm, Scene * /*scene*/, BMFace *f, const bool val)
521static void facetag_set_cb(BMFace *f, bool val, void *user_data_v)
522{
523 UserData *user_data = static_cast<UserData *>(user_data_v);
524 BM_face_select_set(user_data->bm, f, val);
525}
526
527static void mouse_mesh_shortest_path_face(Scene * /*scene*/,
528 Object *obedit,
529 const PathSelectParams *op_params,
530 BMFace *f_act,
531 BMFace *f_dst)
532{
535
536 int cd_offset = -1;
537 switch (op_params->edge_mode) {
538 case EDGE_MODE_SELECT:
541#ifdef WITH_FREESTYLE
543#endif
544 break;
546 cd_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_FLOAT, "crease_edge");
547 break;
549 cd_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_FLOAT, "bevel_weight_edge");
550 break;
551 }
552
553 UserData user_data = {bm, id_cast<Mesh *>(obedit->data), cd_offset, op_params};
554 LinkNode *path = nullptr;
555 bool is_path_ordered = false;
556
557 if (f_act) {
558 if (op_params->use_fill) {
560 reinterpret_cast<BMElem *>(f_act),
561 reinterpret_cast<BMElem *>(f_dst),
563 &user_data);
564 }
565 else {
566 is_path_ordered = true;
567 BMCalcPathParams params{};
569 params.use_step_face = op_params->use_face_step;
570 path = BM_mesh_calc_path_face(bm, f_act, f_dst, &params, facetag_filter_cb, &user_data);
571 }
572
573 if (f_act != f_dst) {
574 if (path) {
575 if (op_params->track_active) {
577 }
578 }
579 }
580 }
581
582 BMFace *f_dst_last = f_dst;
583
584 if (path) {
585 /* toggle the flag */
586 bool all_set = true;
587 LinkNode *node;
588
589 node = path;
590 do {
591 if (!facetag_test_cb(static_cast<BMFace *>(node->link), &user_data)) {
592 all_set = false;
593 break;
594 }
595 } while ((node = node->next));
596
597 int depth = -1;
598 node = path;
599 do {
600 if ((is_path_ordered == false) ||
602 {
603 facetag_set_cb(static_cast<BMFace *>(node->link), !all_set, &user_data);
604 if (is_path_ordered) {
605 f_dst_last = static_cast<BMFace *>(node->link);
606 }
607 }
608 } while ((void)depth++, (node = node->next));
609
610 BLI_linklist_free(path, nullptr);
611 }
612 else {
613 const bool is_act = !facetag_test_cb(f_dst, &user_data);
614 facetag_set_cb(f_dst, is_act, &user_data); /* switch the face option */
615 }
616
619
620 if (op_params->track_active) {
621 /* even if this is selected it may not be in the selection list */
622 if (facetag_test_cb(f_dst_last, &user_data) == 0) {
623 BM_select_history_remove(bm, f_dst_last);
624 }
625 else {
626 BM_select_history_store(bm, f_dst_last);
627 }
628 BM_mesh_active_face_set(bm, f_dst_last);
629
631 em->mat_nr = f_dst_last->mat_nr;
632 }
633
634 EDBMUpdate_Params params{};
635 params.calc_looptris = false;
636 params.calc_normals = false;
637 params.is_destructive = false;
638 EDBM_update(id_cast<Mesh *>(obedit->data), &params);
639}
640
642
643/* -------------------------------------------------------------------- */
646
648 Object *obedit,
649 const PathSelectParams *op_params,
650 BMElem *ele_src,
651 BMElem *ele_dst)
652{
653 bool ok = false;
654
655 if (ELEM(nullptr, ele_src, ele_dst) || (ele_src->head.htype != ele_dst->head.htype)) {
656 /* pass */
657 }
658 else if (ele_src->head.htype == BM_VERT) {
660 obedit,
661 op_params,
662 reinterpret_cast<BMVert *>(ele_src),
663 reinterpret_cast<BMVert *>(ele_dst));
664 ok = true;
665 }
666 else if (ele_src->head.htype == BM_EDGE) {
668 obedit,
669 op_params,
670 reinterpret_cast<BMEdge *>(ele_src),
671 reinterpret_cast<BMEdge *>(ele_dst));
672 ok = true;
673 }
674 else if (ele_src->head.htype == BM_FACE) {
676 obedit,
677 op_params,
678 reinterpret_cast<BMFace *>(ele_src),
679 reinterpret_cast<BMFace *>(ele_dst));
680 ok = true;
681 }
682
683 if (ok) {
686 }
687
688 return ok;
689}
690
691static wmOperatorStatus edbm_shortest_path_pick_exec(bContext *C, wmOperator *op);
692
693static BMElem *edbm_elem_find_nearest(ViewContext *vc, const char htype)
694{
695 BMEditMesh *em = vc->em;
696 float dist = ED_view3d_select_dist_px();
697
698 if ((em->selectmode & SCE_SELECT_VERTEX) && (htype == BM_VERT)) {
699 return reinterpret_cast<BMElem *>(EDBM_vert_find_nearest(vc, &dist));
700 }
701 if ((em->selectmode & SCE_SELECT_EDGE) && (htype == BM_EDGE)) {
702 return reinterpret_cast<BMElem *>(EDBM_edge_find_nearest(vc, &dist));
703 }
704 if ((em->selectmode & SCE_SELECT_FACE) && (htype == BM_FACE)) {
705 return reinterpret_cast<BMElem *>(EDBM_face_find_nearest(vc, &dist));
706 }
707
708 return nullptr;
709}
710
712{
714
715 if ((ele == nullptr) && bm->act_face && BM_elem_flag_test(bm->act_face, BM_ELEM_SELECT)) {
716 ele = reinterpret_cast<BMElem *>(bm->act_face);
717 }
718
719 return ele;
720}
721
723 wmOperator *op,
724 const wmEvent *event)
725{
726 if (RNA_struct_property_is_set(op->ptr, "index")) {
728 }
729
730 BMVert *eve = nullptr;
731 BMEdge *eed = nullptr;
732 BMFace *efa = nullptr;
733
734 bool track_active = true;
735
737 copy_v2_v2_int(vc.mval, event->mval);
740 BMEditMesh *em = vc.em;
742
744
745 {
746 int base_index = -1;
748 *vc.bmain, vc.scene, vc.view_layer, vc.v3d);
749 if (EDBM_unified_findnearest(&vc, bases, &base_index, &eve, &eed, &efa)) {
750 basact = bases[base_index];
752 em = vc.em;
753 }
754 }
755
756 /* If nothing is selected, let's select the picked vertex/edge/face. */
757 if ((bm->totvertsel == 0) && (eve || eed || efa)) {
758 /* TODO(dfelinto): right now we try to find the closest element twice.
759 * The ideal is to refactor EDBM_select_pick so it doesn't
760 * have to pick the nearest vert/edge/face again. */
761 const SelectPick_Params params = {
762 /*sel_op*/ SEL_OP_ADD,
763 };
764 EDBM_select_pick(C, event->mval, params);
765 return OPERATOR_FINISHED;
766 }
767
768 PathSelectParams op_params;
769 path_select_params_from_op(op, vc.scene->toolsettings, &op_params);
770
771 BMElem *ele_src, *ele_dst;
772 if (!(ele_src = edbm_elem_active_elem_or_face_get(bm)) ||
773 !(ele_dst = edbm_elem_find_nearest(&vc, ele_src->head.htype)))
774 {
775 /* special case, toggle edge tags even when we don't have a path */
776 if (((em->selectmode & SCE_SELECT_EDGE) && (op_params.edge_mode != EDGE_MODE_SELECT)) &&
777 /* check if we only have a destination edge */
778 ((ele_src == nullptr) && (ele_dst = edbm_elem_find_nearest(&vc, BM_EDGE))))
779 {
780 ele_src = ele_dst;
781 track_active = false;
782 }
783 else {
785 }
786 }
787
788 op_params.track_active = track_active;
789
790 if (!edbm_shortest_path_pick_ex(vc.scene, vc.obedit, &op_params, ele_src, ele_dst)) {
792 }
793
795 if (BKE_view_layer_active_base_get(vc.view_layer) != basact) {
797 }
798
799 /* to support redo */
801 int index = EDBM_elem_to_index_any(bm, ele_dst);
802
803 RNA_int_set(op->ptr, "index", index);
804
805 return OPERATOR_FINISHED;
806}
807
809{
810 Scene *scene = CTX_data_scene(C);
811 Object *obedit = CTX_data_edit_object(C);
813
814 const int index = RNA_int_get(op->ptr, "index");
815 if (index < 0 || index >= (bm->totvert + bm->totedge + bm->totface)) {
816 return OPERATOR_CANCELLED;
817 }
818
819 BMElem *ele_src, *ele_dst;
820 if (!(ele_src = edbm_elem_active_elem_or_face_get(bm)) ||
821 !(ele_dst = EDBM_elem_from_index_any(bm, index)))
822 {
823 return OPERATOR_CANCELLED;
824 }
825
826 PathSelectParams op_params;
827 path_select_params_from_op(op, scene->toolsettings, &op_params);
828 op_params.track_active = true;
829
830 if (!edbm_shortest_path_pick_ex(scene, obedit, &op_params, ele_src, ele_dst)) {
831 return OPERATOR_CANCELLED;
832 }
833
834 return OPERATOR_FINISHED;
835}
836
838{
839 PropertyRNA *prop;
840
841 /* identifiers */
842 ot->name = "Pick Shortest Path";
843 ot->idname = "MESH_OT_shortest_path_pick";
844 ot->description = "Select shortest path between two selections";
845
846 /* API callbacks. */
851
852 /* flags */
854
855 /* properties */
857
858 /* use for redo */
859 prop = RNA_def_int(ot->srna, "index", -1, -1, INT_MAX, "", "", 0, INT_MAX);
861}
862
864
865/* -------------------------------------------------------------------- */
868
870{
871 const Main *bmain = CTX_data_main(C);
872 Scene *scene = CTX_data_scene(C);
873 bool found_valid_elements = false;
874
875 ViewLayer *view_layer = CTX_data_view_layer(C);
877 *bmain, scene, view_layer, CTX_wm_view3d(C));
878 for (Object *obedit : objects) {
881 BMIter iter;
882 BMEditSelection *ese_src, *ese_dst;
883 BMElem *ele_src = nullptr, *ele_dst = nullptr, *ele;
884
885 if ((bm->totvertsel == 0) && (bm->totedgesel == 0) && (bm->totfacesel == 0)) {
886 continue;
887 }
888
889 /* first try to find vertices in edit selection */
890 ese_src = bm->selected.last();
891 if (ese_src && (ese_dst = ese_src->prev) && (ese_src->htype == ese_dst->htype)) {
892 ele_src = ese_src->ele;
893 ele_dst = ese_dst->ele;
894 }
895 else {
896 /* if selection history isn't available, find two selected elements */
897 ele_src = ele_dst = nullptr;
898 if ((em->selectmode & SCE_SELECT_VERTEX) && (bm->totvertsel >= 2)) {
899 BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) {
901 if (ele_src == nullptr) {
902 ele_src = ele;
903 }
904 else if (ele_dst == nullptr) {
905 ele_dst = ele;
906 }
907 else {
908 break;
909 }
910 }
911 }
912 }
913
914 if ((ele_dst == nullptr) && (em->selectmode & SCE_SELECT_EDGE) && (bm->totedgesel >= 2)) {
915 ele_src = nullptr;
916 BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) {
918 if (ele_src == nullptr) {
919 ele_src = ele;
920 }
921 else if (ele_dst == nullptr) {
922 ele_dst = ele;
923 }
924 else {
925 break;
926 }
927 }
928 }
929 }
930
931 if ((ele_dst == nullptr) && (em->selectmode & SCE_SELECT_FACE) && (bm->totfacesel >= 2)) {
932 ele_src = nullptr;
933 BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) {
935 if (ele_src == nullptr) {
936 ele_src = ele;
937 }
938 else if (ele_dst == nullptr) {
939 ele_dst = ele;
940 }
941 else {
942 break;
943 }
944 }
945 }
946 }
947 }
948
949 if (ele_src && ele_dst) {
950 PathSelectParams op_params;
951 path_select_params_from_op(op, scene->toolsettings, &op_params);
952
953 edbm_shortest_path_pick_ex(scene, obedit, &op_params, ele_src, ele_dst);
954
955 found_valid_elements = true;
956 }
957 }
958
959 if (!found_valid_elements) {
961 op->reports, RPT_WARNING, "Path selection requires two matching elements to be selected");
962 return OPERATOR_CANCELLED;
963 }
964
965 return OPERATOR_FINISHED;
966}
967
969{
970 /* identifiers */
971 ot->name = "Select Shortest Path";
972 ot->idname = "MESH_OT_shortest_path_select";
973 ot->description = "Select shortest path between two vertices/edges/faces";
974
975 /* API callbacks. */
979
980 /* flags */
982
983 /* properties */
985}
986
988
989} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
Object is a sort of wrapper for general info.
#define C
Definition RandGen.cpp:29
#define NC_GEOM
Definition WM_types.hh:406
#define ND_SELECT
Definition WM_types.hh:551
#define ELEM(...)
#define STREQ(a, b)
#define BM_ELEM_CD_GET_BOOL(ele, offset)
#define BM_ELEM_CD_SET_FLOAT(ele, offset, f)
#define BM_ELEM_CD_GET_FLOAT(ele, offset)
#define BM_ELEM_CD_SET_BOOL(ele, offset, f)
#define BM_elem_flag_set(ele, hflag, val)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_test_bool(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BM_select_history_store(bm, ele)
#define BM_select_history_remove(bm, ele)
#define INT_MAX
void base_activate(bContext *C, Base *base)
bool material_active_index_set(Object *ob, int index)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
static void facetag_set_cb(BMFace *f, bool val, void *user_data_v)
bool EDBM_select_pick(bContext *C, const int mval[2], const SelectPick_Params &params)
static void edgetag_set_cb(BMEdge *e, bool val, void *user_data_v)
@ RPT_WARNING
Definition BKE_report.hh:40
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void EDBM_selectmode_flush(BMesh *bm, short selectmode)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
static bool facetag_test_cb(BMFace *f, void *)
@ EDGE_MODE_TAG_SEAM
@ EDGE_MODE_TAG_FREESTYLE
@ EDGE_MODE_TAG_BEVEL
@ EDGE_MODE_TAG_CREASE
@ EDGE_MODE_TAG_SHARP
const char * RNA_property_identifier(const PropertyRNA *prop)
static void mouse_mesh_shortest_path_face(Scene *, Object *obedit, const PathSelectParams *op_params, BMFace *f_act, BMFace *f_dst)
void EDBM_update(Mesh *mesh, const EDBMUpdate_Params *params)
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
static bool edgetag_test_cb(BMEdge *e, void *user_data_v)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
int RNA_int_get(PointerRNA *ptr, const char *name)
void view3d_operator_needs_gpu(const bContext *C)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
ATTR_WARN_UNUSED_RESULT const BMVert * v
static BMElem * edbm_elem_active_elem_or_face_get(BMesh *bm)
void WM_operator_properties_checker_interval(wmOperatorType *ot, bool nth_can_disable)
LinkNode * BM_mesh_calc_path_region_edge(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, bool(*filter_fn)(BMEdge *, void *user_data), void *user_data)
BMVert * EDBM_vert_find_nearest(ViewContext *vc, float *dist_px_manhattan_p)
ViewLayer * CTX_data_view_layer(const bContext *C)
static BMElem * edbm_elem_find_nearest(ViewContext *vc, const char htype)
static void path_select_properties(wmOperatorType *ot)
void ED_view3d_viewcontext_init_object(ViewContext *vc, Object *obact)
LinkNode * BM_mesh_calc_path_face(BMesh *bm, BMFace *f_src, BMFace *f_dst, const BMCalcPathParams *params, bool(*filter_fn)(BMFace *, void *user_data), void *user_data)
LinkNode * BM_mesh_calc_path_vert(BMesh *bm, BMVert *v_src, BMVert *v_dst, const BMCalcPathParams *params, bool(*filter_fn)(BMVert *, void *user_data), void *user_data)
void ED_uvedit_live_unwrap(const Scene *scene, Span< Object * > objects)
bool ED_operator_editmesh(bContext *C)
void MESH_OT_shortest_path_select(wmOperatorType *ot)
static bool edgetag_filter_cb(BMEdge *e, void *)
bool EDBM_unified_findnearest(ViewContext *vc, Span< Base * > bases, int *r_base_index, BMVert **r_eve, BMEdge **r_eed, BMFace **r_efa)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BM_mesh_active_face_set(BMesh *bm, BMFace *f)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
bool WM_operator_properties_checker_interval_test(const CheckerIntervalParams *op_params, int depth)
Object * CTX_data_edit_object(const bContext *C)
int CustomData_get_offset_named(const CustomData *data, eCustomDataType type, StringRef name)
void BM_face_select_set(BMesh *bm, BMFace *f, const bool select)
Select Face.
BMElem * EDBM_elem_from_index_any(BMesh *bm, uint index)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
static wmOperatorStatus edbm_shortest_path_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
static bool edbm_shortest_path_pick_ex(Scene *scene, Object *obedit, const PathSelectParams *op_params, BMElem *ele_src, BMElem *ele_dst)
static void edgetag_ensure_cd_flag(Mesh *mesh, const char edge_mode)
static void mouse_mesh_shortest_path_edge(Scene *scene, Object *obedit, const PathSelectParams *op_params, BMEdge *e_act, BMEdge *e_dst)
static bool facetag_filter_cb(BMFace *f, void *)
static void verttag_set_cb(BMVert *v, bool val, void *user_data_v)
static void path_select_params_from_op(wmOperator *op, ToolSettings *ts, PathSelectParams *op_params)
static bool path_select_poll_property(const bContext *C, wmOperator *, const PropertyRNA *prop)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static void mouse_mesh_shortest_path_vert(Scene *, Object *obedit, const PathSelectParams *op_params, BMVert *v_act, BMVert *v_dst)
BMEdge * EDBM_edge_find_nearest(ViewContext *vc, float *dist_px_manhattan_p)
void MESH_OT_shortest_path_pick(wmOperatorType *ot)
void BM_vert_select_set(BMesh *bm, BMVert *v, const bool select)
Select Vert.
BMFace * EDBM_face_find_nearest(ViewContext *vc, float *dist_px_manhattan_p)
int EDBM_elem_to_index_any(BMesh *bm, BMElem *ele)
LinkNode * BM_mesh_calc_path_edge(BMesh *bm, BMEdge *e_src, BMEdge *e_dst, const BMCalcPathParams *params, bool(*filter_fn)(BMEdge *, void *user_data), void *user_data)
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:59
static wmOperatorStatus edbm_shortest_path_pick_exec(bContext *C, wmOperator *op)
ViewContext em_setup_viewcontext(bContext *C)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc)
Main * CTX_data_main(const bContext *C)
BMElem * BM_mesh_active_elem_get(BMesh *bm)
static bool verttag_test_cb(BMVert *v, void *)
LinkNode * BM_mesh_calc_path_region_face(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, bool(*filter_fn)(BMFace *, void *user_data), void *user_data)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
bool ED_operator_editmesh_region_view3d(bContext *C)
bool EDBM_uvselect_clear(BMesh *bm)
static wmOperatorStatus edbm_shortest_path_select_exec(bContext *C, wmOperator *op)
void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const StringRef name)
Scene * CTX_data_scene(const bContext *C)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
static bool verttag_filter_cb(BMVert *v, void *)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
float ED_view3d_select_dist_px()
LinkNode * BM_mesh_calc_path_region_vert(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, bool(*filter_fn)(BMVert *, void *user_data), void *user_data)
bool CustomData_has_layer_named(const CustomData *data, eCustomDataType type, StringRef name)
Vector< Base * > BKE_view_layer_array_from_bases_in_edit_mode(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
void WM_operator_properties_checker_interval_from_op(wmOperator *op, CheckerIntervalParams *op_params)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
View3D * CTX_wm_view3d(const bContext *C)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void BM_edge_select_set(BMesh *bm, BMEdge *e, const bool select)
Select Edge.
struct BMEditSelection * prev
struct Object * object
CheckerIntervalParams interval_params
struct ToolSettings * toolsettings
const PathSelectParams * op_params
ViewLayer * view_layer
Definition ED_view3d.hh:80
BMEditMesh * em
Definition ED_view3d.hh:87
ListBaseT< BMEditSelection > selected
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
bool(*) poll_property(const bContext *C, wmOperator *op, const PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1171
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports