Blender V5.3
uvedit_path.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cstdlib>
12#include <cstring>
13
14#include "BLI_linklist.hh"
15#include "BLI_math_vector_c.hh"
16#include "BLI_utildefines.hh"
17
18#include "MEM_guardedalloc.h"
19
20#include "DNA_mesh_types.h"
21#include "DNA_object_types.h"
22#include "DNA_scene_types.h"
24
25#include "BKE_context.hh"
26#include "BKE_customdata.hh"
27#include "BKE_editmesh.hh"
28#include "BKE_layer.hh"
29#include "BKE_mesh.hh"
30#include "BKE_report.hh"
31
32#include "DEG_depsgraph.hh"
34
35#include "ED_object.hh"
36#include "ED_screen.hh"
37#include "ED_uvedit.hh"
38
39#include "RNA_access.hh"
40#include "RNA_define.hh"
41
42#include "WM_api.hh"
43#include "WM_types.hh"
44
45#include "UI_view2d.hh"
46
48#include "uvedit_intern.hh"
49
50#include "bmesh_tools.hh"
51
52namespace blender {
53
54/* -------------------------------------------------------------------- */
57
58namespace {
59
60struct PathSelectParams {
62 bool track_active;
64 bool use_face_step;
65 bool use_fill;
66 CheckerIntervalParams interval_params;
67};
68
69struct UserData_UV {
70 Scene *scene;
71 BMesh *bm;
72 BMUVOffsets offsets;
73};
74
75} // namespace
76
78{
80 "use_face_step",
81 false,
82 "Face Stepping",
83 "Traverse connected faces (includes diagonals and edge-rings)");
85 "use_topology_distance",
86 false,
87 "Topology Distance",
88 "Find the minimum number of steps, ignoring spatial distance");
90 "use_fill",
91 false,
92 "Fill Region",
93 "Select all paths between the source/destination elements");
94
96}
97
99{
100 op_params->track_active = false;
101 op_params->use_face_step = RNA_boolean_get(op->ptr, "use_face_step");
102 op_params->use_fill = RNA_boolean_get(op->ptr, "use_fill");
103 op_params->use_topology_distance = RNA_boolean_get(op->ptr, "use_topology_distance");
104 WM_operator_properties_checker_interval_from_op(op, &op_params->interval_params);
105}
106
108
109/* -------------------------------------------------------------------- */
112
113/* callbacks */
114static bool verttag_filter_cb(BMLoop *l, void *user_data_v)
115{
116 UserData_UV *user_data = static_cast<UserData_UV *>(user_data_v);
117 return uvedit_face_visible_test(user_data->scene, l->f);
118}
119static bool verttag_test_cb(BMLoop *l, void *user_data_v)
120{
121 /* All connected loops are selected or we return false. */
122 UserData_UV *user_data = static_cast<UserData_UV *>(user_data_v);
123 const Scene *scene = user_data->scene;
124 const int cd_loop_uv_offset = user_data->offsets.uv;
125 const float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
126 BMIter iter;
127 BMLoop *l_iter;
128 BM_ITER_ELEM (l_iter, &iter, l->v, BM_LOOPS_OF_VERT) {
129 if (verttag_filter_cb(l_iter, user_data)) {
130 const float *luv_iter = BM_ELEM_CD_GET_FLOAT_P(l_iter, cd_loop_uv_offset);
131 if (equals_v2v2(luv, luv_iter)) {
132 if (!uvedit_uv_select_test(scene, user_data->bm, l_iter, user_data->offsets)) {
133 return false;
134 }
135 }
136 }
137 }
138 return true;
139}
140static void verttag_set_cb(BMLoop *l, bool val, void *user_data_v)
141{
142 UserData_UV *user_data = static_cast<UserData_UV *>(user_data_v);
143 const Scene *scene = user_data->scene;
144 BMesh *bm = user_data->bm;
145 const uint cd_loop_uv_offset = user_data->offsets.uv;
146 const float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
147 BMIter iter;
148 BMLoop *l_iter;
149 BM_ITER_ELEM (l_iter, &iter, l->v, BM_LOOPS_OF_VERT) {
150 if (verttag_filter_cb(l_iter, user_data)) {
151 const float *luv_iter = BM_ELEM_CD_GET_FLOAT_P(l_iter, cd_loop_uv_offset);
152 if (equals_v2v2(luv, luv_iter)) {
153 uvedit_uv_select_set(scene, bm, l_iter, val);
154 }
155 }
156 }
157}
158
160 Object *obedit,
161 const PathSelectParams *op_params,
162 BMLoop *l_src,
163 BMLoop *l_dst,
164 const float aspect_y,
165 const BMUVOffsets &offsets)
166{
168 int flush = 0;
169
170 UserData_UV user_data = {};
171 user_data.scene = scene;
172 user_data.bm = bm;
173 user_data.offsets = offsets;
174
175 BMCalcPathUVParams params{};
176 params.use_topology_distance = op_params->use_topology_distance;
177 params.use_step_face = op_params->use_face_step;
178 params.aspect_y = aspect_y;
179 params.cd_loop_uv_offset = offsets.uv;
180
181 LinkNode *path = nullptr;
182 bool is_path_ordered = false;
183
184 if (l_src != l_dst) {
185 if (op_params->use_fill) {
187 reinterpret_cast<BMElem *>(l_src),
188 reinterpret_cast<BMElem *>(l_dst),
189 params.cd_loop_uv_offset,
191 &user_data);
192 }
193 else {
194 is_path_ordered = true;
195 path = BM_mesh_calc_path_uv_vert(bm, l_src, l_dst, &params, verttag_filter_cb, &user_data);
196 }
197 }
198
199 BMLoop *l_dst_last = l_dst;
200
201 if (path) {
202 /* toggle the flag */
203 bool all_set = true;
204 LinkNode *node = path;
205 do {
206 if (!verttag_test_cb(static_cast<BMLoop *>(node->link), &user_data)) {
207 all_set = false;
208 break;
209 }
210 } while ((node = node->next));
211
212 int depth = -1;
213 node = path;
214 do {
215 if ((is_path_ordered == false) ||
216 WM_operator_properties_checker_interval_test(&op_params->interval_params, depth))
217 {
218 verttag_set_cb(static_cast<BMLoop *>(node->link), !all_set, &user_data);
219 if (is_path_ordered) {
220 l_dst_last = static_cast<BMLoop *>(node->link);
221 }
222 }
223 } while ((void)depth++, (node = node->next));
224
225 BLI_linklist_free(path, nullptr);
226 flush = all_set ? -1 : 1;
227 }
228 else {
229 const bool is_act = !verttag_test_cb(l_dst, &user_data);
230 verttag_set_cb(l_dst, is_act, &user_data); /* switch the face option */
231 }
232
233 if (op_params->track_active) {
235 }
236 return flush;
237}
238
240
241/* -------------------------------------------------------------------- */
244
245/* callbacks */
246static bool edgetag_filter_cb(BMLoop *l, void *user_data_v)
247{
248 UserData_UV *user_data = static_cast<UserData_UV *>(user_data_v);
249 return uvedit_face_visible_test(user_data->scene, l->f);
250}
251static bool edgetag_test_cb(BMLoop *l, void *user_data_v)
252{
253 /* All connected loops (UV) are selected or we return false. */
254 UserData_UV *user_data = static_cast<UserData_UV *>(user_data_v);
255 const Scene *scene = user_data->scene;
256 BMIter iter;
257 BMLoop *l_iter;
258 BM_ITER_ELEM (l_iter, &iter, l->e, BM_LOOPS_OF_EDGE) {
259 if (edgetag_filter_cb(l_iter, user_data)) {
260 if (BM_loop_uv_share_edge_check(l, l_iter, user_data->offsets.uv)) {
261 if (!uvedit_edge_select_test(scene, user_data->bm, l_iter, user_data->offsets)) {
262 return false;
263 }
264 }
265 }
266 }
267 return true;
268}
269static void edgetag_set_cb(BMLoop *l, bool val, void *user_data_v)
270{
271 UserData_UV *user_data = static_cast<UserData_UV *>(user_data_v);
272 const Scene *scene = user_data->scene;
273 BMesh *bm = user_data->bm;
274 uvedit_edge_select_set_with_sticky(scene, bm, l, val, user_data->offsets);
275}
276
278 Object *obedit,
279 const PathSelectParams *op_params,
280 BMLoop *l_src,
281 BMLoop *l_dst,
282 const float aspect_y,
283 const BMUVOffsets &offsets)
284{
286 int flush = 0;
287
288 UserData_UV user_data = {};
289 user_data.scene = scene;
290 user_data.bm = bm;
291 user_data.offsets = offsets;
292
293 BMCalcPathUVParams params = {};
294 params.use_topology_distance = op_params->use_topology_distance;
295 params.use_step_face = op_params->use_face_step;
296 params.aspect_y = aspect_y;
297 params.cd_loop_uv_offset = offsets.uv;
298
299 LinkNode *path = nullptr;
300 bool is_path_ordered = false;
301
302 if (l_src != l_dst) {
303 if (op_params->use_fill) {
305 reinterpret_cast<BMElem *>(l_src),
306 reinterpret_cast<BMElem *>(l_dst),
307 params.cd_loop_uv_offset,
309 &user_data);
310 }
311 else {
312 is_path_ordered = true;
313 path = BM_mesh_calc_path_uv_edge(bm, l_src, l_dst, &params, edgetag_filter_cb, &user_data);
314 }
315 }
316
317 BMLoop *l_dst_last = l_dst;
318
319 if (path) {
320 /* toggle the flag */
321 bool all_set = true;
322 LinkNode *node = path;
323 do {
324 if (!edgetag_test_cb(static_cast<BMLoop *>(node->link), &user_data)) {
325 all_set = false;
326 break;
327 }
328 } while ((node = node->next));
329
330 int depth = -1;
331 node = path;
332 do {
333 if ((is_path_ordered == false) ||
334 WM_operator_properties_checker_interval_test(&op_params->interval_params, depth))
335 {
336 edgetag_set_cb(static_cast<BMLoop *>(node->link), !all_set, &user_data);
337 if (is_path_ordered) {
338 l_dst_last = static_cast<BMLoop *>(node->link);
339 }
340 }
341 } while ((void)depth++, (node = node->next));
342
343 BLI_linklist_free(path, nullptr);
344 flush = all_set ? -1 : 1;
345 }
346 else {
347 const bool is_act = !edgetag_test_cb(l_dst, &user_data);
348 edgetag_set_cb(l_dst, is_act, &user_data); /* switch the face option */
349 }
350
351 if (op_params->track_active) {
353 }
354 return flush;
355}
356
358
359/* -------------------------------------------------------------------- */
362
363/* callbacks */
364static bool facetag_filter_cb(BMFace *f, void *user_data_v)
365{
366 UserData_UV *user_data = static_cast<UserData_UV *>(user_data_v);
367 return uvedit_face_visible_test(user_data->scene, f);
368}
369static bool facetag_test_cb(BMFace *f, void *user_data_v)
370{
371 /* All connected loops are selected or we return false. */
372 UserData_UV *user_data = static_cast<UserData_UV *>(user_data_v);
373 const Scene *scene = user_data->scene;
374 BMIter iter;
375 BMLoop *l_iter;
376 BM_ITER_ELEM (l_iter, &iter, f, BM_LOOPS_OF_FACE) {
377 if (!uvedit_edge_select_test(scene, user_data->bm, l_iter, user_data->offsets)) {
378 return false;
379 }
380 }
381 return true;
382}
383static void facetag_set_cb(BMFace *f, bool val, void *user_data_v)
384{
385 UserData_UV *user_data = static_cast<UserData_UV *>(user_data_v);
386 const Scene *scene = user_data->scene;
387 BMesh *bm = user_data->bm;
388 uvedit_face_select_set_with_sticky(scene, bm, f, val, user_data->offsets);
389}
390
392 Object *obedit,
393 const PathSelectParams *op_params,
394 BMFace *f_src,
395 BMFace *f_dst,
396 const float aspect_y,
397 const BMUVOffsets &offsets)
398{
400 int flush = 0;
401
402 UserData_UV user_data = {};
403 user_data.scene = scene;
404 user_data.bm = bm;
405 user_data.offsets = offsets;
406
407 BMCalcPathUVParams params = {};
408 params.use_topology_distance = op_params->use_topology_distance;
409 params.use_step_face = op_params->use_face_step;
410 params.aspect_y = aspect_y;
411 params.cd_loop_uv_offset = offsets.uv;
412
413 LinkNode *path = nullptr;
414 bool is_path_ordered = false;
415
416 if (f_src != f_dst) {
417 if (op_params->use_fill) {
419 reinterpret_cast<BMElem *>(f_src),
420 reinterpret_cast<BMElem *>(f_dst),
421 params.cd_loop_uv_offset,
423 &user_data);
424 }
425 else {
426 is_path_ordered = true;
427 path = BM_mesh_calc_path_uv_face(bm, f_src, f_dst, &params, facetag_filter_cb, &user_data);
428 }
429 }
430
431 BMFace *f_dst_last = f_dst;
432
433 if (path) {
434 /* toggle the flag */
435 bool all_set = true;
436 LinkNode *node = path;
437 do {
438 if (!facetag_test_cb(static_cast<BMFace *>(node->link), &user_data)) {
439 all_set = false;
440 break;
441 }
442 } while ((node = node->next));
443
444 int depth = -1;
445 node = path;
446 do {
447 if ((is_path_ordered == false) ||
448 WM_operator_properties_checker_interval_test(&op_params->interval_params, depth))
449 {
450 facetag_set_cb(static_cast<BMFace *>(node->link), !all_set, &user_data);
451 if (is_path_ordered) {
452 f_dst_last = static_cast<BMFace *>(node->link);
453 }
454 }
455 } while ((void)depth++, (node = node->next));
456
457 BLI_linklist_free(path, nullptr);
458 flush = all_set ? -1 : 1;
459 }
460 else {
461 const bool is_act = !facetag_test_cb(f_dst, &user_data);
462 facetag_set_cb(f_dst, is_act, &user_data); /* switch the face option */
463 }
464
465 if (op_params->track_active) {
466 /* Unlike other types, we can track active without it being selected. */
467 BM_mesh_active_face_set(bm, f_dst_last);
468 }
469 return flush;
470}
471
473
474/* -------------------------------------------------------------------- */
477
478static wmOperatorStatus uv_shortest_path_pick_exec(bContext *C, wmOperator *op);
479
481 Depsgraph *depsgraph,
482 Object *obedit,
483 const PathSelectParams *op_params,
484 BMElem *ele_src,
485 BMElem *ele_dst,
486 const float aspect_y,
487 const BMUVOffsets &offsets)
488{
489 const ToolSettings *ts = scene->toolsettings;
490 const char uv_selectmode = ED_uvedit_select_mode_get(scene);
491 bool ok = false;
492 int flush = 0;
493
494 if (ELEM(nullptr, ele_src, ele_dst) || (ele_src->head.htype != ele_dst->head.htype)) {
495 /* pass */
496 }
497 else if (ele_src->head.htype == BM_FACE) {
499 obedit,
500 op_params,
501 reinterpret_cast<BMFace *>(ele_src),
502 reinterpret_cast<BMFace *>(ele_dst),
503 aspect_y,
504 offsets);
505 ok = true;
506 }
507 else if (ele_src->head.htype == BM_LOOP) {
508 if (uv_selectmode & UV_SELECT_EDGE) {
510 obedit,
511 op_params,
512 reinterpret_cast<BMLoop *>(ele_src),
513 reinterpret_cast<BMLoop *>(ele_dst),
514 aspect_y,
515 offsets);
516 }
517 else {
519 obedit,
520 op_params,
521 reinterpret_cast<BMLoop *>(ele_src),
522 reinterpret_cast<BMLoop *>(ele_dst),
523 aspect_y,
524 offsets);
525 }
526 ok = true;
527 }
528
529 if (ok) {
530 if (flush != 0) {
531 const bool select = (flush == 1);
533 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
535 }
536 else {
538 }
539 }
540
541 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
543 }
544 else {
545 Object *obedit_eval = DEG_get_evaluated(depsgraph, obedit);
546 BKE_mesh_batch_cache_dirty_tag(id_cast<Mesh *>(obedit_eval->data),
548 }
549 /* Only for region redraw. */
551 }
552
553 return ok;
554}
555
557 wmOperator *op,
558 const wmEvent *event)
559{
560 const Main *bmain = CTX_data_main(C);
561 Scene *scene = CTX_data_scene(C);
562 const ToolSettings *ts = scene->toolsettings;
563 const char uv_selectmode = ED_uvedit_select_mode_get(scene);
564
565 /* We could support this, it needs further testing. */
566 if (RNA_struct_property_is_set(op->ptr, "index")) {
567 return uv_shortest_path_pick_exec(C, op);
568 }
569
570 PathSelectParams op_params;
571 path_select_params_from_op(op, &op_params);
572
573 /* Set false if we support edge tagging. */
574 op_params.track_active = true;
575
576 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
577 ViewLayer *view_layer = CTX_data_view_layer(C);
579 *bmain, scene, view_layer, nullptr);
580
581 float co[2];
582
583 const ARegion *region = CTX_wm_region(C);
584
585 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
586
587 BMElem *ele_src = nullptr, *ele_dst = nullptr;
588
589 /* Detect the hit. */
591 bool hit_found = false;
592 if (uv_selectmode == UV_SELECT_FACE) {
593 if (uv_find_nearest_face_multi(scene, objects, co, &hit)) {
594 hit_found = true;
595 }
596 }
597 else if (uv_selectmode & UV_SELECT_EDGE) {
598 if (uv_find_nearest_edge_multi(scene, objects, co, 0.0f, &hit)) {
599 hit_found = true;
600 }
601 }
602 else {
603 if (uv_find_nearest_vert_multi(scene, objects, co, 0.0f, &hit)) {
604 hit_found = true;
605 }
606 }
607
608 bool changed = false;
609 if (hit_found) {
610 /* This may not be the active object. */
611 Object *obedit = hit.ob;
613 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
614
615 /* Respond to the hit. */
616 if (uv_selectmode == UV_SELECT_FACE) {
617 /* Face selection. */
618 BMFace *f_src = BM_mesh_active_face_get(bm, false, false);
619 /* Check selection? */
620 ele_src = reinterpret_cast<BMElem *>(f_src);
621 ele_dst = reinterpret_cast<BMElem *>(hit.efa);
622 }
623 else if (uv_selectmode & UV_SELECT_EDGE) {
624 /* Edge selection. */
625 BMLoop *l_src = nullptr;
626 if ((ts->uv_flag & UV_FLAG_SELECT_SYNC) && (bm->uv_select_sync_valid == false)) {
628 if (e_src != nullptr) {
629 l_src = uv_find_nearest_loop_from_edge(scene, obedit, e_src, co);
630 }
631 }
632 else {
634 if (l_src != nullptr) {
635 if (!uvedit_uv_select_test(scene, bm, l_src, offsets) &&
636 !uvedit_uv_select_test(scene, bm, l_src->next, offsets))
637 {
638 l_src = nullptr;
639 }
640 ele_src = reinterpret_cast<BMElem *>(l_src);
641 }
642 }
643 ele_src = reinterpret_cast<BMElem *>(l_src);
644 ele_dst = reinterpret_cast<BMElem *>(hit.l);
645 }
646 else {
647 /* Vertex selection. */
648 BMLoop *l_src = nullptr;
649 if ((ts->uv_flag & UV_FLAG_SELECT_SYNC) && (bm->uv_select_sync_valid == false)) {
651 if (v_src != nullptr) {
652 l_src = uv_find_nearest_loop_from_vert(scene, obedit, v_src, co);
653 }
654 }
655 else {
657 if (l_src != nullptr) {
658 if (!uvedit_uv_select_test(scene, bm, l_src, offsets)) {
659 l_src = nullptr;
660 }
661 }
662 }
663 ele_src = reinterpret_cast<BMElem *>(l_src);
664 ele_dst = reinterpret_cast<BMElem *>(hit.l);
665 }
666
667 if (ele_src && ele_dst) {
668 /* Always use the active object, not `obedit` as the active defines the UV display. */
669 const float aspect_y = ED_uvedit_get_aspect_y(CTX_data_edit_object(C));
671 scene, depsgraph, obedit, &op_params, ele_src, ele_dst, aspect_y, offsets);
672
673 /* Store the object and it's index so redo is possible. */
674 int index;
675 if (uv_selectmode & UV_SELECT_FACE) {
677 index = BM_elem_index_get(ele_dst);
678 }
679 else if (uv_selectmode & UV_SELECT_EDGE) {
681 index = BM_elem_index_get(ele_dst);
682 }
683 else {
685 index = BM_elem_index_get(ele_dst);
686 }
687
688 const int object_index = ed::object::object_in_mode_to_index(
689 *bmain, scene, view_layer, OB_MODE_EDIT, obedit);
690 BLI_assert(object_index != -1);
691 RNA_int_set(op->ptr, "object_index", object_index);
692 RNA_int_set(op->ptr, "index", index);
693 changed = true;
694 }
695 }
696
697 return changed ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
698}
699
701{
702 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
703 const Main *bmain = CTX_data_main(C);
704 Scene *scene = CTX_data_scene(C);
705 const ToolSettings *ts = scene->toolsettings;
706 ViewLayer *view_layer = CTX_data_view_layer(C);
707 const char uv_selectmode = ED_uvedit_select_mode_get(scene);
708
709 const int object_index = RNA_int_get(op->ptr, "object_index");
710 const int index = RNA_int_get(op->ptr, "index");
711 if (object_index == -1) {
712 return OPERATOR_CANCELLED;
713 }
714
716 *bmain, scene, view_layer, OB_MODE_EDIT, object_index);
717 if (obedit == nullptr) {
718 return OPERATOR_CANCELLED;
719 }
720
722 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
723
724 BMElem *ele_src, *ele_dst;
725
726 /* NOLINTBEGIN: bugprone-assignment-in-if-condition */
727 if (uv_selectmode & UV_SELECT_FACE) {
728 if (index < 0 || index >= bm->totface) {
729 return OPERATOR_CANCELLED;
730 }
731 if (!(ele_src = reinterpret_cast<BMElem *>(BM_mesh_active_face_get(bm, false, false))) ||
732 !(ele_dst = reinterpret_cast<BMElem *>(BM_face_at_index_find_or_table(bm, index))))
733 {
734 return OPERATOR_CANCELLED;
735 }
736 }
737 else if (uv_selectmode & UV_SELECT_EDGE) {
738 if (index < 0 || index >= bm->totloop) {
739 return OPERATOR_CANCELLED;
740 }
741 if (!(ele_src = reinterpret_cast<BMElem *>(ED_uvedit_active_edge_loop_get(ts, bm))) ||
742 !(ele_dst = reinterpret_cast<BMElem *>(BM_loop_at_index_find(bm, index))))
743 {
744 return OPERATOR_CANCELLED;
745 }
746 }
747 else {
748 if (index < 0 || index >= bm->totloop) {
749 return OPERATOR_CANCELLED;
750 }
751 if (!(ele_src = reinterpret_cast<BMElem *>(ED_uvedit_active_vert_loop_get(ts, bm))) ||
752 !(ele_dst = reinterpret_cast<BMElem *>(BM_loop_at_index_find(bm, index))))
753 {
754 return OPERATOR_CANCELLED;
755 }
756 }
757 /* NOLINTEND: bugprone-assignment-in-if-condition */
758
759 /* Always use the active object, not `obedit` as the active defines the UV display. */
760 const float aspect_y = ED_uvedit_get_aspect_y(CTX_data_edit_object(C));
761
762 PathSelectParams op_params;
763 path_select_params_from_op(op, &op_params);
764 op_params.track_active = true;
765
767 scene, depsgraph, obedit, &op_params, ele_src, ele_dst, aspect_y, offsets))
768 {
769 return OPERATOR_CANCELLED;
770 }
771
772 return OPERATOR_FINISHED;
773}
774
776{
777 PropertyRNA *prop;
778
779 /* identifiers */
780 ot->name = "Pick Shortest Path";
781 ot->idname = "UV_OT_shortest_path_pick";
782 ot->description = "Select shortest path between two selections";
783
784 /* API callbacks. */
788
789 /* flags */
791
792 /* properties */
794
795 /* use for redo */
796 prop = RNA_def_int(ot->srna, "object_index", -1, -1, INT_MAX, "", "", 0, INT_MAX);
798 prop = RNA_def_int(ot->srna, "index", -1, -1, INT_MAX, "", "", 0, INT_MAX);
800}
801
803
804/* -------------------------------------------------------------------- */
807
809{
810 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
811 const Main *bmain = CTX_data_main(C);
812 Scene *scene = CTX_data_scene(C);
813 const char uv_selectmode = ED_uvedit_select_mode_get(scene);
814 bool found_valid_elements = false;
815
816 const float aspect_y = ED_uvedit_get_aspect_y(CTX_data_edit_object(C));
817
818 ViewLayer *view_layer = CTX_data_view_layer(C);
820 *bmain, scene, view_layer, nullptr);
821 for (Object *obedit : objects) {
823
824 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
825
826 BMElem *ele_src = nullptr, *ele_dst = nullptr;
827
828 /* Find 2x elements. */
829 {
830 BMElem **ele_array = nullptr;
831 int ele_array_len = 0;
832 if (uv_selectmode & UV_SELECT_FACE) {
833 ele_array = reinterpret_cast<BMElem **>(
834 ED_uvedit_selected_faces(scene, bm, 3, &ele_array_len));
835 }
836 else if (uv_selectmode & UV_SELECT_EDGE) {
837 ele_array = reinterpret_cast<BMElem **>(
838 ED_uvedit_selected_edges(scene, bm, 3, &ele_array_len));
839 }
840 else {
841 ele_array = reinterpret_cast<BMElem **>(
842 ED_uvedit_selected_verts(scene, bm, 3, &ele_array_len));
843 }
844
845 if (ele_array_len == 2) {
846 ele_src = ele_array[0];
847 ele_dst = ele_array[1];
848 }
849 MEM_delete(ele_array);
850 }
851
852 if (ele_src && ele_dst) {
853 PathSelectParams op_params;
854 path_select_params_from_op(op, &op_params);
855
857 scene, depsgraph, obedit, &op_params, ele_src, ele_dst, aspect_y, offsets);
858
859 found_valid_elements = true;
860 }
861 }
862
863 if (!found_valid_elements) {
865 op->reports, RPT_WARNING, "Path selection requires two matching elements to be selected");
866 return OPERATOR_CANCELLED;
867 }
868
869 return OPERATOR_FINISHED;
870}
871
873{
874 /* identifiers */
875 ot->name = "Select Shortest Path";
876 ot->idname = "UV_OT_shortest_path_select";
877 ot->description = "Select shortest path between two vertices/edges/faces";
878
879 /* API callbacks. */
882
883 /* flags */
885
886 /* properties */
888}
889
891
892} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#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 BM_ELEM_CD_GET_FLOAT_P(ele, offset)
#define BM_elem_index_get(ele)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define INT_MAX
int object_in_mode_to_index(const Main &bmain, const Scene *scene, ViewLayer *view_layer, eObjectMode mode, const Object *ob)
Object * object_in_mode_from_index(const Main &bmain, const Scene *scene, ViewLayer *view_layer, eObjectMode mode, int index)
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
static void facetag_set_cb(BMFace *f, bool val, void *user_data_v)
BMLoop * ED_uvedit_active_edge_loop_get(const ToolSettings *ts, BMesh *bm)
static void edgetag_set_cb(BMEdge *e, bool val, void *user_data_v)
bool uvedit_edge_select_test(const Scene *scene, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
@ RPT_WARNING
Definition BKE_report.hh:40
bool uv_find_nearest_face_multi(Scene *scene, Span< Object * > objects, const float co[2], UvNearestHit *hit)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
unsigned int uint
Definition BKE_text.h:55
static bool facetag_test_cb(BMFace *f, void *)
void UV_OT_shortest_path_select(wmOperatorType *ot)
float ED_uvedit_get_aspect_y(Object *obedit)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
bool uvedit_face_visible_test(const Scene *scene, const BMFace *efa)
static int mouse_mesh_uv_shortest_path_vert(Scene *scene, Object *obedit, const PathSelectParams *op_params, BMLoop *l_src, BMLoop *l_dst, const float aspect_y, const BMUVOffsets &offsets)
void ED_uvedit_active_edge_loop_set(BMesh *bm, BMLoop *l)
BMLoop ** ED_uvedit_selected_edges(const Scene *scene, BMesh *bm, int len_max, int *r_edges_len)
void ED_uvedit_active_vert_loop_set(BMesh *bm, BMLoop *l)
void ED_uvedit_selectmode_flush(const Scene *scene, BMesh *bm)
UV Select Mode Flush.
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
static bool edgetag_test_cb(BMEdge *e, void *user_data_v)
int RNA_int_get(PointerRNA *ptr, const char *name)
bool uv_find_nearest_edge_multi(Scene *scene, Span< Object * > objects, const float co[2], float penalty, UvNearestHit *hit)
BMLoop * ED_uvedit_active_vert_loop_get(const ToolSettings *ts, BMesh *bm)
void WM_operator_properties_checker_interval(wmOperatorType *ot, bool nth_can_disable)
BMLoop * uv_find_nearest_loop_from_vert(Scene *scene, Object *obedit, BMVert *v, const float co[2])
BMLoop * BM_loop_at_index_find(BMesh *bm, const int index)
void uvedit_face_select_set_with_sticky(const Scene *scene, BMesh *bm, BMFace *efa, bool select, const BMUVOffsets &offsets)
ViewLayer * CTX_data_view_layer(const bContext *C)
static void path_select_properties(wmOperatorType *ot)
BMEdge * BM_mesh_active_edge_get(BMesh *bm)
bool uvedit_uv_select_test(const Scene *scene, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
bool uv_find_nearest_vert_multi(Scene *scene, Span< Object * > objects, const float co[2], float penalty_dist, UvNearestHit *hit)
BMFace ** ED_uvedit_selected_faces(const Scene *scene, BMesh *bm, int len_max, int *r_faces_len)
static bool edgetag_filter_cb(BMEdge *e, void *)
void ED_uvedit_select_sync_flush(const ToolSettings *ts, BMesh *bm, bool select)
char ED_uvedit_select_mode_get(const Scene *scene)
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
BMLoop * uv_find_nearest_loop_from_edge(Scene *scene, Object *obedit, BMEdge *e, const float co[2])
void BKE_mesh_batch_cache_dirty_tag(Mesh *mesh, eMeshBatchDirtyMode mode)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void UV_OT_shortest_path_pick(wmOperatorType *ot)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
bool WM_operator_properties_checker_interval_test(const CheckerIntervalParams *op_params, int depth)
Object * CTX_data_edit_object(const bContext *C)
BMFace * BM_face_at_index_find_or_table(BMesh *bm, const int index)
UvNearestHit uv_nearest_hit_init_max(const View2D *v2d)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
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)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus uv_shortest_path_select_exec(bContext *C, wmOperator *op)
LinkNode * BM_mesh_calc_path_uv_region_face(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, const int cd_loop_uv_offset, bool(*filter_fn)(BMFace *, void *user_data), void *user_data)
bool ED_operator_uvedit_space_image(bContext *C)
MINLINE bool equals_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
void uvedit_edge_select_set_with_sticky(const Scene *scene, BMesh *bm, BMLoop *l, bool select, const BMUVOffsets &offsets)
LinkNode * BM_mesh_calc_path_uv_region_vert(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, const int cd_loop_uv_offset, bool(*filter_fn)(BMLoop *, void *user_data), void *user_data)
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)
LinkNode * BM_mesh_calc_path_uv_face(BMesh *bm, BMFace *f_src, BMFace *f_dst, const BMCalcPathUVParams *params, bool(*filter_fn)(BMFace *, void *), void *user_data)
void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc)
Main * CTX_data_main(const bContext *C)
void uvedit_uv_select_set(const Scene *scene, BMesh *bm, BMLoop *l, bool select)
Select UV Vertex.
BMFace * BM_mesh_active_face_get(BMesh *bm, const bool is_sloppy, const bool is_selected)
LinkNode * BM_mesh_calc_path_uv_vert(BMesh *bm, BMLoop *l_src, BMLoop *l_dst, const BMCalcPathUVParams *params, bool(*filter_fn)(BMLoop *, void *), void *user_data)
static bool uv_shortest_path_pick_ex(Scene *scene, Depsgraph *depsgraph, Object *obedit, const PathSelectParams *op_params, BMElem *ele_src, BMElem *ele_dst, const float aspect_y, const BMUVOffsets &offsets)
static bool verttag_test_cb(BMVert *v, void *)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
static wmOperatorStatus uv_shortest_path_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool BM_loop_uv_share_edge_check(const BMLoop *l_a, const BMLoop *l_b, const int cd_loop_uv_offset)
static wmOperatorStatus uv_shortest_path_pick_exec(bContext *C, wmOperator *op)
Scene * CTX_data_scene(const bContext *C)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
BMUVOffsets BM_uv_map_offsets_get(const BMesh *bm)
Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
BMLoop ** ED_uvedit_selected_verts(const Scene *scene, BMesh *bm, int len_max, int *r_verts_len)
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)
static int mouse_mesh_uv_shortest_path_edge(Scene *scene, Object *obedit, const PathSelectParams *op_params, BMLoop *l_src, BMLoop *l_dst, const float aspect_y, const BMUVOffsets &offsets)
@ BKE_MESH_BATCH_DIRTY_UVEDIT_SELECT
Definition BKE_mesh.h:53
void WM_operator_properties_checker_interval_from_op(wmOperator *op, CheckerIntervalParams *op_params)
ARegion * CTX_wm_region(const bContext *C)
static int mouse_mesh_uv_shortest_path_face(Scene *scene, Object *obedit, const PathSelectParams *op_params, BMFace *f_src, BMFace *f_dst, const float aspect_y, const BMUVOffsets &offsets)
BMVert * BM_mesh_active_vert_get(BMesh *bm)
LinkNode * BM_mesh_calc_path_uv_edge(BMesh *bm, BMLoop *l_src, BMLoop *l_dst, const BMCalcPathUVParams *params, bool(*filter_fn)(BMLoop *, void *), void *user_data)
LinkNode * BM_mesh_calc_path_uv_region_edge(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, const int cd_loop_uv_offset, bool(*filter_fn)(BMLoop *, void *user_data), void *user_data)
struct BMLoop * next
CheckerIntervalParams interval_params
struct ToolSettings * toolsettings
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
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