Blender V5.3
uvedit_select.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cmath>
10#include <cstdlib>
11#include <cstring>
12
13#include "MEM_guardedalloc.h"
14
15#include "DNA_node_types.h"
16#include "DNA_object_types.h"
17#include "DNA_scene_types.h"
18#include "DNA_space_types.h"
19
20#include "BLI_array.hh"
21#include "BLI_hash_c.hh"
22#include "BLI_heap.hh"
23#include "BLI_kdopbvh.hh"
24#include "BLI_kdtree.hh"
25#include "BLI_lasso_2d.hh"
26#include "BLI_listbase.hh"
27#include "BLI_map.hh"
28#include "BLI_math_geom_c.hh"
29#include "BLI_math_matrix_c.hh"
30#include "BLI_math_vector_c.hh"
31#include "BLI_memarena.hh"
32#include "BLI_polyfill_2d.hh"
34#include "BLI_utildefines.hh"
35#include "BLI_vector_list.hh"
36
37#include "BLT_translation.hh"
38
39#include "BKE_context.hh"
40#include "BKE_customdata.hh"
41#include "BKE_editmesh.hh"
42#include "BKE_layer.hh"
43#include "BKE_material.hh"
44#include "BKE_mesh.hh"
45#include "BKE_mesh_mapping.hh"
46#include "BKE_report.hh"
47
48#include "DEG_depsgraph.hh"
50
51#include "ED_image.hh"
52#include "ED_mesh.hh"
53#include "ED_screen.hh"
54#include "ED_select_utils.hh"
55#include "ED_uvedit.hh"
56
57#include "RNA_access.hh"
58#include "RNA_define.hh"
59#include "RNA_enum_types.hh"
60
61#include "WM_api.hh"
62#include "WM_types.hh"
63
64#include "UI_view2d.hh"
65
66#include "uvedit_intern.hh"
67
68namespace blender {
69
70enum class UVDelimitMode : int {
71 Seam = 1 << 0,
72 Sharp = 1 << 1,
73 Material = 1 << 2,
74};
76
78 {int(UVDelimitMode::Seam), "SEAM", 0, "Seam", "Delimit by edge seams"},
79 {int(UVDelimitMode::Sharp), "SHARP", 0, "Sharp", "Delimit by sharp edges"},
80 {int(UVDelimitMode::Material), "MATERIAL", 0, "Material", "Delimit by face material"},
81 {0, nullptr, 0, nullptr, nullptr},
82};
83
84static void uv_select_all_perform_multi_ex(const Scene *scene,
85 Span<Object *> objects,
86 int action,
87 const Object *ob_exclude);
88static void uv_select_all_perform_multi(const Scene *scene, Span<Object *> objects, int action);
89
90static void uv_select_flush_from_tag_face(const Scene *scene, Object *obedit, const bool select);
91static void uv_select_flush_from_tag_loop(const Scene *scene, Object *obedit, const bool select);
92static void uv_select_flush_from_loop_edge_flag(const Scene *scene, BMesh *bm);
93
94static void uv_select_tag_update_for_object(Depsgraph *depsgraph,
95 const ToolSettings *ts,
96 Object *obedit);
97
110
111/* -------------------------------------------------------------------- */
117
126
128{
129 BMEditSelection *ese = bm->selected.last();
131 if (ese && ese->htype == BM_VERT) {
132 BMVert *v = reinterpret_cast<BMVert *>(ese->ele);
133
134 BMLoop *l;
135 BMIter liter;
136
137 /* Prioritize face, edge then vert selection.
138 * This may be overkill, even so, be deterministic and favor loops connected to selection. */
139 BMLoop *l_select_vert = nullptr;
140 BMLoop *l_select_edge = nullptr;
141 BMLoop *l_select_edge_pair = nullptr;
142 BMLoop *l_select_face = nullptr;
143
144 BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) {
146 continue;
147 }
149 const bool select_edge_prev = BM_loop_edge_uvselect_test(l->prev);
150 const bool select_edge_next = BM_loop_edge_uvselect_test(l);
151 const bool select_face = BM_elem_flag_test(l->f, BM_ELEM_SELECT_UV);
152 l_select_vert = l;
153 if (select_edge_prev || select_edge_next) {
154 l_select_edge_pair = l;
155 }
156 if (select_edge_prev && select_edge_next) {
157 l_select_edge_pair = l;
158 }
159 if (select_face) {
160 l_select_face = l;
161 }
162 }
163 }
164 if (l_select_face) {
165 return l_select_face;
166 }
167 if (l_select_edge_pair) {
168 return l_select_edge_pair;
169 }
170 if (l_select_edge) {
171 return l_select_edge;
172 }
173 return l_select_vert;
174 }
175 return nullptr;
176 }
177
178 if (ese && ese->prev) {
179 BMEditSelection *ese_prev = ese->prev;
180 if ((ese->htype == BM_VERT) && (ese_prev->htype == BM_FACE)) {
181 /* May be null. */
182 return BM_face_vert_share_loop(reinterpret_cast<BMFace *>(ese_prev->ele),
183 reinterpret_cast<BMVert *>(ese->ele));
184 }
185 }
186 return nullptr;
187}
188
197
199{
200 BMEditSelection *ese = bm->selected.last();
202 if (ese && ese->htype == BM_EDGE) {
203 BMEdge *e = reinterpret_cast<BMEdge *>(ese->ele);
204
205 BMLoop *l;
206 BMIter liter;
207
208 /* Prioritize face then edge selection.
209 * This may be overkill, even so, be deterministic and favor loops connected to selection. */
210 BMLoop *l_select_vert = nullptr;
211 BMLoop *l_select_face = nullptr;
212
213 BM_ITER_ELEM (l, &liter, e, BM_LOOPS_OF_EDGE) {
215 continue;
216 }
218 const bool select_face = BM_elem_flag_test(l->f, BM_ELEM_SELECT_UV);
219 l_select_vert = l;
220 if (select_face) {
221 l_select_face = l;
222 }
223 }
224 }
225
226 if (l_select_face) {
227 return l_select_face;
228 }
229 return l_select_vert;
230 }
231 return nullptr;
232 }
233
234 if (ese && ese->prev) {
235 BMEditSelection *ese_prev = ese->prev;
236 if ((ese->htype == BM_EDGE) && (ese_prev->htype == BM_FACE)) {
237 /* May be null. */
238 return BM_face_edge_share_loop(reinterpret_cast<BMFace *>(ese_prev->ele),
239 reinterpret_cast<BMEdge *>(ese->ele));
240 }
241 }
242 return nullptr;
243}
244
246
247/* -------------------------------------------------------------------- */
250
252{
254 if (ts->uv_sticky == UV_STICKY_VERT) {
255 /* In this case use the original mesh selection. */
256 return true;
257 }
258 return false;
259}
260
265
267{
269
270 /* Otherwise, ensure UV select is up to date. */
271 switch (ts->uv_sticky) {
272 case UV_STICKY_LOCATION: {
273 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
275 break;
276 }
277 case UV_STICKY_DISABLE: {
279 break;
280 }
281 case UV_STICKY_VERT: {
283 break;
284 }
285 }
286}
287
289{
290 /* Select sync wont be needed when mode switching. */
292 bm->uv_select_sync_valid = false;
293 return;
294 }
295
296 /* In most cases the caller will ensure this,
297 * check here to allow for this to be called outside of the UV editor. */
299 bm->uv_select_sync_valid = false;
300 return;
301 }
302
303 /* Select sync already calculated. */
305 return;
306 }
307
309}
310
312{
313 const ToolSettings *ts = scene->toolsettings;
314 char uv_selectmode = UV_SELECT_VERT;
315
316 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
317 if (ts->selectmode & SCE_SELECT_VERTEX) {
318 uv_selectmode = UV_SELECT_VERT;
319 }
320 else if (ts->selectmode & SCE_SELECT_EDGE) {
321 uv_selectmode = UV_SELECT_EDGE;
322 }
323 else if (ts->selectmode & SCE_SELECT_FACE) {
324 uv_selectmode = UV_SELECT_FACE;
325 }
326 }
327 else {
328 if (ts->uv_selectmode & UV_SELECT_VERT) {
329 uv_selectmode = UV_SELECT_VERT;
330 }
331 else if (ts->uv_selectmode & UV_SELECT_EDGE) {
332 uv_selectmode = UV_SELECT_EDGE;
333 }
334 else if (ts->uv_selectmode & UV_SELECT_FACE) {
335 uv_selectmode = UV_SELECT_FACE;
336 }
337 }
338 return uv_selectmode;
339}
340
342{
343 if ((ts->uv_flag & UV_FLAG_SELECT_ISLAND) == 0) {
344 return false;
345 }
346
347 /* NOTE: when "strict" only return true when it's possible to select an island in isolation.
348 * At the moment none of the callers require this however it may be necessary to ignore the
349 * "island" selection option for some operations in the future.
350 * This could be exposed as an argument. */
351 const bool strict = false;
352
353 if (strict) {
354 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
356 return false;
357 }
358 }
359 }
360
361 return true;
362}
363
365{
366 /* bmesh API handles flushing but not on de-select */
367 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
370 if (ts->uv_sticky == UV_STICKY_LOCATION) {
371 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
373 }
375 }
376 else {
377 if (ts->selectmode != SCE_SELECT_FACE) {
378 if (select == false) {
380 }
381 else {
382 if (ts->selectmode & SCE_SELECT_VERTEX) {
384 }
385 else {
386 /* Use instead of #BM_mesh_select_flush so selecting edges doesn't
387 * flush vertex to face selection, see: #117320. */
389 }
390 }
391 }
392 }
393
394 if (select == false) {
396 }
397 }
398}
399
400static void uvedit_vertex_select_tagged(BMesh *bm, const Scene *scene, bool select)
401{
402 BMFace *efa;
403 BMLoop *l;
404 BMIter iter, liter;
405
406 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
407 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
410 }
411 }
412 }
413}
414
416{
417 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
418 return (BM_elem_flag_test(efa, BM_ELEM_HIDDEN) == 0);
419 }
421}
422bool uvedit_face_visible_test(const Scene *scene, const BMFace *efa)
423{
424 return uvedit_face_visible_test_ex(scene->toolsettings, efa);
425}
426
427bool uvedit_face_select_test_ex(const ToolSettings *ts, const BMesh *bm, const BMFace *efa)
428{
429 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
432 }
433 /* Caller checks for visibility. */
436 }
437
438 if (ts->uv_selectmode == UV_SELECT_FACE) {
440 return false;
441 }
442 return true;
443 }
444 const char hflag_test = (ts->uv_selectmode & UV_SELECT_VERT) ? BM_ELEM_SELECT_UV :
446 const BMLoop *l_first = BM_FACE_FIRST_LOOP(efa);
447 const BMLoop *l_iter = l_first;
448 do {
449 if (!BM_elem_flag_test(l_iter, hflag_test)) {
450 return false;
451 }
452 } while ((l_iter = l_iter->next) != l_first);
453 return true;
454}
455bool uvedit_face_select_test(const Scene *scene, const BMesh *bm, const BMFace *efa)
456{
457 return uvedit_face_select_test_ex(scene->toolsettings, bm, efa);
458}
459
461 const Scene *scene, BMesh *bm, BMFace *efa, const bool select, const BMUVOffsets &offsets)
462{
463 const ToolSettings *ts = scene->toolsettings;
464 const char sticky = ts->uv_sticky;
465 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
467 uvedit_face_select_set(scene, bm, efa, select);
468 return;
469 }
471 }
472 if (!uvedit_face_visible_test(scene, efa)) {
473 return;
474 }
475 /* NOTE: Previously face selections done in sticky vertex mode selected stray UV vertices
476 * (not part of any face selections). This now uses the sticky location mode logic instead. */
477 switch (sticky) {
478 case UV_STICKY_DISABLE: {
479 uvedit_face_select_set(scene, bm, efa, select);
480 break;
481 }
482 default: {
483 /* UV_STICKY_LOCATION and UV_STICKY_VERT modes. */
484 uvedit_face_select_shared_vert(scene, bm, efa, select, offsets);
485 }
486 }
487}
488
490 BMesh *bm,
491 BMFace *efa,
492 const bool select,
493
494 const BMUVOffsets &offsets)
495{
496 const ToolSettings *ts = scene->toolsettings;
497 BMLoop *l;
498 BMIter liter;
499
500 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
501 if (ts->uv_sticky == UV_STICKY_VERT) {
503 return;
504 }
506
507 /* NOTE: the logic is different enough to split out,
508 * mainly because it's possible to de-select a face but have all it's edges selected.
509 *
510 * NOTE: An alternative to this function would be to simply set the face selection
511 * and flush the entire mesh afterwards, mentioning this because the checks here are
512 * fairly involved. */
513
514 if (ts->uv_sticky == UV_STICKY_DISABLE) {
516 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
519 }
520 }
521 else if (ts->uv_sticky == UV_STICKY_LOCATION) {
523 if (select) {
524 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
525 BM_loop_vert_uvselect_set_shared(bm, l, true, offsets.uv);
526 BM_loop_edge_uvselect_set_shared(bm, l, true, offsets.uv);
527 }
528 }
529 else {
530 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
532 BM_loop_vert_uvselect_set_shared(bm, l, false, offsets.uv);
533 }
535 BM_loop_edge_uvselect_set_shared(bm, l, false, offsets.uv);
536 }
537 }
538 }
539 }
540 return;
541 }
542
544 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
546
547 if (select) {
549 }
550 else {
551 if (!uvedit_vert_is_face_select_any_other(ts, bm, l, offsets)) {
553 }
554 }
555 }
556}
557
558void uvedit_face_select_set(const Scene *scene, BMesh *bm, BMFace *efa, const bool select)
559{
560 if (select) {
561 uvedit_face_select_enable(scene, bm, efa);
562 }
563 else {
564 uvedit_face_select_disable(scene, bm, efa);
565 }
566}
567
569{
570 const ToolSettings *ts = scene->toolsettings;
571
572 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
574 BM_face_select_set(bm, efa, true);
575 }
576 else {
577 BM_face_uvselect_set(bm, efa, true);
578 }
579 }
580 else {
581 BMLoop *l;
582 BMIter liter;
583
584 uvedit_face_select_set_no_sync(ts, bm, efa, true);
585 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
588 }
589 }
590}
591
593{
594 const ToolSettings *ts = scene->toolsettings;
595
596 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
598 BM_face_select_set(bm, efa, false);
599 }
600 else {
601 BM_face_uvselect_set(bm, efa, false);
602 }
603 }
604 else {
605 BMLoop *l;
606 BMIter liter;
607
608 uvedit_face_select_set_no_sync(ts, bm, efa, false);
609 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
612 }
613 }
614}
615
617 const BMesh *bm,
618 const BMLoop *l,
619 const BMUVOffsets &offsets)
620{
621 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
622 if ((bm->uv_select_sync_valid == false) && (ts->selectmode == SCE_SELECT_FACE)) {
623 /* Face only is a special case that can respect sticky modes. */
624 switch (ts->uv_sticky) {
625 case UV_STICKY_LOCATION: {
627 return true;
628 }
629 if (uvedit_edge_is_face_select_any_other(ts, bm, l, offsets)) {
630 return true;
631 }
632 return false;
633 }
634 case UV_STICKY_DISABLE: {
636 }
637 default: {
638 /* #UV_STICKY_VERT */
640 }
641 }
643 }
644
646 if (ts->selectmode & SCE_SELECT_FACE) {
648 }
651 }
654 }
655
657 }
658
659 if (ts->uv_selectmode & UV_SELECT_VERT) {
660 return uvedit_vert_select_get_no_sync(ts, bm, l) &&
662 }
664}
665
667 const BMesh *bm,
668 const BMLoop *l,
669 const BMUVOffsets &offsets)
670{
671 return uvedit_edge_select_test_ex(scene->toolsettings, bm, l, offsets);
672}
673
675 BMesh *bm,
676 BMLoop *l,
677 const bool select,
678
679 const BMUVOffsets &offsets)
680{
681 const ToolSettings *ts = scene->toolsettings;
682 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
685 return;
686 }
688 }
689
690 const int sticky = ts->uv_sticky;
691 switch (sticky) {
692 case UV_STICKY_DISABLE: {
693 if (uvedit_face_visible_test(scene, l->f)) {
695 }
696 break;
697 }
698 case UV_STICKY_VERT: {
700 break;
701 }
702 default: {
703 /* UV_STICKY_LOCATION (Fallback) */
705 break;
706 }
707 }
708}
709
711 BMesh *bm,
712 BMLoop *l)
713{
714 const ToolSettings *ts = scene->toolsettings;
715 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
717 /* Use mesh selection. */
719 }
720 /* Caller checks for visibility. */
723 }
725}
726
728{
729 const ToolSettings *ts = scene->toolsettings;
730 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
732 /* Use mesh selection. */
734 }
735 /* Caller checks for visibility. */
738 }
740}
741
743 BMesh *bm,
744 BMLoop *l,
745 const bool select,
746 const int sticky_flag,
747 const BMUVOffsets &offsets)
748{
750 /* Set edge flags. Rely on this for face visibility checks */
751 uvedit_edge_select_set_noflush(scene, bm, l, select, sticky_flag, offsets);
752
753 /* Vert selections. */
754 BMLoop *l_iter = l;
755 do {
756 if (select) {
757 if (bm_loop_select_edge_check_internal(scene, bm, l_iter)) {
758 uvedit_uv_select_shared_vert(scene, bm, l_iter, true, UV_STICKY_LOCATION, offsets);
759 uvedit_uv_select_shared_vert(scene, bm, l_iter->next, true, UV_STICKY_LOCATION, offsets);
760 }
761 }
762 else {
763 if (!bm_loop_select_edge_check_internal(scene, bm, l_iter)) {
764 if (!uvedit_vert_is_edge_select_any_other(scene->toolsettings, bm, l, offsets)) {
765 uvedit_uv_select_shared_vert(scene, bm, l_iter, false, UV_STICKY_LOCATION, offsets);
766 }
767 if (!uvedit_vert_is_edge_select_any_other(scene->toolsettings, bm, l->next, offsets)) {
769 scene, bm, l_iter->next, false, UV_STICKY_LOCATION, offsets);
770 }
771 }
772 }
773 } while (((l_iter = l_iter->radial_next) != l) && (sticky_flag != UV_STICKY_LOCATION));
774}
775
777 BMesh *bm,
778 BMLoop *l,
779 const bool select,
780 const int sticky_flag,
781 const BMUVOffsets &offsets)
782{
783 const ToolSettings *ts = scene->toolsettings;
784 if ((ts->uv_flag & UV_FLAG_SELECT_SYNC) == 0) {
785 BLI_assert(offsets.uv >= 0);
786 }
787 BMLoop *l_iter = l;
788 do {
789 if (uvedit_face_visible_test(scene, l_iter->f)) {
790 if ((sticky_flag == UV_STICKY_VERT) || BM_loop_uv_share_edge_check(l, l_iter, offsets.uv)) {
791 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
793 }
794 else {
796 }
797 }
798 }
799 } while (((l_iter = l_iter->radial_next) != l) && (sticky_flag != UV_STICKY_DISABLE));
800}
801
802void uvedit_edge_select_set(const Scene *scene, BMesh *bm, BMLoop *l, const bool select)
803{
804 if (select) {
806 }
807 else {
809 }
810}
811
813
814{
815 const ToolSettings *ts = scene->toolsettings;
816 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
818 if (ts->selectmode & SCE_SELECT_FACE) {
819 BM_face_select_set(bm, l->f, true);
820 }
821 else if (ts->selectmode & SCE_SELECT_EDGE) {
822 BM_edge_select_set(bm, l->e, true);
823 }
824 else {
825 BM_vert_select_set(bm, l->e->v1, true);
826 BM_vert_select_set(bm, l->e->v2, true);
827 }
828 }
829 else {
831 }
832 }
833 else {
837 }
838}
839
841{
842 const ToolSettings *ts = scene->toolsettings;
843
844 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
846 if (ts->selectmode & SCE_SELECT_FACE) {
847 BM_face_select_set(bm, l->f, false);
848 }
849 else if (ts->selectmode & SCE_SELECT_EDGE) {
850 BM_edge_select_set(bm, l->e, false);
851 }
852 else {
853 BM_vert_select_set(bm, l->e->v1, false);
854 BM_vert_select_set(bm, l->e->v2, false);
855 }
856 }
857 else {
859 if ((ts->selectmode & SCE_SELECT_VERTEX) == 0) {
860 /* Deselect UV vertex if not part of another edge selection */
863 }
866 }
867 }
868 else {
871 }
872 }
873 }
874 else {
876 if ((ts->uv_selectmode & UV_SELECT_VERT) == 0) {
877 /* Deselect UV vertex if not part of another edge selection */
880 }
883 }
884 }
885 else {
888 }
889 }
890}
891
893 const BMesh *bm,
894 const BMLoop *l,
895 const BMUVOffsets &offsets)
896{
897 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
898
899 if ((bm->uv_select_sync_valid == false) && (ts->selectmode == SCE_SELECT_FACE)) {
900 /* Face only is a special case that can respect sticky modes. */
901 switch (ts->uv_sticky) {
902 case UV_STICKY_LOCATION: {
904 return true;
905 }
906 if (uvedit_vert_is_face_select_any_other(ts, bm, l, offsets)) {
907 return true;
908 }
909 return false;
910 }
911 case UV_STICKY_DISABLE: {
913 }
914 default: {
915 /* #UV_STICKY_VERT */
917 }
918 }
920 }
921
923 /* Pass. */
924 }
925 else if ((ts->selectmode & ~SCE_SELECT_FACE) == SCE_SELECT_EDGE) {
926 /* Edge/Face is a special case that can respect sticky modes. */
927 switch (ts->uv_sticky) {
928 case UV_STICKY_LOCATION: {
930 return true;
931 }
932 if (uvedit_vert_is_edge_select_any_other(ts, bm, l, offsets)) {
933 return true;
934 }
935 return false;
936 }
937 case UV_STICKY_DISABLE: {
940 }
941 default: {
942 /* #UV_STICKY_VERT */
944 }
945 }
947 }
948
950 if (ts->selectmode & SCE_SELECT_FACE) {
952 }
953 if (ts->selectmode & SCE_SELECT_EDGE) {
954 /* Are you looking for `uvedit_edge_select_test(...)` instead? */
955 }
957 }
959 }
960
961 if (ts->selectmode & SCE_SELECT_FACE) {
962 /* Are you looking for `uvedit_face_select_test(...)` instead? */
963 }
964
965 if (ts->selectmode & SCE_SELECT_EDGE) {
966 /* Are you looking for `uvedit_edge_select_test(...)` instead? */
967 }
968
970}
971
972bool uvedit_uv_select_test(const Scene *scene,
973 const BMesh *bm,
974 const BMLoop *l,
975 const BMUVOffsets &offsets)
976{
977 return uvedit_uv_select_test_ex(scene->toolsettings, bm, l, offsets);
978}
979
981 const Scene *scene, BMesh *bm, BMLoop *l, const bool select, const BMUVOffsets &offsets)
982{
983 const ToolSettings *ts = scene->toolsettings;
984 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
987 return;
988 }
989 }
990
991 const int sticky = ts->uv_sticky;
992 switch (sticky) {
993 case UV_STICKY_DISABLE: {
994 if (uvedit_face_visible_test(scene, l->f)) {
996 }
997 break;
998 }
999 case UV_STICKY_VERT: {
1001 break;
1002 }
1003 default: {
1004 /* UV_STICKY_LOCATION. */
1006 break;
1007 }
1008 }
1009}
1010
1012 BMesh *bm,
1013 BMLoop *l,
1014 const bool select,
1015 const int sticky_flag,
1016
1017 const BMUVOffsets &offsets)
1018{
1020 BLI_assert(offsets.uv >= 0);
1021
1022 BMEdge *e_first, *e_iter;
1023 e_first = e_iter = l->e;
1024 do {
1025 BMLoop *l_radial_iter = e_iter->l;
1026 if (!l_radial_iter) {
1027 continue; /* Skip wire edges with no loops. */
1028 }
1029 do {
1030 if (l_radial_iter->v == l->v) {
1031 if (uvedit_face_visible_test(scene, l_radial_iter->f)) {
1032 bool do_select = false;
1033 if (sticky_flag == UV_STICKY_VERT) {
1034 do_select = true;
1035 }
1036 else if (BM_loop_uv_share_vert_check(l, l_radial_iter, offsets.uv)) {
1037 do_select = true;
1038 }
1039
1040 if (do_select) {
1041 uvedit_uv_select_set(scene, bm, l_radial_iter, select);
1042 }
1043 }
1044 }
1045 } while ((l_radial_iter = l_radial_iter->radial_next) != e_iter->l);
1046 } while ((e_iter = BM_DISK_EDGE_NEXT(e_iter, l->v)) != e_first);
1047}
1048
1049void uvedit_uv_select_set(const Scene *scene, BMesh *bm, BMLoop *l, const bool select)
1050{
1051 if (select) {
1052 uvedit_uv_select_enable(scene, bm, l);
1053 }
1054 else {
1055 uvedit_uv_select_disable(scene, bm, l);
1056 }
1057}
1058
1060{
1061 const ToolSettings *ts = scene->toolsettings;
1062
1063 if (ts->selectmode & SCE_SELECT_EDGE) {
1064 /* Are you looking for `uvedit_edge_select_set(...)` instead? */
1065 }
1066
1067 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
1069 if (ts->selectmode & SCE_SELECT_FACE) {
1070 BM_face_select_set(bm, l->f, true);
1071 }
1072 else {
1073 BM_vert_select_set(bm, l->v, true);
1074 }
1075 }
1076 else {
1078 }
1079 }
1080 else {
1082 }
1083}
1084
1086{
1087 const ToolSettings *ts = scene->toolsettings;
1088
1089 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
1091 if (ts->selectmode & SCE_SELECT_FACE) {
1092 BM_face_select_set(bm, l->f, false);
1093 }
1094 else {
1095 BM_vert_select_set(bm, l->v, false);
1096 }
1097 }
1098 else {
1100 }
1101 }
1102 else {
1103 uvedit_vert_select_set_no_sync(ts, bm, l, false);
1104 }
1105}
1106
1108 BMLoop *l_src,
1109 const BMUVOffsets &offsets)
1110{
1111 BLI_assert(offsets.uv >= 0);
1112 BMLoop *l_other = nullptr;
1113 BMLoop *l_iter = l_src->radial_next;
1114 if (l_iter != l_src) {
1115 do {
1116 if (uvedit_face_visible_test(scene, l_iter->f) &&
1117 BM_loop_uv_share_edge_check(l_src, l_iter, offsets.uv))
1118 {
1119 /* Check UVs are contiguous. */
1120 if (l_other == nullptr) {
1121 l_other = l_iter;
1122 }
1123 else {
1124 /* Only use when there is a single alternative. */
1125 l_other = nullptr;
1126 break;
1127 }
1128 }
1129 } while ((l_iter = l_iter->radial_next) != l_src);
1130 }
1131 return l_other;
1132}
1133
1135 BMLoop *l_edge,
1136 BMVert *v_pivot,
1137 const BMUVOffsets &offsets)
1138{
1140 nullptr);
1141
1142 BMLoop *l_step = l_edge;
1143 l_step = (l_step->v == v_pivot) ? l_step->prev : l_step->next;
1144 BMLoop *l_step_last = nullptr;
1145 do {
1146 BLI_assert(BM_vert_in_edge(l_step->e, v_pivot));
1147 l_step_last = l_step;
1148 l_step = uvedit_loop_find_other_radial_loop_with_visible_face(scene, l_step, offsets);
1149 if (l_step) {
1150 l_step = (l_step->v == v_pivot) ? l_step->prev : l_step->next;
1151 }
1152 } while (l_step != nullptr);
1153
1154 if (l_step_last != nullptr) {
1156 nullptr);
1157 }
1158
1159 return l_step_last;
1160}
1161
1163
1164/* -------------------------------------------------------------------- */
1167
1177
1179{
1180 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
1183 /* Caller checks for visibility. */
1186 }
1187 return uvedit_edge_select_get_no_sync(ts, bm, l);
1188}
1189
1191 const BMesh *bm,
1192 BMLoop *l,
1193 const bool select)
1194{
1195 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
1199 return;
1200 }
1202}
1203
1205 const BMesh *bm,
1206 BMLoop *l,
1207 const bool select)
1208{
1209 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
1213 return;
1214 }
1216}
1217
1219
1220/* -------------------------------------------------------------------- */
1223
1224UvNearestHit uv_nearest_hit_init_dist_px(const View2D *v2d, const float dist_px)
1225{
1226 UvNearestHit hit = {nullptr};
1227 hit.dist_sq = square_f(U.pixelsize * dist_px);
1228 hit.scale[0] = ui::view2d_scale_get_x(v2d);
1229 hit.scale[1] = ui::view2d_scale_get_y(v2d);
1230 return hit;
1231}
1232
1234{
1235 UvNearestHit hit = {nullptr};
1236 hit.dist_sq = FLT_MAX;
1237 hit.scale[0] = ui::view2d_scale_get_x(v2d);
1238 hit.scale[1] = ui::view2d_scale_get_y(v2d);
1239 return hit;
1240}
1241
1243{
1244 UvNearestHit hit = {nullptr};
1245 hit.dist_sq = FLT_MAX;
1246 hit.scale[0] = 1.0f;
1247 hit.scale[1] = 1.0f;
1248 return hit;
1249}
1250
1252 UvNearestHit *hit,
1253 const short uv_selectmode)
1254{
1255 /* When not selecting faces, find the nearest vertex or edge within the hit face.
1256 * This is needed in some cases where "face" selection is used as a fallback
1257 * but the callers expect `hit.l` to be set (during island selection).
1258 *
1259 * For vertex and edge selection it is important that `hit.l` is set when `found == true`,
1260 * since in that case the caller expects `found` to mean a found element that matches
1261 * the current selection mode, see: #152045.
1262 *
1263 * If this isn't needed, passing in a `uv_selectmode` of #UV_SELECT_FACE is a harmless NOP. */
1265 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
1266
1267 if (uv_selectmode & UV_SELECT_VERT) {
1268 /* Find the loop with the nearest UV vertex. */
1269 BMLoop *l_iter, *l_first, *l_best;
1270 float dist_best_sq = FLT_MAX;
1271 /* Initialize to first loop, as null `hit.l` can crash, see: #152045. */
1272 l_iter = l_first = l_best = BM_FACE_FIRST_LOOP(hit->efa);
1273 do {
1274 const float *luv = BM_ELEM_CD_GET_FLOAT_P(l_iter, cd_loop_uv_offset);
1275 float delta_uv[2];
1276 sub_v2_v2v2(delta_uv, co, luv);
1277 mul_v2_v2(delta_uv, hit->scale);
1278 const float dist_test_sq = len_squared_v2(delta_uv);
1279 if (dist_test_sq < dist_best_sq) {
1280 dist_best_sq = dist_test_sq;
1281 l_best = l_iter;
1282 }
1283 } while ((l_iter = l_iter->next) != l_first);
1284 hit->l = l_best;
1285 }
1286 else if (uv_selectmode & UV_SELECT_EDGE) {
1287 /* Find the loop with the nearest UV edge. */
1288 BMLoop *l_iter, *l_first, *l_best;
1289 float dist_best_sq = FLT_MAX;
1290 /* Initialize to first loop, as null `hit.l` can crash, see: #152045. */
1291 l_iter = l_first = l_best = BM_FACE_FIRST_LOOP(hit->efa);
1292 do {
1293 const float *luv = BM_ELEM_CD_GET_FLOAT_P(l_iter, cd_loop_uv_offset);
1294 const float *luv_next = BM_ELEM_CD_GET_FLOAT_P(l_iter->next, cd_loop_uv_offset);
1295 float delta[2];
1296 closest_to_line_segment_v2(delta, co, luv, luv_next);
1297 sub_v2_v2(delta, co);
1298 mul_v2_v2(delta, hit->scale);
1299 const float dist_test_sq = len_squared_v2(delta);
1300 if (dist_test_sq < dist_best_sq) {
1301 dist_best_sq = dist_test_sq;
1302 l_best = l_iter;
1303 }
1304 } while ((l_iter = l_iter->next) != l_first);
1305 hit->l = l_best;
1306 }
1307}
1308
1310 Scene *scene, Object *obedit, const float co[2], const float penalty, UvNearestHit *hit)
1311{
1312 BLI_assert((hit->scale[0] > 0.0f) && (hit->scale[1] > 0.0f));
1314 BMFace *efa;
1315 BMLoop *l;
1316 BMIter iter, liter;
1317 float *luv, *luv_next;
1318 int i;
1319 bool found = false;
1320
1321 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
1322 BLI_assert(offsets.uv >= 0);
1323
1325
1326 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
1327 if (!uvedit_face_visible_test(scene, efa)) {
1328 continue;
1329 }
1330 BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
1331 luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
1332 luv_next = BM_ELEM_CD_GET_FLOAT_P(l->next, offsets.uv);
1333
1334 float delta[2];
1335 closest_to_line_segment_v2(delta, co, luv, luv_next);
1336
1337 sub_v2_v2(delta, co);
1338 mul_v2_v2(delta, hit->scale);
1339
1340 float dist_test_sq = len_squared_v2(delta);
1341
1342 /* Ensures that successive selection attempts will select other edges sharing the same
1343 * UV coordinates as the previous selection. */
1344 if ((penalty != 0.0f) && uvedit_edge_select_test(scene, bm, l, offsets)) {
1345 dist_test_sq = square_f(sqrtf(dist_test_sq) + penalty);
1346 }
1347 if (dist_test_sq < hit->dist_sq) {
1348 hit->ob = obedit;
1349 hit->efa = efa;
1350
1351 hit->l = l;
1352
1353 hit->dist_sq = dist_test_sq;
1354 found = true;
1355 }
1356 }
1357 }
1358 return found;
1359}
1360
1362 const Span<Object *> objects,
1363 const float co[2],
1364 const float penalty,
1365 UvNearestHit *hit)
1366{
1367 bool found = false;
1368 for (Object *obedit : objects) {
1369 if (uv_find_nearest_edge(scene, obedit, co, penalty, hit)) {
1370 found = true;
1371 }
1372 }
1373 return found;
1374}
1375
1377 Scene *scene, Object *obedit, const float co[2], UvNearestHit *hit, const bool only_in_face)
1378{
1379 BLI_assert((hit->scale[0] > 0.0f) && (hit->scale[1] > 0.0f));
1381 bool found = false;
1382
1383 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
1384
1385 BMIter iter;
1386 BMFace *efa;
1387
1388 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
1389 if (!uvedit_face_visible_test(scene, efa)) {
1390 continue;
1391 }
1392
1393 float cent[2];
1394 BM_face_uv_calc_center_median(efa, cd_loop_uv_offset, cent);
1395
1396 float delta[2];
1397 sub_v2_v2v2(delta, co, cent);
1398 mul_v2_v2(delta, hit->scale);
1399
1400 const float dist_test_sq = len_squared_v2(delta);
1401
1402 if (dist_test_sq < hit->dist_sq) {
1403
1404 if (only_in_face) {
1405 if (!BM_face_uv_point_inside_test(efa, co, cd_loop_uv_offset)) {
1406 continue;
1407 }
1408 }
1409
1410 hit->ob = obedit;
1411 hit->efa = efa;
1412 hit->dist_sq = dist_test_sq;
1413 found = true;
1414 }
1415 }
1416 return found;
1417}
1418
1419bool uv_find_nearest_face(Scene *scene, Object *obedit, const float co[2], UvNearestHit *hit)
1420{
1421 return uv_find_nearest_face_ex(scene, obedit, co, hit, false);
1422}
1423
1425 const Span<Object *> objects,
1426 const float co[2],
1427 UvNearestHit *hit,
1428 const bool only_in_face)
1429{
1430 bool found = false;
1431 for (Object *obedit : objects) {
1432 if (uv_find_nearest_face_ex(scene, obedit, co, hit, only_in_face)) {
1433 found = true;
1434 }
1435 }
1436 return found;
1437}
1438
1440 const Span<Object *> objects,
1441 const float co[2],
1442 UvNearestHit *hit)
1443{
1444 return uv_find_nearest_face_multi_ex(scene, objects, co, hit, false);
1445}
1446
1447static bool uv_nearest_between(const BMLoop *l, const float co[2], const int cd_loop_uv_offset)
1448{
1449 const float *uv_prev = BM_ELEM_CD_GET_FLOAT_P(l->prev, cd_loop_uv_offset);
1450 const float *uv_curr = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
1451 const float *uv_next = BM_ELEM_CD_GET_FLOAT_P(l->next, cd_loop_uv_offset);
1452
1453 return ((line_point_side_v2(uv_prev, uv_curr, co) > 0.0f) &&
1454 (line_point_side_v2(uv_next, uv_curr, co) <= 0.0f));
1455}
1456
1458 Scene *scene, Object *obedit, float const co[2], const float penalty_dist, UvNearestHit *hit)
1459{
1460 BLI_assert((hit->scale[0] > 0.0f) && (hit->scale[1] > 0.0f));
1461 bool found = false;
1462
1464 BMFace *efa;
1465 BMIter iter;
1466
1468
1469 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
1470 BLI_assert(offsets.uv >= 0);
1471
1472 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
1473 if (!uvedit_face_visible_test(scene, efa)) {
1474 continue;
1475 }
1476
1477 BMIter liter;
1478 BMLoop *l;
1479 int i;
1480 BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
1481 float *luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
1482
1483 float delta[2];
1484
1485 sub_v2_v2v2(delta, co, luv);
1486 mul_v2_v2(delta, hit->scale);
1487
1488 float dist_test_sq = len_squared_v2(delta);
1489
1490 /* Ensures that successive selection attempts will select other vertices sharing the same
1491 * UV coordinates */
1492 if ((penalty_dist != 0.0f) && uvedit_uv_select_test(scene, bm, l, offsets)) {
1493 dist_test_sq = square_f(sqrtf(dist_test_sq) + penalty_dist);
1494 }
1495
1496 if (dist_test_sq <= hit->dist_sq) {
1497 if (dist_test_sq == hit->dist_sq) {
1498 if (!uv_nearest_between(l, co, offsets.uv)) {
1499 continue;
1500 }
1501 }
1502
1503 hit->dist_sq = dist_test_sq;
1504
1505 hit->ob = obedit;
1506 hit->efa = efa;
1507 hit->l = l;
1508 found = true;
1509 }
1510 }
1511 }
1512
1513 return found;
1514}
1515
1517 const Span<Object *> objects,
1518 float const co[2],
1519 const float penalty_dist,
1520 UvNearestHit *hit)
1521{
1522 bool found = false;
1523 for (Object *obedit : objects) {
1524 if (uv_find_nearest_vert(scene, obedit, co, penalty_dist, hit)) {
1525 found = true;
1526 }
1527 }
1528 return found;
1529}
1530
1531static bool uvedit_nearest_uv(const Scene *scene,
1532 Object *obedit,
1533 const float co[2],
1534 const float scale[2],
1535 const bool ignore_selected,
1536 float *dist_sq,
1537 float r_uv[2])
1538{
1540 BMIter iter;
1541 BMFace *efa;
1542 const float *uv_best = nullptr;
1543 float dist_best = *dist_sq;
1544 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
1545 BLI_assert(offsets.uv >= 0);
1546 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
1547 if (!uvedit_face_visible_test(scene, efa)) {
1548 continue;
1549 }
1550 BMLoop *l_iter, *l_first;
1551 l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
1552 do {
1553 if (ignore_selected && uvedit_uv_select_test(scene, bm, l_iter, offsets)) {
1554 continue;
1555 }
1556
1557 const float *uv = BM_ELEM_CD_GET_FLOAT_P(l_iter, offsets.uv);
1558 float co_tmp[2];
1559 mul_v2_v2v2(co_tmp, scale, uv);
1560 const float dist_test = len_squared_v2v2(co, co_tmp);
1561 if (dist_best > dist_test) {
1562 dist_best = dist_test;
1563 uv_best = uv;
1564 }
1565 } while ((l_iter = l_iter->next) != l_first);
1566 }
1567
1568 if (uv_best != nullptr) {
1569 copy_v2_v2(r_uv, uv_best);
1570 *dist_sq = dist_best;
1571 return true;
1572 }
1573 return false;
1574}
1575
1577 const Scene *scene,
1578 const Span<Object *> objects,
1579 const float mval_fl[2],
1580 const bool ignore_selected,
1581 float *dist_sq,
1582 float r_uv[2])
1583{
1584 bool found = false;
1585
1586 float scale[2], offset[2];
1587 ui::view2d_scale_get(v2d, &scale[0], &scale[1]);
1588 ui::view2d_view_to_region_fl(v2d, 0.0f, 0.0f, &offset[0], &offset[1]);
1589
1590 float co[2];
1591 sub_v2_v2v2(co, mval_fl, offset);
1592
1593 for (Object *obedit : objects) {
1594 if (uvedit_nearest_uv(scene, obedit, co, scale, ignore_selected, dist_sq, r_uv)) {
1595 found = true;
1596 }
1597 }
1598 return found;
1599}
1600
1602
1603/* -------------------------------------------------------------------- */
1610
1611BMLoop *uv_find_nearest_loop_from_vert(Scene *scene, Object *obedit, BMVert *v, const float co[2])
1612{
1614 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
1615
1616 BMIter liter;
1617 BMLoop *l;
1618 BMLoop *l_found = nullptr;
1619 float dist_best_sq = FLT_MAX;
1620
1621 BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) {
1622 if (!uvedit_face_visible_test(scene, l->f)) {
1623 continue;
1624 }
1625
1626 const float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
1627 const float dist_test_sq = len_squared_v2v2(co, luv);
1628 if (dist_test_sq < dist_best_sq) {
1629 dist_best_sq = dist_test_sq;
1630 l_found = l;
1631 }
1632 }
1633 return l_found;
1634}
1635
1636BMLoop *uv_find_nearest_loop_from_edge(Scene *scene, Object *obedit, BMEdge *e, const float co[2])
1637{
1639 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
1640
1641 BMIter eiter;
1642 BMLoop *l;
1643 BMLoop *l_found = nullptr;
1644 float dist_best_sq = FLT_MAX;
1645
1646 BM_ITER_ELEM (l, &eiter, e, BM_LOOPS_OF_EDGE) {
1647 if (!uvedit_face_visible_test(scene, l->f)) {
1648 continue;
1649 }
1650 const float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
1651 const float *luv_next = BM_ELEM_CD_GET_FLOAT_P(l->next, cd_loop_uv_offset);
1652 const float dist_test_sq = dist_squared_to_line_segment_v2(co, luv, luv_next);
1653 if (dist_test_sq < dist_best_sq) {
1654 dist_best_sq = dist_test_sq;
1655 l_found = l;
1656 }
1657 }
1658 return l_found;
1659}
1660
1662
1663/* -------------------------------------------------------------------- */
1666
1667static bool uvedit_select_pin_ok_or_report(const Scene *scene, ReportList *reports)
1668{
1670 BKE_report(reports, RPT_ERROR, "Pinned vertices can be selected in Vertex Mode only");
1671 return false;
1672 }
1673 return true;
1674}
1675
1677{
1678 const ToolSettings *ts = scene->toolsettings;
1681
1682 /* Needed because this data must *not* be used for select-sync
1683 * once this has been manipulated with select-sync disabled. */
1685}
1686
1691
1693{
1694 const ToolSettings *ts = scene->toolsettings;
1695 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
1697 }
1698 else {
1700 }
1701}
1702
1704 const BMesh *bm,
1705 const BMLoop *l,
1706 const BMUVOffsets &offsets)
1707{
1708 BLI_assert(offsets.uv >= 0);
1709 BMEdge *e_iter = l->e;
1710 do {
1711 BMLoop *l_radial_iter = e_iter->l;
1712 if (!l_radial_iter) {
1713 continue; /* Skip wire edges with no loops. */
1714 }
1715 do {
1716 if (!uvedit_face_visible_test_ex(ts, l_radial_iter->f)) {
1717 continue;
1718 }
1719 /* Use #l_other to check if the uvs are connected (share the same uv coordinates)
1720 * and #l_radial_iter for the actual edge selection test. */
1721 BMLoop *l_other = (l_radial_iter->v != l->v) ? l_radial_iter->next : l_radial_iter;
1722 if (BM_loop_uv_share_vert_check(l, l_other, offsets.uv) &&
1723 uvedit_edge_select_test_ex(ts, bm, l_radial_iter, offsets))
1724 {
1725 return true;
1726 }
1727 } while ((l_radial_iter = l_radial_iter->radial_next) != e_iter->l);
1728 } while ((e_iter = BM_DISK_EDGE_NEXT(e_iter, l->v)) != l->e);
1729
1730 return false;
1731}
1732
1734 const BMesh *bm,
1735 const BMLoop *l,
1736 const BMUVOffsets &offsets)
1737{
1738 BLI_assert(offsets.uv >= 0);
1739 BMLoop *l_radial_iter = l->radial_next;
1740 if (l_radial_iter == l) {
1741 return false;
1742 }
1743 do {
1744 if (!uvedit_face_visible_test_ex(ts, l_radial_iter->f)) {
1745 continue;
1746 }
1747 if (BM_loop_uv_share_edge_check(l, l_radial_iter, offsets.uv) &&
1748 uvedit_face_select_test_ex(ts, bm, l_radial_iter->f))
1749 {
1750 return true;
1751 }
1752 } while ((l_radial_iter = l_radial_iter->radial_next) != l);
1753
1754 return false;
1755}
1756
1758 const BMesh *bm,
1759 const BMLoop *l,
1760 const BMUVOffsets &offsets)
1761{
1762 BLI_assert(offsets.uv >= 0);
1763 BMIter liter;
1764 BMLoop *l_iter;
1765 BM_ITER_ELEM (l_iter, &liter, l->v, BM_LOOPS_OF_VERT) {
1766 if (!uvedit_face_visible_test_ex(ts, l_iter->f) || (l_iter->f == l->f)) {
1767 continue;
1768 }
1769 if (BM_loop_uv_share_vert_check(l, l_iter, offsets.uv) &&
1770 uvedit_face_select_test_ex(ts, bm, l_iter->f))
1771 {
1772 return true;
1773 }
1774 }
1775 return false;
1776}
1777
1779 const BMesh *bm,
1780 const BMLoop *l,
1781 const BMUVOffsets &offsets)
1782{
1783 BLI_assert(offsets.uv >= 0);
1784 BMIter liter;
1785 BMLoop *l_iter;
1786 BM_ITER_ELEM (l_iter, &liter, l->v, BM_LOOPS_OF_VERT) {
1787 if ((l_iter->f == l->f) || !uvedit_face_visible_test_ex(ts, l_iter->f)) {
1788 continue;
1789 }
1790 if (BM_loop_uv_share_vert_check(l, l_iter, offsets.uv) &&
1791 !uvedit_face_select_test_ex(ts, bm, l_iter->f))
1792 {
1793 return false;
1794 }
1795 }
1796 return true;
1797}
1798
1799static void bm_clear_uv_vert_selection(const Scene *scene, BMesh *bm)
1800{
1801 const ToolSettings *ts = scene->toolsettings;
1802 BMFace *efa;
1803 BMLoop *l;
1804 BMIter iter, liter;
1805 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
1806 if (!uvedit_face_visible_test(scene, efa)) {
1807 continue;
1808 }
1809 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
1810 uvedit_vert_select_set_no_sync(ts, bm, l, false);
1811 }
1812 }
1813}
1814
1816
1817/* -------------------------------------------------------------------- */
1825
1827{
1828 BLI_assert(bm && (ts->uv_flag & UV_FLAG_SELECT_SYNC) == 0);
1831}
1839{
1840 BLI_assert(bm && (ts->uv_flag & UV_FLAG_SELECT_SYNC) == 0);
1843}
1844
1846 const BMesh *bm,
1847 BMLoop *l,
1848 bool select)
1849{
1850 BLI_assert(bm && (ts->uv_flag & UV_FLAG_SELECT_SYNC) == 0);
1851 BLI_assert(bm->uv_select_sync_valid == false); /* #uvedit_select_prepare_custom_data ensures. */
1855}
1857 const BMesh *bm,
1858 BMLoop *l,
1859 bool select)
1860{
1861 BLI_assert(bm && (ts->uv_flag & UV_FLAG_SELECT_SYNC) == 0);
1862 BLI_assert(bm->uv_select_sync_valid == false); /* #uvedit_select_prepare_custom_data ensures. */
1866}
1867
1869 const BMesh *bm,
1870 BMFace *f,
1871 bool select)
1872{
1873 BLI_assert(bm && (ts->uv_flag & UV_FLAG_SELECT_SYNC) == 0);
1874 BLI_assert(bm->uv_select_sync_valid == false); /* #uvedit_select_prepare_custom_data ensures. */
1878}
1879
1881
1882/* -------------------------------------------------------------------- */
1888
1889namespace ed::uv {
1890
1891std::unique_ptr<UVSyncSelectFromMesh> UVSyncSelectFromMesh::create_if_needed(
1892 const ToolSettings &ts, BMesh &bm)
1893{
1894 if ((ts.uv_flag & UV_FLAG_SELECT_SYNC) == 0) {
1895 return nullptr;
1896 }
1898 return nullptr;
1899 }
1900 if (bm.uv_select_sync_valid == false) {
1901 return nullptr;
1902 }
1903 const int cd_loop_uv_offset = CustomData_get_active_layer(&bm.ldata, CD_PROP_FLOAT2);
1904 if (cd_loop_uv_offset == -1) {
1905 return nullptr;
1906 }
1907 return std::make_unique<UVSyncSelectFromMesh>(bm, ts.uv_sticky);
1908}
1909
1911{
1912 const int cd_loop_uv_offset = CustomData_get_active_layer(&bm_.ldata, CD_PROP_FLOAT2);
1913 BLI_assert(cd_loop_uv_offset != -1);
1914
1915 const bool shared = uv_sticky_ == UV_STICKY_LOCATION;
1916 const BMUVSelectPickParams uv_pick_params = {
1917 /*cd_loop_uv_offset*/ cd_loop_uv_offset,
1918 /*shared*/ shared,
1919 };
1920
1922 &bm_, false, uv_pick_params, bm_verts_deselect_, bm_edges_deselect_, bm_faces_deselect_);
1923
1925 &bm_, true, uv_pick_params, bm_verts_select_, bm_edges_select_, bm_faces_select_);
1926}
1927
1928/* Select. */
1929
1931{
1932 bm_verts_select_.append(v);
1933}
1935{
1936 bm_edges_select_.append(f);
1937}
1939{
1940 bm_faces_select_.append(f);
1941}
1942
1943/* De-Select. */
1944
1946{
1947 bm_verts_deselect_.append(v);
1948}
1950{
1951 bm_edges_deselect_.append(f);
1952}
1954{
1955 bm_faces_deselect_.append(f);
1956}
1957
1958/* Select set. */
1959
1961{
1962 if (value) {
1963 bm_verts_select_.append(v);
1964 }
1965 else {
1966 bm_verts_deselect_.append(v);
1967 }
1968}
1970{
1971 if (value) {
1972 bm_edges_select_.append(f);
1973 }
1974 else {
1975 bm_edges_deselect_.append(f);
1976 }
1977}
1979{
1980 if (value) {
1981 bm_faces_select_.append(f);
1982 }
1983 else {
1984 bm_faces_deselect_.append(f);
1985 }
1986}
1987
1988} // namespace ed::uv
1989
1991
1992/* -------------------------------------------------------------------- */
1996
1998{
1999 const ToolSettings *ts = scene->toolsettings;
2002
2004
2005 /* Vertex Mode only. */
2006 if (ts->uv_selectmode & UV_SELECT_VERT) {
2007 BMFace *efa;
2008 BMLoop *l;
2009 BMIter iter, liter;
2010 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
2011 if (!uvedit_face_visible_test(scene, efa)) {
2012 continue;
2013 }
2014 bool select_all = true;
2015 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
2016 bool edge_selected = uvedit_vert_select_get_no_sync(ts, bm, l) &&
2018 uvedit_edge_select_set_no_sync(ts, bm, l, edge_selected);
2019 if (!edge_selected) {
2020 select_all = false;
2021 }
2022 }
2023 uvedit_face_select_set_no_sync(ts, bm, efa, select_all);
2024 }
2025 }
2026 else if (ts->uv_selectmode & UV_SELECT_EDGE) {
2027 BMFace *efa;
2028 BMLoop *l;
2029 BMIter iter, liter;
2030 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
2031 if (!uvedit_face_visible_test(scene, efa)) {
2032 continue;
2033 }
2034 bool select_all = true;
2035 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
2036 if (!uvedit_edge_select_get_no_sync(ts, bm, l)) {
2037 select_all = false;
2038 break;
2039 }
2040 }
2041 uvedit_face_select_set_no_sync(ts, bm, efa, select_all);
2042 }
2043 }
2044}
2045
2047
2048/* -------------------------------------------------------------------- */
2051
2052void uvedit_select_flush_from_verts(const Scene *scene, BMesh *bm, const bool select)
2053{
2054 const ToolSettings *ts = scene->toolsettings;
2058
2059 if (select) {
2060 /* Careful when using this in face select mode.
2061 * For face selections with sticky mode enabled, this can create invalid selection states. */
2062 BMFace *efa;
2063 BMLoop *l;
2064 BMIter iter, liter;
2065 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
2066 if (!uvedit_face_visible_test(scene, efa)) {
2067 continue;
2068 }
2069 bool select_all = true;
2070 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
2073 {
2075 }
2076 else {
2077 select_all = false;
2078 }
2079 }
2080 if (select_all) {
2081 uvedit_face_select_set_no_sync(ts, bm, efa, true);
2082 }
2083 }
2084 }
2085 else {
2086 BMFace *efa;
2087 BMLoop *l;
2088 BMIter iter, liter;
2089 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
2090 if (!uvedit_face_visible_test(scene, efa)) {
2091 continue;
2092 }
2093 bool select_all = true;
2094 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
2095 if (!uvedit_vert_select_get_no_sync(ts, bm, l) ||
2097 {
2098 uvedit_edge_select_set_no_sync(ts, bm, l, false);
2099 select_all = false;
2100 }
2101 }
2102 if (select_all == false) {
2103 uvedit_face_select_set_no_sync(ts, bm, efa, false);
2104 }
2105 }
2106 }
2107}
2108
2110
2111/* -------------------------------------------------------------------- */
2114
2122
2124 BMLoop *l_step,
2125 BMVert *v_from,
2126 const BMUVOffsets &offsets)
2127{
2128 if (l_step->f->len == 4) {
2129 BMVert *v_from_next = BM_edge_other_vert(l_step->e, v_from);
2130 BMLoop *l_step_over = (v_from == l_step->v) ? l_step->next : l_step->prev;
2132 scene, l_step_over, offsets);
2133 if (l_step_over) {
2134 return (l_step_over->v == v_from_next) ? l_step_over->prev : l_step_over->next;
2135 }
2136 }
2137 return nullptr;
2138}
2139
2141 BMLoop *l_step,
2142 BMVert *v_from,
2143 const BMUVOffsets &offsets)
2144{
2145 BMVert *v_from_next = BM_edge_other_vert(l_step->e, v_from);
2147 scene, l_step, v_from_next, offsets);
2148}
2149
2150/* TODO(@ideasman42): support this in the BMesh API, as we have for clearing other types. */
2152{
2153 BMIter iter;
2154 BMFace *f;
2155 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
2156 BMIter liter;
2157 BMLoop *l_iter;
2158 BM_ITER_ELEM (l_iter, &liter, f, BM_LOOPS_OF_FACE) {
2160 }
2161 }
2162}
2163
2168 BMesh *bm,
2169 BMLoop *l_init_pair[2],
2170 const BMUVOffsets &offsets)
2171{
2173
2174 for (int side = 0; side < 2; side++) {
2175 BMLoop *l_step_pair[2] = {l_init_pair[0], l_init_pair[1]};
2176 BMVert *v_from = side ? l_step_pair[0]->e->v1 : l_step_pair[0]->e->v2;
2177 /* Disable since we start from the same edge. */
2178 BM_elem_flag_disable(l_step_pair[0], BM_ELEM_TAG);
2179 BM_elem_flag_disable(l_step_pair[1], BM_ELEM_TAG);
2180 while ((l_step_pair[0] != nullptr) && (l_step_pair[1] != nullptr)) {
2181 if (!uvedit_face_visible_test(scene, l_step_pair[0]->f) ||
2182 !uvedit_face_visible_test(scene, l_step_pair[1]->f) ||
2183 /* Check loops have not diverged. */
2184 (uvedit_loop_find_other_radial_loop_with_visible_face(scene, l_step_pair[0], offsets) !=
2185 l_step_pair[1]))
2186 {
2187 break;
2188 }
2189
2190 BLI_assert(l_step_pair[0]->e == l_step_pair[1]->e);
2191
2192 BM_elem_flag_enable(l_step_pair[0], BM_ELEM_TAG);
2193 BM_elem_flag_enable(l_step_pair[1], BM_ELEM_TAG);
2194
2195 BMVert *v_from_next = BM_edge_other_vert(l_step_pair[0]->e, v_from);
2196 /* Walk over both sides, ensure they keep on the same edge. */
2197 for (int i = 0; i < ARRAY_SIZE(l_step_pair); i++) {
2198 l_step_pair[i] = bm_select_edgeloop_double_side_next(
2199 scene, l_step_pair[i], v_from, offsets);
2200 }
2201
2202 if ((l_step_pair[0] && BM_elem_flag_test(l_step_pair[0], BM_ELEM_TAG)) ||
2203 (l_step_pair[1] && BM_elem_flag_test(l_step_pair[1], BM_ELEM_TAG)))
2204 {
2205 break;
2206 }
2207 v_from = v_from_next;
2208 }
2209 }
2210}
2211
2219 BMesh *bm,
2220 BMLoop *l_init,
2221 const BMUVOffsets &offsets,
2222 enum eUVEdgeLoopBoundaryMode boundary_mode,
2223 int r_count_by_select[2])
2224{
2225 if (r_count_by_select) {
2226 r_count_by_select[0] = r_count_by_select[1] = 0;
2227 }
2228
2230
2231 for (int side = 0; side < 2; side++) {
2232 BMLoop *l_step = l_init;
2233 BMVert *v_from = side ? l_step->e->v1 : l_step->e->v2;
2234 /* Disable since we start from the same edge. */
2236 while (l_step != nullptr) {
2237
2238 if (!uvedit_face_visible_test(scene, l_step->f) ||
2239 /* Check the boundary is still a boundary. */
2241 nullptr))
2242 {
2243 break;
2244 }
2245
2246 if (r_count_by_select != nullptr) {
2247 r_count_by_select[uvedit_edge_select_test(scene, bm, l_step, offsets)] += 1;
2248 /* Early exit when mixed could be optional if needed. */
2249 if (r_count_by_select[0] && r_count_by_select[1]) {
2250 r_count_by_select[0] = r_count_by_select[1] = -1;
2251 break;
2252 }
2253 }
2254
2256
2257 BMVert *v_from_next = BM_edge_other_vert(l_step->e, v_from);
2258 BMFace *f_step_prev = l_step->f;
2259
2260 l_step = bm_select_edgeloop_single_side_next(scene, l_step, v_from, offsets);
2261
2262 if (l_step && BM_elem_flag_test(l_step, BM_ELEM_TAG)) {
2263 break;
2264 }
2265 if (boundary_mode == UV_EDGE_LOOP_BOUNDARY_LOOP) {
2266 /* Don't allow walking over the face. */
2267 if (f_step_prev == l_step->f) {
2268 break;
2269 }
2270 }
2271 v_from = v_from_next;
2272 }
2273 }
2274}
2275
2276static int uv_select_edgeloop(Scene *scene, Object *obedit, UvNearestHit *hit, const bool extend)
2277{
2278 const ToolSettings *ts = scene->toolsettings;
2280 bool select;
2281
2282 /* NOTE: this is a special case, even when sync select is enabled,
2283 * the flags are used then flushed to the vertices.
2284 * So these need to be ensured even though the layers aren't used afterwards. */
2285 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
2286
2287 if (extend) {
2288 select = !uvedit_edge_select_test(scene, bm, hit->l, offsets);
2289 }
2290 else {
2291 select = true;
2292 }
2293
2294 BMLoop *l_init_pair[2] = {
2295 hit->l,
2297 };
2298
2299 /* When selecting boundaries, support cycling between selection modes. */
2301
2302 /* Tag all loops that are part of the edge loop (select after).
2303 * This is done so we can */
2304 if (l_init_pair[1] == nullptr) {
2305 int count_by_select[2];
2306 /* If the loops selected toggle the boundaries. */
2308 scene, bm, l_init_pair[0], offsets, boundary_mode, count_by_select);
2309 if (count_by_select[!select] == 0) {
2310 boundary_mode = UV_EDGE_LOOP_BOUNDARY_ALL;
2311
2312 /* If the boundary is selected, toggle back to the loop. */
2314 scene, bm, l_init_pair[0], offsets, boundary_mode, count_by_select);
2315 if (count_by_select[!select] == 0) {
2316 boundary_mode = UV_EDGE_LOOP_BOUNDARY_LOOP;
2317 }
2318 }
2319 }
2320
2321 if (l_init_pair[1] == nullptr) {
2322 uv_select_edgeloop_single_side_tag(scene, bm, l_init_pair[0], offsets, boundary_mode, nullptr);
2323 }
2324 else {
2325 uv_select_edgeloop_double_side_tag(scene, bm, l_init_pair, offsets);
2326 }
2327
2328 /* Apply the selection. */
2329 if (!extend) {
2330 ED_uvedit_deselect_all(scene, obedit, SEL_DESELECT);
2331 }
2332
2333 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
2335 }
2336
2337 /* Select all tagged loops. */
2338 {
2339 BMIter iter;
2340 BMFace *f;
2341 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
2342 BMIter liter;
2343 BMLoop *l_iter;
2344 BM_ITER_ELEM (l_iter, &liter, f, BM_LOOPS_OF_FACE) {
2345 if (BM_elem_flag_test(l_iter, BM_ELEM_TAG)) {
2346 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
2347 uvedit_edge_select_set_with_sticky(scene, bm, l_iter, select, offsets);
2348 }
2349 else {
2350 if (ts->uv_selectmode == UV_SELECT_VERT) {
2351 uvedit_uv_select_set_with_sticky(scene, bm, l_iter, select, offsets);
2352 uvedit_uv_select_set_with_sticky(scene, bm, l_iter->next, select, offsets);
2353 }
2354 else {
2355 uvedit_edge_select_set_with_sticky(scene, bm, l_iter, select, offsets);
2356 }
2357 }
2358 }
2359 }
2360 }
2361 }
2362
2363 return select ? 1 : -1;
2364}
2365
2367
2368/* -------------------------------------------------------------------- */
2371
2372static int uv_select_faceloop(Scene *scene, Object *obedit, UvNearestHit *hit, const bool extend)
2373{
2374 const ToolSettings *ts = scene->toolsettings;
2376 bool select;
2377
2378 if (!extend) {
2379 ED_uvedit_deselect_all(scene, obedit, SEL_DESELECT);
2380 }
2381
2382 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
2384 }
2385 else {
2387 }
2388 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
2389
2391
2392 if (extend) {
2393 select = !uvedit_face_select_test(scene, bm, hit->l->f);
2394 }
2395 else {
2396 select = true;
2397 }
2398
2399 BMLoop *l_pair[2] = {
2400 hit->l,
2402 };
2403
2404 for (int side = 0; side < 2; side++) {
2405 BMLoop *l_step = l_pair[side];
2406 while (l_step) {
2407 if (!uvedit_face_visible_test(scene, l_step->f)) {
2408 break;
2409 }
2410
2411 uvedit_face_select_set_with_sticky(scene, bm, l_step->f, select, offsets);
2412
2414 if (l_step->f->len == 4) {
2415 BMLoop *l_step_opposite = l_step->next->next;
2417 scene, l_step_opposite, offsets);
2418 }
2419 else {
2420 l_step = nullptr;
2421 }
2422
2423 /* Break iteration when `l_step`:
2424 * - is the first loop where we started from.
2425 * - tagged using #BM_ELEM_TAG (meaning this loop has been visited in this iteration). */
2426 if (l_step && BM_elem_flag_test(l_step->f, BM_ELEM_TAG)) {
2427 break;
2428 }
2429 }
2430 }
2431
2432 return (select) ? 1 : -1;
2433}
2434
2436
2437/* -------------------------------------------------------------------- */
2440
2441static int uv_select_edgering(Scene *scene, Object *obedit, UvNearestHit *hit, const bool extend)
2442{
2443 const ToolSettings *ts = scene->toolsettings;
2445 const bool use_face_select = (ts->uv_flag & UV_FLAG_SELECT_SYNC) ?
2446 (ts->selectmode & SCE_SELECT_FACE) :
2448 const bool use_vertex_select = (ts->uv_flag & UV_FLAG_SELECT_SYNC) ?
2451 bool select;
2452
2453 if (!extend) {
2454 ED_uvedit_deselect_all(scene, obedit, SEL_DESELECT);
2455 }
2456
2457 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
2459 }
2460 else {
2462 }
2463 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
2464
2466
2467 if (extend) {
2468 select = !uvedit_edge_select_test(scene, bm, hit->l, offsets);
2469 }
2470 else {
2471 select = true;
2472 }
2473
2474 BMLoop *l_pair[2] = {
2475 hit->l,
2477 };
2478
2479 for (int side = 0; side < 2; side++) {
2480 BMLoop *l_step = l_pair[side];
2481 /* Disable since we start from the same edge. */
2483 while (l_step) {
2484 if (!uvedit_face_visible_test(scene, l_step->f)) {
2485 break;
2486 }
2487
2488 if (use_face_select) {
2489 /* While selecting face loops is now done in a separate function #uv_select_faceloop(),
2490 * this check is still kept for edge ring selection, to keep it consistent with how edge
2491 * ring selection works in face mode in the 3D viewport. */
2492 uvedit_face_select_set_with_sticky(scene, bm, l_step->f, select, offsets);
2493 }
2494 else if (use_vertex_select) {
2495 uvedit_uv_select_set_with_sticky(scene, bm, l_step, select, offsets);
2496 uvedit_uv_select_set_with_sticky(scene, bm, l_step->next, select, offsets);
2497 }
2498 else {
2499 /* Edge select mode */
2500 uvedit_edge_select_set_with_sticky(scene, bm, l_step, select, offsets);
2501 }
2502
2504 if (l_step->f->len == 4) {
2505 BMLoop *l_step_opposite = l_step->next->next;
2507 scene, l_step_opposite, offsets);
2508 if (l_step == nullptr) {
2509 /* Ensure we touch the opposite edge if we can't walk over it. */
2510 l_step = l_step_opposite;
2511 }
2512 }
2513 else {
2514 l_step = nullptr;
2515 }
2516
2517 /* Break iteration when `l_step`:
2518 * - Is the first loop where we started from.
2519 * - Tagged using #BM_ELEM_TAG (meaning this loop has been visited in this iteration).
2520 * - Has its corresponding UV edge selected/unselected based on #select. */
2521 if (l_step && BM_elem_flag_test(l_step->e, BM_ELEM_TAG)) {
2522 /* Previously this check was not done and this resulted in the final edge in the edge ring
2523 * cycle to be skipped during selection (caused by old sticky selection behavior). */
2524 bool is_select;
2525 if (use_vertex_select && !use_face_select) {
2526 /* When selecting vertices in sync-select mode we must read from vertices too
2527 * since flushing to edges happens afterwards. */
2528 is_select = uvedit_uv_select_test(scene, bm, l_step, offsets) &&
2529 uvedit_uv_select_test(scene, bm, l_step->next, offsets);
2530 }
2531 else {
2532 is_select = uvedit_edge_select_test(scene, bm, l_step, offsets);
2533 }
2534 if (is_select == select) {
2535 break;
2536 }
2537 }
2538 }
2539 }
2540
2541 return (select) ? 1 : -1;
2542}
2543
2545
2546/* -------------------------------------------------------------------- */
2549
2560 const BMLoop *l_vert_step,
2561 const BMFace *f_dst,
2562 const UVDelimitMode delimit_mode)
2563{
2564 /* Material is a face property, check independently of edges. */
2565 if (bool(delimit_mode & UVDelimitMode::Material) && f_src->mat_nr != f_dst->mat_nr) {
2566 return true;
2567 }
2568
2569 /* Check edge-based delimiters on the two edges of `f_src` incident on `l_vert_step->v`.
2570 * These are the only edges that can be shared with `f_dst`
2571 * since the faces are linked through this vertex. */
2572 constexpr UVDelimitMode edge_delimit = UVDelimitMode::Seam | UVDelimitMode::Sharp;
2573 if (bool(delimit_mode & edge_delimit)) {
2574 const BMEdge *edges[] = {l_vert_step->e, l_vert_step->prev->e};
2575 bool has_valid_edge = false;
2576 for (const BMEdge *e : edges) {
2577 if (!BM_edge_in_face(e, f_dst)) {
2578 continue;
2579 }
2580 if (bool(delimit_mode & UVDelimitMode::Seam) && BM_elem_flag_test(e, BM_ELEM_SEAM)) {
2581 continue;
2582 }
2583 if (bool(delimit_mode & UVDelimitMode::Sharp) && !BM_elem_flag_test(e, BM_ELEM_SMOOTH)) {
2584 continue;
2585 }
2586 has_valid_edge = true;
2587 break;
2588 }
2589 if (!has_valid_edge) {
2590 return true;
2591 }
2592 }
2593
2594 return false;
2595}
2596
2597static void uv_select_linked_multi(const Scene *scene,
2598 const Span<Object *> objects,
2599 UvNearestHit *hit,
2600 const bool extend,
2601 bool deselect,
2602 const bool toggle,
2603 const bool select_faces,
2604 const UVDelimitMode delimit_mode,
2605 const char hflag)
2606{
2607 if (select_faces) {
2609 }
2610 else {
2611 /* Tagging could be supported for other elements but currently isn't needed. */
2612 BLI_assert(hflag == BM_ELEM_SELECT);
2613 }
2614 /* With BM_ELEM_TAG we only mark faces; it is the responsibility of the function
2615 * that flushes tags to selection to choose select vs deselect. Passing `deselect=true`
2616 * would clear the tags, leaving no tagged faces for the flush function to process.
2617 * See: #153444. */
2618 BLI_assert(!((hflag & BM_ELEM_TAG) && deselect));
2619
2620 const ToolSettings *ts = scene->toolsettings;
2621 const bool uv_select_sync = (ts->uv_flag & UV_FLAG_SELECT_SYNC);
2622
2623 /* loop over objects, or just use hit->ob */
2624 for (const int ob_index : objects.index_range()) {
2625 if (hit && ob_index != 0) {
2626 break;
2627 }
2628 Object *obedit = hit ? hit->ob : objects[ob_index];
2629
2630 BMFace *efa;
2631 BMLoop *l;
2632 BMIter iter, liter;
2633 UvMapVert *vlist, *iterv, *startv;
2634 int i, stacksize = 0, *stack;
2635 uint a;
2636 char *flag;
2638
2639 if (uv_select_sync) {
2641 }
2642 else {
2644 }
2645 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
2646
2647 BM_mesh_elem_table_ensure(bm, BM_FACE); /* we can use this too */
2648
2649 /* NOTE: we had 'use winding' so we don't consider overlapping islands as connected, see #44320
2650 * this made *every* projection split the island into front/back islands.
2651 * Keep 'use_winding' to false, see: #50970.
2652 *
2653 * Better solve this by having a delimit option for select-linked operator,
2654 * keeping island-select working as is. */
2655 UvVertMap *vmap = BM_uv_vert_map_create(bm, !uv_select_sync, true);
2656 if (vmap == nullptr) {
2657 continue;
2658 }
2659
2660 stack = MEM_new_array_uninitialized<int>(bm->totface + 1, "UvLinkStack");
2661 flag = MEM_new_array_zeroed<char>(bm->totface, "UvLinkFlag");
2662
2663 if (hit == nullptr) {
2664 /* Use existing selection */
2665 BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, a) {
2666 if (uvedit_face_visible_test(scene, efa)) {
2667 if (select_faces) {
2668 if (BM_elem_flag_test(efa, hflag)) {
2669 stack[stacksize] = a;
2670 stacksize++;
2671 flag[a] = 1;
2672 }
2673 }
2674 else {
2675 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
2676 if (uvedit_uv_select_test(scene, bm, l, offsets)) {
2677 bool add_to_stack = true;
2678 if (uv_select_sync && (ts->uv_sticky == UV_STICKY_VERT)) {
2679 /* Special case with the following options enabled:
2680 * - Vertex/edge & selection mode.
2681 * - Sticky vertex selection mode.
2682 * - Selection sync enabled.
2683 *
2684 * With this combination of options selecting an island will (necessarily)
2685 * select the island *and* vertices on other islands.
2686 *
2687 * Without this check, a second call to linked select will *grow* the
2688 * selection each time as each new selection reaches the boundaries of
2689 * islands that share vertices but not UVs.
2690 *
2691 * Rules applied here:
2692 * - This loops face isn't selected.
2693 * - The only other fully selected face is connected or,
2694 * - There are no connected fully selected faces UV-connected to this loop.
2695 */
2696 BLI_assert(!select_faces);
2697 if (uvedit_face_select_test(scene, bm, l->f)) {
2698 /* pass */
2699 }
2700 else {
2701 BMIter liter_other;
2702 BMLoop *l_other;
2703 BM_ITER_ELEM (l_other, &liter_other, l->v, BM_LOOPS_OF_VERT) {
2704 if ((l != l_other) && !BM_loop_uv_share_vert_check(l, l_other, offsets.uv) &&
2705 uvedit_face_select_test(scene, bm, l_other->f))
2706 {
2707 add_to_stack = false;
2708 break;
2709 }
2710 }
2711 }
2712 }
2713
2714 if (add_to_stack) {
2715 stack[stacksize] = a;
2716 stacksize++;
2717 flag[a] = 1;
2718 break;
2719 }
2720 }
2721 }
2722 }
2723 }
2724 }
2725 }
2726 else {
2727 BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, a) {
2728 if (efa == hit->efa) {
2729 stack[stacksize] = a;
2730 stacksize++;
2731 flag[a] = 1;
2732 break;
2733 }
2734 }
2735 }
2736
2737 while (stacksize > 0) {
2738
2739 stacksize--;
2740 a = stack[stacksize];
2741
2742 efa = BM_face_at_index(bm, a);
2743
2744 BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
2745
2746 /* make_uv_vert_map_EM sets verts tmp.l to the indices */
2748
2749 startv = vlist;
2750
2751 for (iterv = vlist; iterv; iterv = iterv->next) {
2752 if (iterv->separate) {
2753 startv = iterv;
2754 }
2755 if (iterv->face_index == a) {
2756 break;
2757 }
2758 }
2759
2760 for (iterv = startv; iterv; iterv = iterv->next) {
2761 if ((startv != iterv) && (iterv->separate)) {
2762 break;
2763 }
2764 if (!flag[iterv->face_index]) {
2765 if (delimit_mode != UVDelimitMode(0)) {
2766 BMFace *iterv_f = BM_face_at_index(bm, iterv->face_index);
2767 if (uv_select_linked_delimit_check(efa, l, iterv_f, delimit_mode)) {
2768 continue;
2769 }
2770 }
2771 flag[iterv->face_index] = 1;
2772 stack[stacksize] = iterv->face_index;
2773 stacksize++;
2774 }
2775 }
2776 }
2777 }
2778
2779 /* Toggling - if any of the linked vertices is selected (and visible), we deselect. */
2780 if ((toggle == true) && (extend == false) && (deselect == false)) {
2781 BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, a) {
2782 bool found_selected = false;
2783 if (!flag[a]) {
2784 continue;
2785 }
2786
2787 if (select_faces) {
2788 if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
2789 if (BM_elem_flag_test(efa, hflag)) {
2790 found_selected = true;
2791 }
2792 }
2793 }
2794 else {
2795 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
2796 if (uvedit_uv_select_test(scene, bm, l, offsets)) {
2797 found_selected = true;
2798 break;
2799 }
2800 }
2801
2802 if (found_selected) {
2803 deselect = true;
2804 break;
2805 }
2806 }
2807 }
2808 }
2809
2810#define SET_SELECTION(value) \
2811 if (select_faces) { \
2812 if (hflag == BM_ELEM_SELECT) { \
2813 BM_face_select_set(bm, efa, value); \
2814 } \
2815 else { \
2816 BM_elem_flag_set(efa, hflag, value); \
2817 } \
2818 } \
2819 else { \
2820 uvedit_face_select_set(scene, bm, efa, value); \
2821 } \
2822 (void)0
2823
2824 /* When sync-select is enabled in vertex or edge selection modes,
2825 * selecting an islands faces may select vertices or edges on other UV islands.
2826 * In this case it's important perform selection in two passes,
2827 * otherwise the final vertex/edge selection around UV island boundaries
2828 * will contain a mixed selection depending on the order of faces. */
2829 const bool needs_multi_pass = uv_select_sync &&
2830 (scene->toolsettings->selectmode &
2832 (deselect == false);
2833 const bool deselect_elem = !extend && !deselect && !toggle;
2834
2835 if (needs_multi_pass == false) {
2836 BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, a) {
2837 if (!flag[a]) {
2838 if (deselect_elem) {
2839 SET_SELECTION(false);
2840 }
2841 continue;
2842 }
2843 if (deselect) {
2844 SET_SELECTION(false);
2845 }
2846 else {
2847 SET_SELECTION(true);
2848 }
2849 }
2850 }
2851 else {
2852 /* The same as the previous block, just use multiple passes.
2853 * It just so happens that multi-pass is only needed when selecting (deselect==false). */
2854 BLI_assert(deselect == false);
2855 /* Pass 1 (de-select). */
2856 if (deselect_elem) {
2857 BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, a) {
2858 if (!flag[a]) {
2859 SET_SELECTION(false);
2860 }
2861 }
2862 }
2863 /* Pass 2 (select). */
2864 BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, a) {
2865 if (!flag[a]) {
2866 continue;
2867 }
2868 SET_SELECTION(true);
2869 }
2870 }
2871
2872#undef SET_SELECTION
2873
2874 MEM_delete(stack);
2875 MEM_delete(flag);
2876 BM_uv_vert_map_free(vmap);
2877
2878 if (uv_select_sync) {
2880 if (deselect) {
2882 }
2883 else {
2884 if (!select_faces) {
2886 }
2887 }
2888 }
2889 else {
2891 if (bm->uv_select_sync_valid) {
2892 if (deselect) {
2894 }
2895 else {
2897 }
2899 }
2900 }
2901 }
2902 }
2903}
2904
2906
2907/* -------------------------------------------------------------------- */
2910
2921 const Scene *scene = nullptr;
2922 BMesh *bm = nullptr;
2923
2927 UvVertMap *vmap_ = nullptr;
2929 int *stack_ = nullptr;
2931 bool *face_is_tagged_ = nullptr;
2932
2936 bool has_data = false;
2944 bool has_face = false;
2945
2947
2949 {
2950 init(scene, bm);
2951 }
2952
2954 {
2955 if (vmap_) {
2957 }
2958 MEM_SAFE_DELETE(stack_);
2959 MEM_SAFE_DELETE(face_is_tagged_);
2960 }
2961 void init(const Scene *scene, BMesh *bm)
2962 {
2963 this->scene = scene;
2964 this->bm = bm;
2965 }
2966
2971 void clear()
2972 {
2973 if (has_face) {
2974 memset(face_is_tagged_, false, sizeof(bool) * bm->totface);
2975 }
2976 has_face = false;
2977 }
2978
2983 bool face_add(BMFace *efa)
2984 {
2985 /* Lazily create the UV vertex map, stack, and face tracking. */
2986 if (!has_data) [[unlikely]] {
2987 const ToolSettings *ts = scene->toolsettings;
2988 const bool uv_select_sync = (ts->uv_flag & UV_FLAG_SELECT_SYNC);
2990 vmap_ = BM_uv_vert_map_create(bm, !uv_select_sync, true);
2991 if (vmap_ == nullptr) [[unlikely]] {
2992 /* This will keep attempting to allocate on every `face_add` call.
2993 * This is weak but such a corner case that it's not worth attempting to
2994 * gracefully handle the code path in the case there is no mapping data to use. */
2995 return false;
2996 }
2997 stack_ = MEM_new_array<int>(bm->totface + 1, __func__);
2998 face_is_tagged_ = MEM_new_array<bool>(bm->totface, __func__);
2999 memset(face_is_tagged_, false, sizeof(bool) * bm->totface);
3000 has_data = true;
3001 }
3002
3003 has_face = true;
3004
3005 const int face_index = BM_elem_index_get(efa);
3006 if (face_is_tagged_[face_index]) {
3007 return false;
3008 }
3009
3010 /* Flood-fill to find and tag all linked faces. */
3011 int stack_len = 0;
3012 stack_[stack_len++] = face_index;
3013 face_is_tagged_[face_index] = true;
3014
3015 while (stack_len > 0) {
3016 const int i = stack_[--stack_len];
3017 BMFace *efa = BM_face_at_index(bm, i);
3018
3019 BMLoop *l;
3020 BMIter liter;
3021 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
3023
3024 /* Find the start of the UV island segment for this vertex. */
3025 UvMapVert *startv = vlist;
3026 for (UvMapVert *iterv = vlist; iterv; iterv = iterv->next) {
3027 if (iterv->separate) {
3028 startv = iterv;
3029 }
3030 if (iterv->face_index == i) {
3031 break;
3032 }
3033 }
3034
3035 /* Add all connected faces from this UV island segment. */
3036 for (UvMapVert *iterv = startv; iterv; iterv = iterv->next) {
3037 if ((startv != iterv) && iterv->separate) {
3038 break;
3039 }
3040 if (!face_is_tagged_[iterv->face_index]) {
3041 face_is_tagged_[iterv->face_index] = true;
3042 stack_[stack_len++] = iterv->face_index;
3043 }
3044 }
3045 }
3046 }
3047
3048 return true;
3049 }
3050
3054 bool face_check(BMFace *efa) const
3055 {
3056 if (!has_face) {
3057 return false;
3058 }
3060 }
3061
3066 void tag_all()
3067 {
3068 if (!has_face) {
3069 return;
3070 }
3071 BMFace *efa;
3072 BMIter iter;
3073 int a;
3074 BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, a) {
3075 if (face_is_tagged_[a]) {
3077 }
3078 }
3079 }
3080
3085 void select_all(const bool select)
3086 {
3087 if (!has_face) {
3088 return;
3089 }
3090 BMFace *efa;
3091 BMIter iter;
3092 int a;
3093 BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, a) {
3094 if (face_is_tagged_[a]) {
3096 }
3097 }
3098 }
3099};
3100
3108 std::optional<Array<UVSelectLinkedHelper>> linked_helpers;
3109
3110 UVCircleSelectState(const Scene *scene, Vector<Object *> objects, const bool use_select_linked)
3111 : objects(std::move(objects))
3112 {
3113 if (use_select_linked) {
3114 linked_helpers.emplace(this->objects.size());
3115 for (const int i : this->objects.index_range()) {
3116 BMesh *bm = BKE_editmesh_bmesh_get_for_write(this->objects[i]);
3117 (*linked_helpers)[i].init(scene, bm);
3118 }
3119 }
3120 }
3121};
3122
3124{
3126 MEM_delete(state);
3127}
3128
3130 const BMesh *bm,
3131 BMVert *eve,
3132 const BMUVOffsets &offsets)
3133{
3134 BMIter liter;
3135 BMLoop *l;
3136
3137 BM_ITER_ELEM (l, &liter, eve, BM_LOOPS_OF_VERT) {
3138 if (!uvedit_face_visible_test(scene, l->f)) {
3139 continue;
3140 }
3141
3142 if (uvedit_uv_select_test(scene, bm, l, offsets)) {
3143 float *luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
3144 return luv;
3145 }
3146 }
3147
3148 return nullptr;
3149}
3150
3152
3153/* -------------------------------------------------------------------- */
3156
3158{
3159 const Main *bmain = CTX_data_main(C);
3160 Scene *scene = CTX_data_scene(C);
3161 ViewLayer *view_layer = CTX_data_view_layer(C);
3162
3163 BMFace *efa;
3164 BMLoop *l;
3165 BMIter iter, liter;
3166 const ToolSettings *ts = scene->toolsettings;
3167
3169 *bmain, scene, view_layer, nullptr);
3170
3171 const bool is_uv_face_selectmode = (ts->uv_flag & UV_FLAG_SELECT_SYNC) ?
3172 (ts->selectmode == SCE_SELECT_FACE) :
3174
3175 for (Object *obedit : objects) {
3177
3178 bool changed = false;
3179
3180 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3182 }
3183 else {
3185 }
3186 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
3187
3188 if ((ts->uv_flag & UV_FLAG_SELECT_SYNC) && (bm->uv_select_sync_valid == false)) {
3190 if (select) {
3191 EDBM_select_more(bm, em->selectmode, true);
3192 }
3193 else {
3194 EDBM_select_less(bm, em->selectmode, true);
3195 }
3196
3197 DEG_id_tag_update(obedit->data, ID_RECALC_SELECT);
3198 WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
3199 continue;
3200 }
3201
3202 if (is_uv_face_selectmode) {
3203
3204 /* clear tags */
3206
3207 /* Tag loops to be selected. */
3208 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
3209 if (uvedit_face_visible_test(scene, efa)) {
3210
3211 if (select) {
3212#define NEIGHBORING_FACE_IS_SEL 1
3213#define CURR_FACE_IS_UNSEL 2
3214
3215 int sel_state = 0;
3216
3217 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
3218 if (uvedit_loop_vert_select_get(ts, bm, l)) {
3219 sel_state |= NEIGHBORING_FACE_IS_SEL;
3220 }
3221 else {
3222 sel_state |= CURR_FACE_IS_UNSEL;
3223 }
3224
3225 if (!uvedit_loop_edge_select_get(ts, bm, l)) {
3226 sel_state |= CURR_FACE_IS_UNSEL;
3227 }
3228
3229 /* If the current face is not selected and at least one neighboring face is
3230 * selected, then tag the current face to grow selection. */
3231 if (sel_state == (NEIGHBORING_FACE_IS_SEL | CURR_FACE_IS_UNSEL)) {
3233 changed = true;
3234 break;
3235 }
3236 }
3237
3238#undef NEIGHBORING_FACE_IS_SEL
3239#undef CURR_FACE_IS_UNSEL
3240 }
3241 else {
3242 if (!uvedit_face_select_test(scene, bm, efa)) {
3243 continue;
3244 }
3245 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
3246 /* Deselect face when at least one of the surrounding faces is not selected */
3247 if (!uvedit_vert_is_all_other_faces_selected(ts, bm, l, offsets)) {
3249 changed = true;
3250 break;
3251 }
3252 }
3253 }
3254 }
3255 }
3256 }
3257 else {
3258
3259 /* clear tags */
3260 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
3261 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
3263 }
3264 }
3265
3266 /* Tag loops to be selected. */
3267 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
3268 if (uvedit_face_visible_test(scene, efa)) {
3269 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
3270
3271 if (uvedit_loop_vert_select_get(ts, bm, l) == select) {
3274 changed = true;
3275 }
3276 }
3277 }
3278 }
3279 }
3280
3281 if (changed) {
3282 if (is_uv_face_selectmode) {
3283 /* Select tagged faces. */
3284 uv_select_flush_from_tag_face(scene, obedit, select);
3285 }
3286 else {
3287 /* Select tagged loops. */
3288 uv_select_flush_from_tag_loop(scene, obedit, select);
3289 /* Set/unset edge flags based on selected verts. */
3290 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3291 /* Pass. */
3292 }
3293 else {
3295 }
3296 }
3297
3298 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3299 BLI_assert(bm->uv_select_sync_valid); /* Already handled. */
3300 if (select) {
3302 }
3303 else {
3305 }
3307 }
3308
3309 DEG_id_tag_update(obedit->data, ID_RECALC_SELECT);
3310 WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
3311 }
3312 }
3313
3314 return OPERATOR_FINISHED;
3315}
3316
3318{
3319 return uv_select_more_less(C, true);
3320}
3321
3323{
3324 /* identifiers */
3325 ot->name = "Select More";
3326 ot->description = "Select more UV vertices connected to initial selection";
3327 ot->idname = "UV_OT_select_more";
3329
3330 /* API callbacks. */
3333}
3334
3336{
3337 return uv_select_more_less(C, false);
3338}
3339
3341{
3342 /* identifiers */
3343 ot->name = "Select Less";
3344 ot->description = "Deselect UV vertices at the boundary of each selection region";
3345 ot->idname = "UV_OT_select_less";
3347
3348 /* API callbacks. */
3351}
3352
3354
3355/* -------------------------------------------------------------------- */
3358
3360{
3361 const ToolSettings *ts = scene->toolsettings;
3362 BMFace *efa;
3363 BMLoop *l;
3364 BMIter iter, liter;
3365
3366 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3367 return (bm->totvertsel || bm->totedgesel || bm->totfacesel);
3368 }
3369
3370 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
3371 if (!uvedit_face_visible_test(scene, efa)) {
3372 continue;
3373 }
3374 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
3376 return true;
3377 }
3378 }
3379 }
3380 return false;
3381}
3382
3384{
3385 bool found = false;
3386 for (Object *obedit : objects) {
3388 if (uvedit_select_is_any_selected(scene, bm)) {
3389 found = true;
3390 break;
3391 }
3392 }
3393 return found;
3394}
3395
3396static void uv_select_all(const Scene *scene, BMesh *bm, bool select_all)
3397{
3398 const ToolSettings *ts = scene->toolsettings;
3399
3400 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3401 /* Clear all partial selection as there is no need for it. */
3402 bm->uv_select_sync_valid = false;
3403
3404 if (select_all) {
3406 }
3407 else {
3409 }
3410 return;
3411 }
3412
3413 BMFace *efa;
3414 BMLoop *l;
3415 BMIter iter, liter;
3416
3418
3419 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
3420 if (!uvedit_face_visible_test(scene, efa)) {
3421 continue;
3422 }
3423 uvedit_face_select_set_no_sync(ts, bm, efa, select_all);
3424 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
3425 uvedit_vert_select_set_no_sync(ts, bm, l, select_all);
3426 uvedit_edge_select_set_no_sync(ts, bm, l, select_all);
3427 }
3428 }
3429}
3430
3431static void uv_select_toggle_all(const Scene *scene, BMesh *bm)
3432{
3433 bool select_any = uvedit_select_is_any_selected(scene, bm);
3434 uv_select_all(scene, bm, !select_any);
3435}
3436
3437static void uv_select_invert(const Scene *scene, BMEditMesh *em, BMesh *bm)
3438{
3439 const ToolSettings *ts = scene->toolsettings;
3440
3441 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3443 bm->uv_select_sync_valid = false;
3444 }
3445 /* If selection wasn't synced, there is no need to sync. */
3446 if (bm->uv_select_sync_valid == false) {
3447 EDBM_select_swap(em, bm);
3449 return;
3450 }
3451
3452 /* Invert */
3453 BMIter iter;
3454 BMFace *efa;
3455
3457 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
3459 continue;
3460 }
3461 BMIter liter;
3462 BMLoop *l;
3463 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
3465 }
3466 }
3467 /* Flush vertices to edges & faces. */
3469 }
3470 else if (em->selectmode & SCE_SELECT_EDGE) {
3471 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
3472
3473 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
3475 continue;
3476 }
3477 BMIter liter;
3478 BMLoop *l;
3479 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
3480 /* No need to flush edges, as they will all be flipped. */
3482 /* Flush back afterwards. */
3484 }
3485 }
3486 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
3488 continue;
3489 }
3490 bool face_select = true;
3491 BMIter liter;
3492 BMLoop *l;
3493 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
3495 if (ts->uv_sticky == UV_STICKY_LOCATION) {
3496 BM_loop_vert_uvselect_set_shared(bm, l, true, offsets.uv);
3497 BM_loop_vert_uvselect_set_shared(bm, l->next, true, offsets.uv);
3498 }
3499 else {
3502 }
3503 }
3504 else {
3505 face_select = false;
3506 }
3507 }
3508 BM_face_uvselect_set_noflush(bm, efa, face_select);
3509 }
3510 /* Edges are flushed to faces inline. */
3511 }
3512 else {
3513 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
3515 continue;
3516 }
3518 }
3519
3520 if (ts->uv_sticky == UV_STICKY_LOCATION) {
3521 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
3523 }
3524 }
3525
3526 /* NOTE: no need to run: #BM_mesh_uvselect_flush_shared_only_select
3527 * because inverting doesn't change the sticky state. */
3529 return;
3530 }
3531
3533 BMFace *efa;
3534 BMLoop *l;
3535 BMIter iter, liter;
3536 char uv_selectmode = ts->uv_selectmode;
3537 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
3538 if (!uvedit_face_visible_test(scene, efa)) {
3539 continue;
3540 }
3541 bool select_all = true;
3542 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
3543 if (uv_selectmode & (UV_SELECT_EDGE | UV_SELECT_FACE)) {
3544 /* Use UV edge selection to find vertices and edges that must be selected. */
3545 bool es = !uvedit_edge_select_get_no_sync(ts, bm, l);
3547 uvedit_vert_select_set_no_sync(ts, bm, l, false);
3548 if (es == false) {
3549 select_all = false;
3550 }
3551 }
3552 /* Use UV vertex selection to find vertices and edges that must be selected. */
3553 else {
3554 BLI_assert(uv_selectmode & UV_SELECT_VERT);
3555 bool vs = !uvedit_vert_select_get_no_sync(ts, bm, l);
3557 uvedit_edge_select_set_no_sync(ts, bm, l, false);
3558 if (vs == false) {
3559 select_all = false;
3560 }
3561 }
3562 }
3563 uvedit_face_select_set_no_sync(ts, bm, efa, select_all);
3564 }
3565
3566 /* Flush based on uv vert/edge flags and current UV select mode */
3567 if (ELEM(uv_selectmode, UV_SELECT_EDGE, UV_SELECT_FACE)) {
3569 }
3570 else {
3571 uvedit_select_flush_from_verts(scene, bm, true);
3572 }
3573}
3574
3575void ED_uvedit_deselect_all(const Scene *scene, Object *obedit, int action)
3576{
3577 const ToolSettings *ts = scene->toolsettings;
3580
3581 /* In the case of where the selection is all or none, there is no need to hold
3582 * a separate state for UV's and the mesh. */
3583 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3584 if (bm->uv_select_sync_valid) {
3585 if (ELEM(action, SEL_SELECT, SEL_DESELECT)) {
3587 }
3588 }
3589 }
3590
3591 switch (action) {
3592 case SEL_TOGGLE: {
3593 uv_select_toggle_all(scene, bm);
3594 break;
3595 }
3596 case SEL_SELECT: {
3597 uv_select_all(scene, bm, true);
3598 break;
3599 }
3600 case SEL_DESELECT: {
3601 uv_select_all(scene, bm, false);
3602 break;
3603 }
3604 case SEL_INVERT: {
3605 uv_select_invert(scene, em, bm);
3606 break;
3607 }
3608 }
3609}
3610
3611static void uv_select_all_perform_multi_ex(const Scene *scene,
3612 const Span<Object *> objects,
3613 int action,
3614 const Object *ob_exclude)
3615{
3616 if (action == SEL_TOGGLE) {
3617 action = uvedit_select_is_any_selected_multi(scene, objects) ? SEL_DESELECT : SEL_SELECT;
3618 }
3619
3620 for (Object *obedit : objects) {
3621 if (ob_exclude && (obedit == ob_exclude)) {
3622 continue;
3623 }
3624 ED_uvedit_deselect_all(scene, obedit, action);
3625 }
3626}
3627
3628static void uv_select_all_perform_multi(const Scene *scene, Span<Object *> objects, int action)
3629{
3630 uv_select_all_perform_multi_ex(scene, objects, action, nullptr);
3631}
3632
3634{
3635 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
3636 const Main *bmain = CTX_data_main(C);
3637 Scene *scene = CTX_data_scene(C);
3638 const ToolSettings *ts = scene->toolsettings;
3639 ViewLayer *view_layer = CTX_data_view_layer(C);
3640
3641 int action = RNA_enum_get(op->ptr, "action");
3642
3644 *bmain, scene, view_layer, nullptr);
3645
3646 uv_select_all_perform_multi(scene, objects, action);
3647
3648 for (Object *obedit : objects) {
3649 uv_select_tag_update_for_object(depsgraph, ts, obedit);
3650 }
3651
3652 return OPERATOR_FINISHED;
3653}
3654
3656{
3657 /* identifiers */
3658 ot->name = "(De)select All";
3659 ot->description = "Change selection of all UV vertices";
3660 ot->idname = "UV_OT_select_all";
3662
3663 /* API callbacks. */
3666
3668}
3669
3671
3672/* -------------------------------------------------------------------- */
3675
3677 const Span<Object *> objects,
3678 const float co[2],
3679 const SelectPick_Params &params)
3680{
3681 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
3682 const ARegion *region = CTX_wm_region(C);
3683 Scene *scene = CTX_data_scene(C);
3684 const ToolSettings *ts = scene->toolsettings;
3685 UvNearestHit hit = region ? uv_nearest_hit_init_dist_px(&region->v2d, 75.0f) :
3687 int selectmode, sticky;
3688 bool found_item = false;
3689 /* 0 == don't flush, 1 == sel, -1 == deselect; only use when selection sync is enabled. */
3690 int flush = 0;
3691 const bool use_select_linked = ED_uvedit_select_island_check(ts);
3692
3693 /* Penalty (in pixels) applied to elements that are already selected
3694 * so elements that aren't already selected are prioritized. */
3695 const float penalty_dist = 3.0f * U.pixelsize;
3696
3697 /* retrieve operation mode */
3698 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3699 if (ts->selectmode & SCE_SELECT_FACE) {
3700 selectmode = UV_SELECT_FACE;
3701 }
3702 else if (ts->selectmode & SCE_SELECT_EDGE) {
3703 selectmode = UV_SELECT_EDGE;
3704 }
3705 else {
3706 selectmode = UV_SELECT_VERT;
3707 }
3708
3709 sticky = UV_STICKY_DISABLE;
3710 }
3711 else {
3712 selectmode = ts->uv_selectmode;
3713 sticky = ts->uv_sticky;
3714 }
3715
3716 /* find nearest element */
3717
3718 if (selectmode == UV_SELECT_VERT) {
3719 /* Find vertex. */
3720 found_item = uv_find_nearest_vert_multi(scene, objects, co, penalty_dist, &hit);
3721
3722 if (use_select_linked && !found_item) {
3723 /* Without this, we can be within the face of an island but too far from an edge,
3724 * see face selection comment for details. */
3725 hit.dist_sq = FLT_MAX;
3726 found_item = uv_find_nearest_face_multi_ex(scene, objects, co, &hit, true);
3727 if (found_item) {
3728 uv_nearest_hit_elem_set_from_face(co, &hit, selectmode);
3729 }
3730 }
3731
3732 if (found_item) {
3733 if ((ts->uv_flag & UV_FLAG_SELECT_SYNC) == 0) {
3736 }
3737 }
3738 }
3739 else if (selectmode == UV_SELECT_EDGE) {
3740 /* find edge */
3741 found_item = uv_find_nearest_edge_multi(scene, objects, co, penalty_dist, &hit);
3742
3743 if (use_select_linked && !found_item) {
3744 /* Without this, we can be within the face of an island but too far from an edge,
3745 * see face selection comment for details. */
3746 hit.dist_sq = FLT_MAX;
3747 found_item = uv_find_nearest_face_multi_ex(scene, objects, co, &hit, true);
3748 if (found_item) {
3749 uv_nearest_hit_elem_set_from_face(co, &hit, selectmode);
3750 }
3751 }
3752
3753 if (found_item) {
3754 if ((ts->uv_flag & UV_FLAG_SELECT_SYNC) == 0) {
3757 }
3758 }
3759 }
3760 else if (selectmode == UV_SELECT_FACE) {
3761 /* find face */
3762 found_item = uv_find_nearest_face_multi(scene, objects, co, &hit);
3763
3764 if (!found_item) {
3765 /* Fallback, perform a second pass without a limited threshold,
3766 * which succeeds as long as the cursor is inside the UV face.
3767 * Useful when zoomed in, to select faces with distant screen-space face centers. */
3768 hit.dist_sq = FLT_MAX;
3769 found_item = uv_find_nearest_face_multi_ex(scene, objects, co, &hit, true);
3770 }
3771
3772 if (found_item) {
3775 }
3776 }
3777
3778 bool found = found_item;
3779 bool changed = false;
3780
3781 bool is_selected = false;
3782 if (found) {
3783 Object *obedit = hit.ob;
3785 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3786 /* Pass. */
3787 }
3788 else {
3790 }
3791 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
3792
3793 if (selectmode == UV_SELECT_FACE) {
3794 is_selected = uvedit_face_select_test(scene, bm, hit.efa);
3795 }
3796 else if (selectmode == UV_SELECT_EDGE) {
3797 is_selected = uvedit_edge_select_test(scene, bm, hit.l, offsets);
3798 }
3799 else {
3800 is_selected = uvedit_uv_select_test(scene, bm, hit.l, offsets);
3801 }
3802 }
3803
3804 if (params.sel_op == SEL_OP_SET) {
3805 if ((found && params.select_passthrough) && is_selected) {
3806 found = false;
3807 }
3808 else if (found || params.deselect_all) {
3809 /* Deselect everything. */
3811 for (Object *obedit : objects) {
3812 uv_select_tag_update_for_object(depsgraph, ts, obedit);
3813 }
3814 changed = true;
3815 }
3816 }
3817
3818 if (found) {
3819 Object *obedit = hit.ob;
3821
3822 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3823 /* Pass. */
3824 }
3825 else {
3827 }
3828 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
3829 BMElem *ele_active = nullptr;
3830
3831 if (use_select_linked) {
3832 const bool extend = params.sel_op == SEL_OP_ADD;
3833 const bool deselect = params.sel_op == SEL_OP_SUB;
3834 const bool toggle = params.sel_op == SEL_OP_XOR;
3835 /* Current behavior of 'extend'
3836 * is actually toggling, so pass extend flag as 'toggle' here */
3838 scene, objects, &hit, extend, deselect, toggle, false, UVDelimitMode(0), BM_ELEM_SELECT);
3839 /* TODO: check if this actually changed. */
3840 changed = true;
3841 }
3842 else {
3844 bool select_value = false;
3845 switch (params.sel_op) {
3846 case SEL_OP_ADD: {
3847 select_value = true;
3848 break;
3849 }
3850 case SEL_OP_SUB: {
3851 select_value = false;
3852 break;
3853 }
3854 case SEL_OP_XOR: {
3855 select_value = !is_selected;
3856 break;
3857 }
3858 case SEL_OP_SET: {
3859 /* Deselect has already been performed. */
3860 select_value = true;
3861 break;
3862 }
3863 case SEL_OP_AND: {
3864 BLI_assert_unreachable(); /* Doesn't make sense for picking. */
3865 break;
3866 }
3867 }
3868
3869 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3871 }
3872
3873 if (selectmode == UV_SELECT_FACE) {
3874 uvedit_face_select_set_with_sticky(scene, bm, hit.efa, select_value, offsets);
3875 flush = 1;
3876 }
3877 else if (selectmode == UV_SELECT_EDGE) {
3878 uvedit_edge_select_set_with_sticky(scene, bm, hit.l, select_value, offsets);
3879 flush = 1;
3880 }
3881 else if (selectmode == UV_SELECT_VERT) {
3882 uvedit_uv_select_set_with_sticky(scene, bm, hit.l, select_value, offsets);
3883 flush = 1;
3884 }
3885 else {
3887 }
3888
3889 /* De-selecting an edge may deselect a face too - validate. */
3890 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3891 if (select_value) {
3892 /* Postpone setting active until it's known if the underlying element is selected. */
3893 if (selectmode == UV_SELECT_FACE) {
3894 ele_active = reinterpret_cast<BMElem *>(hit.efa);
3895 }
3896 else if (selectmode == UV_SELECT_EDGE) {
3897 ele_active = reinterpret_cast<BMElem *>(hit.l->e);
3898 }
3899 else if (selectmode == UV_SELECT_VERT) {
3900 ele_active = reinterpret_cast<BMElem *>(hit.l->v);
3901 }
3902 }
3903 else {
3905 }
3906 }
3907
3908 /* (de)select sticky UV nodes. */
3909 if (sticky != UV_STICKY_DISABLE) {
3910 flush = select_value ? 1 : -1;
3911 }
3912
3913 changed = true;
3914 }
3915
3916 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
3917 if (flush != 0) {
3918 if (bm->uv_select_sync_valid) {
3919 /* TODO: the picking should edge deselection to faces for e.g. */
3920
3921 /* NOTE: currently face selection handles all flushing itself.
3922 * Flushing face mode will dis-connect the shared vertices unless
3923 * shared locations are re-applied afterwards. */
3924 if (selectmode != UV_SELECT_FACE) {
3926 }
3927
3929 }
3930 else {
3932 }
3933 }
3934
3935 if (ele_active) {
3936 if (BM_elem_flag_test(ele_active, BM_ELEM_SELECT)) {
3937 BM_select_history_store(bm, ele_active);
3938 }
3939 }
3940 }
3941 else {
3942 /* Setting the selection implies a single element, which doesn't need to be flushed. */
3943 if (params.sel_op != SEL_OP_SET) {
3945 }
3946 }
3947 }
3948
3949 if (changed && found) {
3950 /* Only update the `hit` object as de-selecting all will have refreshed the others. */
3951 Object *obedit = hit.ob;
3952 uv_select_tag_update_for_object(depsgraph, ts, obedit);
3953 }
3954
3955 return changed || found;
3956}
3957static bool uv_mouse_select(bContext *C, const float co[2], const SelectPick_Params &params)
3958{
3959 const Main *bmain = CTX_data_main(C);
3960 const Scene *scene = CTX_data_scene(C);
3961 ViewLayer *view_layer = CTX_data_view_layer(C);
3963 *bmain, scene, view_layer, nullptr);
3964 bool changed = uv_mouse_select_multi(C, objects, co, params);
3965 return changed;
3966}
3967
3969{
3970 float co[2];
3971
3972 RNA_float_get_array(op->ptr, "location", co);
3973
3975
3976 const bool changed = uv_mouse_select(C, co, params);
3977
3978 if (changed) {
3980 }
3982}
3983
3985{
3986 const ARegion *region = CTX_wm_region(C);
3987 float co[2];
3988
3989 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
3990 RNA_float_set_array(op->ptr, "location", co);
3991
3992 const wmOperatorStatus retval = uv_select_exec(C, op);
3993
3994 return WM_operator_flag_only_pass_through_on_press(retval, event);
3995}
3996
3998{
3999 /* identifiers */
4000 ot->name = "Select";
4001 ot->description = "Select UV vertices";
4002 ot->idname = "UV_OT_select";
4003 ot->flag = OPTYPE_UNDO;
4004
4005 /* API callbacks. */
4006 ot->exec = uv_select_exec;
4008 ot->poll = ED_operator_uvedit; /* requires space image */
4010
4011 /* properties */
4012 PropertyRNA *prop;
4013
4015
4016 prop = RNA_def_float_vector(
4017 ot->srna,
4018 "location",
4019 2,
4020 nullptr,
4021 -FLT_MAX,
4022 FLT_MAX,
4023 "Location",
4024 "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds",
4025 -100.0f,
4026 100.0f);
4028}
4029
4031
4032/* -------------------------------------------------------------------- */
4035
4040
4042 const Span<Object *> objects,
4043 const float co[2],
4044 const bool extend,
4045 enum eUVLoopGenericType loop_type)
4046{
4047 const ARegion *region = CTX_wm_region(C);
4048 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
4049 Scene *scene = CTX_data_scene(C);
4050 const ToolSettings *ts = scene->toolsettings;
4051 UvNearestHit hit = region ? uv_nearest_hit_init_max(&region->v2d) :
4053 bool found_item = false;
4054 /* 0 == don't flush, 1 == sel, -1 == deselect; only use when selection sync is enabled. */
4055 int flush = 0;
4056
4057 /* Find edge. */
4058 found_item = uv_find_nearest_edge_multi(scene, objects, co, 0.0f, &hit);
4059 if (!found_item) {
4060 return OPERATOR_CANCELLED;
4061 }
4062
4063 Object *obedit = hit.ob;
4065
4066 /* Do selection. */
4067 if (!extend) {
4068 uv_select_all_perform_multi_ex(scene, objects, SEL_DESELECT, obedit);
4069 }
4070
4071 if (loop_type == UV_LOOP_SELECT) {
4073 flush = uv_select_faceloop(scene, obedit, &hit, extend);
4074 }
4075 else {
4076 flush = uv_select_edgeloop(scene, obedit, &hit, extend);
4077 }
4078 }
4079 else if (loop_type == UV_RING_SELECT) {
4080 flush = uv_select_edgering(scene, obedit, &hit, extend);
4081 }
4082 else {
4084 }
4085
4086 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4088 if (flush != 0) {
4089 BM_mesh_select_flush_from_verts(bm, flush == 1 ? true : false);
4090 }
4091 }
4092 else {
4093 if (flush != 0) {
4094 ED_uvedit_select_sync_flush(ts, bm, flush == 1 ? true : false);
4095 }
4096 }
4097 }
4098 else {
4100 }
4101
4102 for (Object *ob : objects) {
4103 uv_select_tag_update_for_object(depsgraph, ts, ob);
4104 }
4105
4107}
4109 const float co[2],
4110 const bool extend,
4111 enum eUVLoopGenericType loop_type)
4112{
4113 const Main *bmain = CTX_data_main(C);
4114 const Scene *scene = CTX_data_scene(C);
4115 ViewLayer *view_layer = CTX_data_view_layer(C);
4117 *bmain, scene, view_layer, nullptr);
4118 wmOperatorStatus ret = uv_mouse_select_loop_generic_multi(C, objects, co, extend, loop_type);
4119 return ret;
4120}
4121
4123
4124/* -------------------------------------------------------------------- */
4127
4129{
4130 float co[2];
4131
4132 RNA_float_get_array(op->ptr, "location", co);
4133 const bool extend = RNA_boolean_get(op->ptr, "extend");
4134
4135 return uv_mouse_select_loop_generic(C, co, extend, UV_LOOP_SELECT);
4136}
4137
4139{
4140 const ARegion *region = CTX_wm_region(C);
4141 float co[2];
4142
4143 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
4144 RNA_float_set_array(op->ptr, "location", co);
4145
4146 const wmOperatorStatus retval = uv_select_loop_exec(C, op);
4147
4148 return WM_operator_flag_only_pass_through_on_press(retval, event);
4149}
4150
4152{
4153 /* identifiers */
4154 ot->name = "Loop Select";
4155 ot->description = "Select a loop of connected UV vertices";
4156 ot->idname = "UV_OT_select_loop";
4157 ot->flag = OPTYPE_UNDO;
4158
4159 /* API callbacks. */
4162 ot->poll = ED_operator_uvedit; /* requires space image */
4163
4164 /* properties */
4165 PropertyRNA *prop;
4166 prop = RNA_def_boolean(ot->srna,
4167 "extend",
4168 false,
4169 "Extend",
4170 "Extend selection rather than clearing the existing selection");
4172 prop = RNA_def_float_vector(
4173 ot->srna,
4174 "location",
4175 2,
4176 nullptr,
4177 -FLT_MAX,
4178 FLT_MAX,
4179 "Location",
4180 "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds",
4181 -100.0f,
4182 100.0f);
4184}
4185
4187
4188/* -------------------------------------------------------------------- */
4191
4193{
4194 float co[2];
4195 RNA_float_get_array(op->ptr, "location", co);
4196 const bool extend = RNA_boolean_get(op->ptr, "extend");
4197 return uv_mouse_select_loop_generic(C, co, extend, UV_RING_SELECT);
4198}
4199
4201 wmOperator *op,
4202 const wmEvent *event)
4203{
4204 const ARegion *region = CTX_wm_region(C);
4205 float co[2];
4206
4207 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
4208 RNA_float_set_array(op->ptr, "location", co);
4209
4210 const wmOperatorStatus retval = uv_select_edge_ring_exec(C, op);
4211
4212 return WM_operator_flag_only_pass_through_on_press(retval, event);
4213}
4214
4216{
4217 /* identifiers */
4218 ot->name = "Edge Ring Select";
4219 ot->description = "Select an edge ring of connected UV vertices";
4220 ot->idname = "UV_OT_select_edge_ring";
4221 ot->flag = OPTYPE_UNDO;
4222
4223 /* API callbacks. */
4226 ot->poll = ED_operator_uvedit; /* requires space image */
4227
4228 /* properties */
4229 PropertyRNA *prop;
4230 prop = RNA_def_boolean(ot->srna,
4231 "extend",
4232 false,
4233 "Extend",
4234 "Extend selection rather than clearing the existing selection");
4236 prop = RNA_def_float_vector(
4237 ot->srna,
4238 "location",
4239 2,
4240 nullptr,
4241 -FLT_MAX,
4242 FLT_MAX,
4243 "Location",
4244 "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds",
4245 -100.0f,
4246 100.0f);
4248}
4249
4251
4252/* -------------------------------------------------------------------- */
4255
4257 wmOperator *op,
4258 const wmEvent *event,
4259 bool pick)
4260{
4261 const ARegion *region = CTX_wm_region(C);
4262 const Main *bmain = CTX_data_main(C);
4263 Scene *scene = CTX_data_scene(C);
4264 const ToolSettings *ts = scene->toolsettings;
4265 ViewLayer *view_layer = CTX_data_view_layer(C);
4266 bool extend = true;
4267 bool deselect = false;
4268 bool select_faces = (ts->uv_flag & UV_FLAG_SELECT_SYNC) && (ts->selectmode & SCE_SELECT_FACE) &&
4269 (ts->uv_sticky == UV_STICKY_VERT);
4270
4271 UvNearestHit hit = region ? uv_nearest_hit_init_max(&region->v2d) :
4273
4274 if (pick) {
4275 extend = RNA_boolean_get(op->ptr, "extend");
4276 deselect = RNA_boolean_get(op->ptr, "deselect");
4277 }
4278 const UVDelimitMode delimit_mode = UVDelimitMode(RNA_enum_get(op->ptr, "delimit"));
4279
4281 *bmain, scene, view_layer, nullptr);
4282
4283 if (pick) {
4284 float co[2];
4285
4286 if (event) {
4287 /* invoke */
4288 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
4289 RNA_float_set_array(op->ptr, "location", co);
4290 }
4291 else {
4292 /* exec */
4293 RNA_float_get_array(op->ptr, "location", co);
4294 }
4295
4296 if (!uv_find_nearest_edge_multi(scene, objects, co, 0.0f, &hit)) {
4297 return OPERATOR_CANCELLED;
4298 }
4299 }
4300
4301 if (!extend && !deselect) {
4303 }
4304
4306 objects,
4307 pick ? &hit : nullptr,
4308 extend,
4309 deselect,
4310 false,
4311 select_faces,
4312 delimit_mode,
4314
4315 if (pick) {
4318 }
4319 else {
4320 for (Object *obedit : objects) {
4322 WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
4323 }
4324 }
4325
4326 return OPERATOR_FINISHED;
4327}
4328
4330{
4331 return uv_select_linked_internal(C, op, nullptr, false);
4332}
4333
4335{
4336 /* identifiers */
4337 ot->name = "Select Linked";
4338 ot->description = "Select all UV vertices linked to the active UV map";
4339 ot->idname = "UV_OT_select_linked";
4340
4341 /* API callbacks. */
4343 ot->poll = ED_operator_uvedit; /* requires space image */
4344
4345 /* flags */
4347
4348 /* properties */
4350 "delimit",
4352 0,
4353 "Delimit",
4354 "Delimit selection when selecting linked UVs");
4355}
4356
4358
4359/* -------------------------------------------------------------------- */
4362
4364 wmOperator *op,
4365 const wmEvent *event)
4366{
4367 return uv_select_linked_internal(C, op, event, true);
4368}
4369
4371{
4372 return uv_select_linked_internal(C, op, nullptr, true);
4373}
4374
4376{
4377 /* identifiers */
4378 ot->name = "Select Linked Pick";
4379 ot->description = "Select all UV vertices linked under the mouse";
4380 ot->idname = "UV_OT_select_linked_pick";
4381
4382 /* flags */
4384
4385 /* API callbacks. */
4388 ot->poll = ED_operator_uvedit; /* requires space image */
4389
4390 /* properties */
4391 PropertyRNA *prop;
4392 prop = RNA_def_boolean(ot->srna,
4393 "extend",
4394 false,
4395 "Extend",
4396 "Extend selection rather than clearing the existing selection");
4398 prop = RNA_def_boolean(ot->srna,
4399 "deselect",
4400 false,
4401 "Deselect",
4402 "Deselect linked UV vertices rather than selecting them");
4405 "delimit",
4407 0,
4408 "Delimit",
4409 "Delimit selection when selecting linked UVs");
4410 prop = RNA_def_float_vector(
4411 ot->srna,
4412 "location",
4413 2,
4414 nullptr,
4415 -FLT_MAX,
4416 FLT_MAX,
4417 "Location",
4418 "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds",
4419 -100.0f,
4420 100.0f);
4422}
4423
4425
4426/* -------------------------------------------------------------------- */
4429
4437{
4438 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
4439 const Main *bmain = CTX_data_main(C);
4440 Scene *scene = CTX_data_scene(C);
4441 ViewLayer *view_layer = CTX_data_view_layer(C);
4442 const ToolSettings *ts = scene->toolsettings;
4443
4444 BMFace *efa;
4445 BMLoop *l;
4446 BMIter iter, liter;
4447
4448 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4449 /* Face selection. */
4450 if (ts->uv_sticky == UV_STICKY_VERT) {
4451 BKE_report(
4452 op->reports,
4453 RPT_ERROR,
4454 "Cannot split selection with \"Sync Select\" and \"Shared Vertex\" selection enabled");
4455 return OPERATOR_CANCELLED;
4456 }
4457 }
4458
4459 bool changed_multi = false;
4460
4462 *bmain, scene, view_layer, nullptr);
4463
4464 for (Object *obedit : objects) {
4466
4467 bool changed = false;
4468
4469 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4471 }
4472 else {
4474 }
4475
4476 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
4477 bool is_sel = false;
4478 bool is_unsel = false;
4479
4480 if (!uvedit_face_visible_test(scene, efa)) {
4481 continue;
4482 }
4483
4484 /* are we all selected? */
4485 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
4486 const bool select_vert = uvedit_loop_vert_select_get(ts, bm, l);
4487 const bool select_edge = uvedit_loop_edge_select_get(ts, bm, l);
4488
4489 if (select_vert || select_edge) {
4490 is_sel = true;
4491 }
4492 if (!select_vert || !select_edge) {
4493 is_unsel = true;
4494 }
4495
4496 /* we have mixed selection, bail out */
4497 if (is_sel && is_unsel) {
4498 break;
4499 }
4500 }
4501
4502 if (is_sel && is_unsel) {
4503 /* No need to deselect the face (with sync-select) as it wont be selected,
4504 * since it already has a mixed selection. */
4505 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
4506 uvedit_loop_vert_select_set(ts, bm, l, false);
4507 uvedit_loop_edge_select_set(ts, bm, l, false);
4508 }
4509
4510 changed = true;
4511 }
4512 }
4513
4514 if (changed) {
4515 changed_multi = true;
4517 uv_select_tag_update_for_object(depsgraph, ts, obedit);
4518 }
4519 }
4520
4521 return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
4522}
4523
4525{
4526 /* identifiers */
4527 ot->name = "Select Split";
4528 ot->description = "Select only entirely selected faces";
4529 ot->idname = "UV_OT_select_split";
4531
4532 /* API callbacks. */
4534 ot->poll = ED_operator_uvedit; /* requires space image */
4535}
4536
4538
4539/* -------------------------------------------------------------------- */
4544
4554static void uv_select_sync_update(const Scene *scene, Object *obedit)
4555{
4556 const ToolSettings *ts = scene->toolsettings;
4557 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4558 return;
4559 }
4560
4561 /* Sync selection has been disabled re-use or re-create the select-sync data. */
4563 /* May be -1, this is accounted for. */
4564 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
4565 if (bm->selectmode == ts->uv_selectmode) {
4566 if (bm->uv_select_sync_valid == false) {
4568 /* When the modes match, don't clear. */
4569 }
4570 }
4571 else {
4572 if (bm->uv_select_sync_valid) {
4574 }
4575 else {
4576 const short selectmode_orig = bm->selectmode;
4579 bm->selectmode = selectmode_orig;
4580 }
4581 /* Always false because the mode doesn't match. */
4583 }
4584}
4585
4586static void uv_select_tag_update_for_object(Depsgraph *depsgraph,
4587 const ToolSettings *ts,
4588 Object *obedit)
4589{
4590 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4593 }
4594 else {
4595 Object *obedit_eval = DEG_get_evaluated(depsgraph, obedit);
4596 BKE_mesh_batch_cache_dirty_tag(id_cast<Mesh *>(obedit_eval->data),
4598 /* Only for region redraw. */
4600 }
4601}
4602
4613static void uv_select_flush_from_tag_face(const Scene *scene, Object *obedit, const bool select)
4614{
4615 /* Selecting UV Faces with some modes requires us to change
4616 * the selection in other faces (depending on the sticky mode).
4617 *
4618 * This only needs to be done when the Mesh is not used for
4619 * selection (so for sticky modes, vertex or location based). */
4620
4621 const ToolSettings *ts = scene->toolsettings;
4623 BMFace *efa;
4624 BMLoop *l;
4625 BMIter iter, liter;
4626
4627 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4629 }
4630 else {
4632 }
4633 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
4634
4635 bool use_sticky = true;
4636 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4638 /* Use the mesh selection directly. */
4639 use_sticky = false;
4640 }
4641 }
4642 if (ts->uv_sticky == UV_STICKY_DISABLE) {
4643 /* No need for sticky calculation when it's disabled. */
4644 use_sticky = false;
4645 }
4646
4647 if (use_sticky) {
4648 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
4649 if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) {
4650 continue;
4651 }
4652
4653 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4655 }
4656 else {
4658 }
4659 }
4660
4661 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
4662 if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) {
4663 continue;
4664 }
4665
4666 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
4668
4669 if (select) {
4670 /* Only flush UV vertices. Flushing UV edges would flag the edges of unselected
4671 * neighboring faces, making a face enclosed by the selection look fully selected. */
4673 }
4674 else {
4675 /* Match selecting logic, except UV's still used by other selected faces must be kept.
4676 * Note that #uvedit_edge_select_shared_vert only de-selects a UV vertex once it's
4677 * last selected UV edge is de-selected, see: #161419. */
4678 if (!uvedit_vert_is_face_select_any_other(ts, bm, l, offsets)) {
4680 }
4681 if (!uvedit_edge_is_face_select_any_other(ts, bm, l, offsets)) {
4683 }
4684 }
4685 }
4686 }
4687 }
4688 else {
4689 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
4690 if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) {
4691 continue;
4692 }
4693 uvedit_face_select_set(scene, bm, efa, select);
4694 }
4695 }
4696}
4697
4708static void uv_select_flush_from_tag_loop(const Scene *scene, Object *obedit, const bool select)
4709{
4710 /* Selecting UV Loops with some modes requires us to change
4711 * the selection in other faces (depending on the sticky mode).
4712 *
4713 * This only needs to be done when the Mesh is not used for
4714 * selection (so for sticky modes, vertex or location based). */
4715
4716 const ToolSettings *ts = scene->toolsettings;
4718 BMFace *efa;
4719 BMLoop *l;
4720 BMIter iter, liter;
4721
4722 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4724 }
4725 else {
4727 }
4728 const bool use_mesh_select = (ts->uv_flag & UV_FLAG_SELECT_SYNC) &&
4729 (bm->uv_select_sync_valid == false);
4730
4731 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
4732
4733 if ((use_mesh_select == false) && ts->uv_sticky == UV_STICKY_VERT) {
4734 /* Tag all verts as untouched, then touch the ones that have a face center
4735 * in the loop and select all UVs that use a touched vert. */
4737
4738 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
4739 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
4742 }
4743 }
4744 }
4745
4746 /* now select tagged verts */
4747 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
4748 bool tag_all = true;
4749 bool tag_any = false;
4750 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
4752 uvedit_uv_select_set(scene, bm, l, select);
4753 tag_any = true;
4754 }
4755 else {
4756 tag_all = false;
4757 }
4758 }
4759 if (select) {
4760 if (tag_all && uvedit_face_visible_test(scene, efa)) {
4761 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4762 BM_face_uvselect_set_noflush(bm, efa, true);
4763 }
4764 else {
4765 uvedit_face_select_set_no_sync(ts, bm, efa, true);
4766 }
4767 }
4768 }
4769 else {
4770 if (tag_any && uvedit_face_visible_test(scene, efa)) {
4771 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4772 BM_face_uvselect_set_noflush(bm, efa, false);
4773 }
4774 else {
4775 uvedit_face_select_set_no_sync(ts, bm, efa, false);
4776 }
4777 }
4778 }
4779 }
4780 }
4781 else if ((use_mesh_select == false) && (ts->uv_sticky == UV_STICKY_LOCATION)) {
4782 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
4783 bool tag_all = true;
4784 bool tag_any = false;
4785 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
4788 tag_any = true;
4789 }
4790 else {
4791 tag_all = false;
4792 }
4793 }
4794 if (select) {
4795 if (tag_all && uvedit_face_visible_test(scene, efa)) {
4796 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4797 BM_face_uvselect_set_noflush(bm, efa, true);
4798 }
4799 else {
4800 uvedit_face_select_set_no_sync(ts, bm, efa, true);
4801 }
4802 }
4803 }
4804 else {
4805 if (tag_any && uvedit_face_visible_test(scene, efa)) {
4806 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4807 BM_face_uvselect_set_noflush(bm, efa, false);
4808 }
4809 else {
4810 uvedit_face_select_set_no_sync(ts, bm, efa, false);
4811 }
4812 }
4813 }
4814 }
4815 }
4816 else { /* UV_STICKY_DISABLE or ts->uv_flag & UV_FLAG_SELECT_SYNC */
4817 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
4818 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
4820 uvedit_uv_select_set(scene, bm, l, select);
4821 }
4822 }
4823 }
4824 }
4825}
4826
4838{
4839 const ToolSettings *ts = scene->toolsettings;
4840 BMFace *efa;
4841 BMLoop *l;
4842 BMIter iter, liter;
4843
4844 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4846 }
4847 else {
4849 }
4850 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
4851
4852 bool use_sticky = true;
4853 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4854 if (ts->uv_sticky == UV_STICKY_VERT) {
4855 /* Use the mesh selection directly. */
4856 use_sticky = false;
4857 }
4858 }
4859 if (ts->uv_sticky == UV_STICKY_DISABLE) {
4860 /* No need for sticky calculation when it's disabled. */
4861 use_sticky = false;
4862 }
4863
4864 if (use_sticky) {
4865 /* Use UV edge selection to identify which verts must to be selected */
4866
4867 /* Clear UV vert flags */
4869
4870 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
4871 if (!uvedit_face_visible_test(scene, efa)) {
4872 /* This visibility check could be removed? Simply relying on edge flags to ensure
4873 * visibility might be sufficient. */
4874 continue;
4875 }
4876 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
4877 /* Select verts based on UV edge flag. */
4879 uvedit_uv_select_shared_vert(scene, bm, l, true, UV_STICKY_LOCATION, offsets);
4880 uvedit_uv_select_shared_vert(scene, bm, l->next, true, UV_STICKY_LOCATION, offsets);
4881 }
4882 }
4883 }
4884 }
4885 else {
4886 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4888 }
4889 else {
4890 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
4891 bool select_all = true;
4892 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
4896 }
4897 else if (!uvedit_edge_select_get_no_sync(ts, bm, l->prev)) {
4899 select_all = false;
4900 }
4901 }
4902 uvedit_face_select_set_no_sync(ts, bm, efa, select_all);
4903 }
4904 }
4905 }
4906}
4907
4909
4910/* -------------------------------------------------------------------- */
4913
4915{
4916 const Scene *scene = CTX_data_scene(C);
4917 const bool pinned = RNA_boolean_get(op->ptr, "pinned");
4918 if (pinned) {
4919 if (!uvedit_select_pin_ok_or_report(scene, op->reports)) {
4920 return OPERATOR_CANCELLED;
4921 }
4922 }
4923 return WM_gesture_box_invoke(C, op, event);
4924}
4925
4927{
4928 const Scene *scene = CTX_data_scene(C);
4929 const ToolSettings *ts = scene->toolsettings;
4930
4931 const bool pinned = RNA_boolean_get(op->ptr, "pinned");
4932
4933 /* Note that face selection uses the face-center. */
4934 const char uv_select_mode = ED_uvedit_select_mode_get(scene);
4935 const bool use_select_linked = pinned ? false : ED_uvedit_select_island_check(ts);
4936
4937 if (pinned) {
4938 if (!uvedit_select_pin_ok_or_report(scene, op->reports)) {
4939 return OPERATOR_CANCELLED;
4940 }
4941 }
4942
4943 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
4944 const Main *bmain = CTX_data_main(C);
4945 ViewLayer *view_layer = CTX_data_view_layer(C);
4946 const ARegion *region = CTX_wm_region(C);
4947 BMFace *efa;
4948 BMLoop *l;
4949 BMIter iter, liter;
4950 float *luv;
4951 rctf rectf;
4952
4953 /* get rectangle from operator */
4955 ui::view2d_region_to_view_rctf(&region->v2d, &rectf, &rectf);
4956
4957 const eSelectOp sel_op = eSelectOp(RNA_enum_get(op->ptr, "mode"));
4958 const bool select = (sel_op != SEL_OP_SUB);
4959 const bool use_pre_deselect = SEL_OP_USE_PRE_DESELECT(sel_op);
4960
4961 bool changed_multi = false;
4962
4964 *bmain, scene, view_layer, nullptr);
4965
4966 if (use_pre_deselect) {
4968 }
4969
4970 /* don't indent to avoid diff noise! */
4971 for (Object *obedit : objects) {
4973
4974 bool changed = false;
4975
4976 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
4978 }
4979 else {
4981 }
4982
4983 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
4984
4985 /* do actual selection */
4986 if (pinned && offsets.pin == -1) {
4987 /* Special case, nothing is pinned so it's known in advance that nothing will be selected.
4988 * Still run the code after this block finishes as the UV's may have been de-selected. */
4989 }
4990 else if (uv_select_mode == UV_SELECT_FACE) {
4991 /* Handle face selection (face center). */
4992 std::optional<UVSelectLinkedHelper> linked_helper;
4993 if (use_select_linked) {
4994 linked_helper.emplace(scene, bm);
4996 }
4997 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
4998 if (use_select_linked) {
4999 if (linked_helper->face_check(efa)) {
5000 continue;
5001 }
5002 }
5003 else {
5005 }
5006 if (uvedit_face_visible_test(scene, efa)) {
5007 float cent[2];
5008 BM_face_uv_calc_center_median(efa, offsets.uv, cent);
5009 if (BLI_rctf_isect_pt_v(&rectf, cent)) {
5010 changed = true;
5011 if (use_select_linked) {
5012 linked_helper->face_add(efa);
5013 }
5014 else {
5016 }
5017 }
5018 }
5019 }
5020 if (use_select_linked) {
5021 linked_helper->tag_all();
5022 }
5023
5024 /* (de)selects all tagged faces and deals with sticky modes */
5025 if (changed) {
5026 uv_select_flush_from_tag_face(scene, obedit, select);
5027 }
5028 }
5029 else if (uv_select_mode == UV_SELECT_EDGE) {
5030 std::optional<UVSelectLinkedHelper> linked_helper;
5031 if (use_select_linked) {
5032 linked_helper.emplace(scene, bm);
5033 }
5034 bool do_second_pass = true;
5035 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
5036 if (!uvedit_face_visible_test(scene, efa)) {
5037 continue;
5038 }
5039
5040 BMLoop *l_prev = BM_FACE_FIRST_LOOP(efa)->prev;
5041 float *luv_prev = BM_ELEM_CD_GET_FLOAT_P(l_prev, offsets.uv);
5042
5043 bool has_selected = false;
5044 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
5045 luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
5046 if (BLI_rctf_isect_pt_v(&rectf, luv) && BLI_rctf_isect_pt_v(&rectf, luv_prev)) {
5047 uvedit_edge_select_set_with_sticky(scene, bm, l_prev, select, offsets);
5048 do_second_pass = false;
5049 has_selected = true;
5050 changed = true;
5051 }
5052 l_prev = l;
5053 luv_prev = luv;
5054 }
5055 if (has_selected && use_select_linked) {
5056 linked_helper->face_add(efa);
5057 }
5058 }
5059 /* Do a second pass if no complete edges could be selected.
5060 * This matches wire-frame edit-mesh selection in the 3D view. */
5061 if (do_second_pass) {
5062 /* Second pass to check if edges partially overlap with the selection area (box). */
5063 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
5064 if (!uvedit_face_visible_test(scene, efa)) {
5065 continue;
5066 }
5067 BMLoop *l_prev = BM_FACE_FIRST_LOOP(efa)->prev;
5068 float *luv_prev = BM_ELEM_CD_GET_FLOAT_P(l_prev, offsets.uv);
5069
5070 bool has_selected = false;
5071 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
5072 luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
5073 if (BLI_rctf_isect_segment(&rectf, luv_prev, luv)) {
5074 uvedit_edge_select_set_with_sticky(scene, bm, l_prev, select, offsets);
5075 has_selected = true;
5076 changed = true;
5077 }
5078 l_prev = l;
5079 luv_prev = luv;
5080 }
5081 if (has_selected && use_select_linked) {
5082 linked_helper->face_add(efa);
5083 }
5084 }
5085 }
5086 if (use_select_linked) {
5087 linked_helper->select_all(select);
5088 }
5089 }
5090 else {
5091 /* Handle vert selection. */
5092 BLI_assert(uv_select_mode == UV_SELECT_VERT);
5093
5094 changed = true;
5096
5097 std::optional<UVSelectLinkedHelper> linked_helper;
5098 if (use_select_linked) {
5099 linked_helper.emplace(scene, bm);
5100 }
5101
5102 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
5103 if (!uvedit_face_visible_test(scene, efa)) {
5104 continue;
5105 }
5106 bool has_selected = false;
5107 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
5108 luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
5109 if (select != uvedit_uv_select_test(scene, bm, l, offsets)) {
5110 if (BLI_rctf_isect_pt_v(&rectf, luv)) {
5111 if (!pinned || BM_ELEM_CD_GET_BOOL(l, offsets.pin)) {
5112 uvedit_uv_select_set(scene, bm, l, select);
5114 has_selected = true;
5115 }
5116 }
5117 }
5118 }
5119 if (has_selected && use_select_linked) {
5120 linked_helper->face_add(efa);
5121 }
5122 }
5123 if (use_select_linked) {
5124 linked_helper->select_all(select);
5125 }
5126
5127 if (ts->uv_sticky == UV_STICKY_VERT) {
5129 }
5130 }
5131
5132 if (changed || use_pre_deselect) {
5133 changed_multi = true;
5134 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
5136 }
5137 else {
5139 }
5140 uv_select_tag_update_for_object(depsgraph, ts, obedit);
5141 }
5142 }
5143
5144 return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
5145}
5146
5148{
5149 /* identifiers */
5150 ot->name = "Box Select";
5151 ot->description = "Select UV vertices using box selection";
5152 ot->idname = "UV_OT_select_box";
5153
5154 /* API callbacks. */
5158 ot->poll = ED_operator_uvedit_space_image; /* requires space image */
5160
5161 /* flags */
5162 ot->flag = OPTYPE_UNDO;
5163
5164 /* properties */
5165 RNA_def_boolean(ot->srna, "pinned", false, "Pinned", "Border select pinned UVs only");
5166
5169}
5170
5172
5173/* -------------------------------------------------------------------- */
5176
5177static bool uv_circle_select_is_point_inside(const float uv[2],
5178 const float offset[2],
5179 const float ellipse[2])
5180{
5181 /* normalized ellipse: ell[0] = scaleX, ell[1] = scaleY */
5182 const float co[2] = {
5183 (uv[0] - offset[0]) * ellipse[0],
5184 (uv[1] - offset[1]) * ellipse[1],
5185 };
5186 return len_squared_v2(co) < 1.0f;
5187}
5188
5189static bool uv_circle_select_is_edge_inside(const float uv_a[2],
5190 const float uv_b[2],
5191 const float offset[2],
5192 const float ellipse[2])
5193{
5194 /* normalized ellipse: ell[0] = scaleX, ell[1] = scaleY */
5195 const float co_a[2] = {
5196 (uv_a[0] - offset[0]) * ellipse[0],
5197 (uv_a[1] - offset[1]) * ellipse[1],
5198 };
5199 const float co_b[2] = {
5200 (uv_b[0] - offset[0]) * ellipse[0],
5201 (uv_b[1] - offset[1]) * ellipse[1],
5202 };
5203 const float co_zero[2] = {0.0f, 0.0f};
5204 return dist_squared_to_line_segment_v2(co_zero, co_a, co_b) < 1.0f;
5205}
5206
5208{
5209 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
5211 const Main *bmain = CTX_data_main(C);
5212 Scene *scene = CTX_data_scene(C);
5213 ViewLayer *view_layer = CTX_data_view_layer(C);
5214 const ToolSettings *ts = scene->toolsettings;
5215 const ARegion *region = CTX_wm_region(C);
5216 BMFace *efa;
5217 BMLoop *l;
5218 BMIter iter, liter;
5219 float *luv;
5220 int x, y, radius, width, height;
5221 float zoomx, zoomy;
5222 float offset[2], ellipse[2];
5223
5224 /* Note that face selection uses the face-center. */
5225 const char uv_select_mode = ED_uvedit_select_mode_get(scene);
5226 const bool use_select_linked = ED_uvedit_select_island_check(ts);
5227
5228 /* get operator properties */
5229 x = RNA_int_get(op->ptr, "x");
5230 y = RNA_int_get(op->ptr, "y");
5231 radius = RNA_int_get(op->ptr, "radius");
5232
5233 /* compute ellipse size and location, not a circle since we deal
5234 * with non square image. ellipse is normalized, r = 1.0. */
5235 ED_space_image_get_size(sima, &width, &height);
5236 ED_space_image_get_zoom(sima, region, &zoomx, &zoomy);
5237
5238 ellipse[0] = width * zoomx / radius;
5239 ellipse[1] = height * zoomy / radius;
5240
5241 ui::view2d_region_to_view(&region->v2d, x, y, &offset[0], &offset[1]);
5242
5243 bool changed_multi = false;
5244
5245 wmGesture *gesture = static_cast<wmGesture *>(op->customdata);
5246 const eSelectOp sel_op = ED_select_op_modal(eSelectOp(RNA_enum_get(op->ptr, "mode")),
5248 const bool select = (sel_op != SEL_OP_SUB);
5249 const bool use_pre_deselect = SEL_OP_USE_PRE_DESELECT(sel_op);
5250
5251 /* Get or create state for modal reuse. */
5252 UVCircleSelectState *state = static_cast<UVCircleSelectState *>(gesture->user_data.data);
5253 if (state == nullptr) {
5255 *bmain, scene, view_layer, nullptr);
5256 state = MEM_new<UVCircleSelectState>(__func__, scene, std::move(objects), use_select_linked);
5257 gesture->user_data.data = state;
5258 gesture->user_data.free_fn = uv_circle_select_state_free;
5259 gesture->user_data.use_free = true;
5260 }
5261
5262 const Span<Object *> objects = state->objects.as_span();
5263
5264 if (use_pre_deselect) {
5266 }
5267
5268 for (const int ob_index : objects.index_range()) {
5269 Object *obedit = objects[ob_index];
5271
5272 bool changed = false;
5273
5274 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
5276 }
5277 else {
5279 }
5280 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
5281
5282 UVSelectLinkedHelper *linked_helper = use_select_linked ? &(*state->linked_helpers)[ob_index] :
5283 nullptr;
5284 if (use_select_linked) {
5285 /* As they are reused, there is some chance of stale data. */
5286 BLI_assert(linked_helper->has_face == false);
5287 }
5288
5289 /* do selection */
5290 if (uv_select_mode == UV_SELECT_FACE) {
5291 /* Handle face selection (face center). */
5292 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
5293 /* Clear the tag on hidden faces too, needed for: #uv_select_flush_from_tag_face. */
5295
5296 if (!uvedit_face_visible_test(scene, efa)) {
5297 continue;
5298 }
5299 if (use_select_linked) {
5300 if (linked_helper->face_check(efa)) {
5301 continue;
5302 }
5303 }
5304 else {
5305 if (select == uvedit_face_select_test(scene, bm, efa)) {
5306 continue;
5307 }
5308 }
5309
5310 float cent[2];
5311 BM_face_uv_calc_center_median(efa, offsets.uv, cent);
5312 if (uv_circle_select_is_point_inside(cent, offset, ellipse)) {
5313 changed = true;
5314 if (use_select_linked) {
5315 linked_helper->face_add(efa);
5316 }
5317 else {
5319 }
5320 }
5321 }
5322 if (use_select_linked) {
5323 linked_helper->tag_all();
5324 linked_helper->clear();
5325 }
5326
5327 /* (de)selects all tagged faces and deals with sticky modes */
5328 if (changed) {
5329 uv_select_flush_from_tag_face(scene, obedit, select);
5330 }
5331 }
5332 else if (uv_select_mode == UV_SELECT_EDGE) {
5333 /* Handle edge selection. */
5334 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
5335 if (!uvedit_face_visible_test(scene, efa)) {
5336 continue;
5337 }
5338
5339 BMLoop *l_prev = BM_FACE_FIRST_LOOP(efa)->prev;
5340 const float *luv_prev = BM_ELEM_CD_GET_FLOAT_P(l_prev, offsets.uv);
5341
5342 bool has_selected = false;
5343 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
5344 luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
5345 if (uv_circle_select_is_edge_inside(luv, luv_prev, offset, ellipse)) {
5346 uvedit_edge_select_set_with_sticky(scene, bm, l_prev, select, offsets);
5347 has_selected = true;
5348 changed = true;
5349 }
5350 l_prev = l;
5351 luv_prev = luv;
5352 }
5353 if (has_selected && use_select_linked) {
5354 linked_helper->face_add(efa);
5355 }
5356 }
5357 if (use_select_linked) {
5358 linked_helper->select_all(select);
5359 linked_helper->clear();
5360 }
5361 }
5362 else {
5363 /* Handle vert selection. */
5364 BLI_assert(uv_select_mode == UV_SELECT_VERT);
5365
5367
5368 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
5369 if (!uvedit_face_visible_test(scene, efa)) {
5370 continue;
5371 }
5372 bool has_selected = false;
5373 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
5374 if (select != uvedit_uv_select_test(scene, bm, l, offsets)) {
5375 luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
5376 if (uv_circle_select_is_point_inside(luv, offset, ellipse)) {
5377 changed = true;
5378 uvedit_uv_select_set(scene, bm, l, select);
5380 has_selected = true;
5381 }
5382 }
5383 }
5384 if (has_selected && use_select_linked) {
5385 linked_helper->face_add(efa);
5386 }
5387 }
5388 if (use_select_linked) {
5389 linked_helper->select_all(select);
5390 linked_helper->clear();
5391 }
5392
5393 if (ts->uv_sticky == UV_STICKY_VERT) {
5395 }
5396 }
5397
5398 if (changed || use_pre_deselect) {
5399 changed_multi = true;
5400 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
5402 }
5403 else {
5405 }
5406 uv_select_tag_update_for_object(depsgraph, ts, obedit);
5407 }
5408 }
5409
5410 return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
5411}
5412
5414{
5415 /* identifiers */
5416 ot->name = "Circle Select";
5417 ot->description = "Select UV vertices using circle selection";
5418 ot->idname = "UV_OT_select_circle";
5419
5420 /* API callbacks. */
5424 ot->poll = ED_operator_uvedit_space_image; /* requires space image */
5427
5428 /* flags */
5429 ot->flag = OPTYPE_UNDO;
5430
5431 /* properties */
5434}
5435
5437
5438/* -------------------------------------------------------------------- */
5441
5443 const rcti *clip_rect,
5444 const Span<int2> mcoords,
5445 const float co_test[2])
5446{
5447 int co_screen[2];
5449 &region->v2d, co_test[0], co_test[1], &co_screen[0], &co_screen[1]) &&
5450 BLI_rcti_isect_pt_v(clip_rect, co_screen) &&
5451 BLI_lasso_is_point_inside(mcoords, co_screen[0], co_screen[1], V2D_IS_CLIPPED))
5452 {
5453 return true;
5454 }
5455 return false;
5456}
5457
5459 const rcti *clip_rect,
5460 const Span<int2> mcoords,
5461 const float co_test_a[2],
5462 const float co_test_b[2])
5463{
5464 int co_screen_a[2], co_screen_b[2];
5466 &region->v2d, co_test_a, co_test_b, co_screen_a, co_screen_b) &&
5467 BLI_rcti_isect_segment(clip_rect, co_screen_a, co_screen_b) &&
5469 mcoords, UNPACK2(co_screen_a), UNPACK2(co_screen_b), V2D_IS_CLIPPED))
5470 {
5471 return true;
5472 }
5473 return false;
5474}
5475
5476static bool do_lasso_select_mesh_uv(bContext *C, const Span<int2> mcoords, const eSelectOp sel_op)
5477{
5478 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
5479 const ARegion *region = CTX_wm_region(C);
5480 const Main *bmain = CTX_data_main(C);
5481 Scene *scene = CTX_data_scene(C);
5482 const ToolSettings *ts = scene->toolsettings;
5483 ViewLayer *view_layer = CTX_data_view_layer(C);
5484
5485 /* Note that face selection uses the face-center. */
5486 const char uv_select_mode = ED_uvedit_select_mode_get(scene);
5487 const bool use_select_linked = ED_uvedit_select_island_check(ts);
5488
5489 const bool select = (sel_op != SEL_OP_SUB);
5490 const bool use_pre_deselect = SEL_OP_USE_PRE_DESELECT(sel_op);
5491
5492 BMIter iter, liter;
5493
5494 BMFace *efa;
5495 BMLoop *l;
5496 bool changed_multi = false;
5497 rcti rect;
5498
5499 BLI_lasso_boundbox(&rect, mcoords);
5500
5502 *bmain, scene, view_layer, nullptr);
5503
5504 if (use_pre_deselect) {
5506 }
5507
5508 for (Object *obedit : objects) {
5509
5510 bool changed = false;
5511
5513
5514 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
5516 }
5517 else {
5519 }
5520 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
5521
5522 std::optional<UVSelectLinkedHelper> linked_helper;
5523 if (use_select_linked) {
5524 linked_helper.emplace(scene, bm);
5525 }
5526
5527 if (uv_select_mode == UV_SELECT_FACE) {
5528 /* Handle face selection (face center). */
5529 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
5530 /* Clear the tag on hidden faces too, needed for: #uv_select_flush_from_tag_face. */
5532 if (!uvedit_face_visible_test(scene, efa)) {
5533 continue;
5534 }
5535 if (use_select_linked) {
5536 if (linked_helper->face_check(efa)) {
5537 continue;
5538 }
5539 }
5540 else {
5541 if (select == uvedit_face_select_test(scene, bm, efa)) {
5542 continue;
5543 }
5544 }
5545
5546 float cent[2];
5547 BM_face_uv_calc_center_median(efa, offsets.uv, cent);
5548 if (do_lasso_select_mesh_uv_is_point_inside(region, &rect, mcoords, cent)) {
5549 changed = true;
5550 if (use_select_linked) {
5551 linked_helper->face_add(efa);
5552 }
5553 else {
5555 }
5556 }
5557 }
5558 if (use_select_linked) {
5559 linked_helper->tag_all();
5560 }
5561
5562 /* (de)selects all tagged faces and deals with sticky modes */
5563 if (changed) {
5564 uv_select_flush_from_tag_face(scene, obedit, select);
5565 }
5566 }
5567 else if (uv_select_mode == UV_SELECT_EDGE) {
5568 /* Handle edge selection. */
5569 bool do_second_pass = true;
5570 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
5571 if (!uvedit_face_visible_test(scene, efa)) {
5572 continue;
5573 }
5574
5575 bool has_selected = false;
5576 BMLoop *l_prev = BM_FACE_FIRST_LOOP(efa)->prev;
5577 float *luv_prev = BM_ELEM_CD_GET_FLOAT_P(l_prev, offsets.uv);
5578 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
5579 float *luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
5580 if (do_lasso_select_mesh_uv_is_point_inside(region, &rect, mcoords, luv) &&
5581 do_lasso_select_mesh_uv_is_point_inside(region, &rect, mcoords, luv_prev))
5582 {
5583 uvedit_edge_select_set_with_sticky(scene, bm, l_prev, select, offsets);
5584 do_second_pass = false;
5585 has_selected = true;
5586 changed = true;
5587 }
5588 l_prev = l;
5589 luv_prev = luv;
5590 }
5591 if (has_selected && use_select_linked) {
5592 linked_helper->face_add(efa);
5593 }
5594 }
5595 /* Do a second pass if no complete edges could be selected.
5596 * This matches wire-frame edit-mesh selection in the 3D view. */
5597 if (do_second_pass) {
5598 /* Second pass to check if edges partially overlap with the selection area (lasso). */
5599 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
5600 if (!uvedit_face_visible_test(scene, efa)) {
5601 continue;
5602 }
5603 BMLoop *l_prev = BM_FACE_FIRST_LOOP(efa)->prev;
5604 float *luv_prev = BM_ELEM_CD_GET_FLOAT_P(l_prev, offsets.uv);
5605
5606 bool has_selected = false;
5607 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
5608 float *luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
5609 if (do_lasso_select_mesh_uv_is_edge_inside(region, &rect, mcoords, luv, luv_prev)) {
5610 uvedit_edge_select_set_with_sticky(scene, bm, l_prev, select, offsets);
5611 has_selected = true;
5612 changed = true;
5613 }
5614 l_prev = l;
5615 luv_prev = luv;
5616 }
5617 if (has_selected && use_select_linked) {
5618 linked_helper->face_add(efa);
5619 }
5620 }
5621 }
5622 if (use_select_linked) {
5623 linked_helper->select_all(select);
5624 }
5625 }
5626 else {
5627 /* Handle vert selection. */
5628 BLI_assert(uv_select_mode == UV_SELECT_VERT);
5629
5631
5632 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
5633 if (!uvedit_face_visible_test(scene, efa)) {
5634 continue;
5635 }
5636 bool has_selected = false;
5637 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
5638 if (select != uvedit_uv_select_test(scene, bm, l, offsets)) {
5639 float *luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
5640 if (do_lasso_select_mesh_uv_is_point_inside(region, &rect, mcoords, luv)) {
5641 uvedit_uv_select_set(scene, bm, l, select);
5642 changed = true;
5644 has_selected = true;
5645 }
5646 }
5647 }
5648 if (has_selected && use_select_linked) {
5649 linked_helper->face_add(efa);
5650 }
5651 }
5652 if (use_select_linked) {
5653 linked_helper->select_all(select);
5654 }
5655
5656 if (ts->uv_sticky == UV_STICKY_VERT) {
5658 }
5659 }
5660
5661 if (changed || use_pre_deselect) {
5662 changed_multi = true;
5663 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
5665 }
5666 else {
5668 }
5669 uv_select_tag_update_for_object(depsgraph, ts, obedit);
5670 }
5671 }
5672
5673 return changed_multi;
5674}
5675
5677{
5679 if (mcoords.is_empty()) {
5680 return OPERATOR_PASS_THROUGH;
5681 }
5682
5683 const eSelectOp sel_op = eSelectOp(RNA_enum_get(op->ptr, "mode"));
5684 bool changed = do_lasso_select_mesh_uv(C, mcoords, sel_op);
5685
5686 return changed ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
5687}
5688
5690{
5691 ot->name = "Lasso Select UV";
5692 ot->description = "Select UVs using lasso selection";
5693 ot->idname = "UV_OT_select_lasso";
5694
5700
5701 /* flags */
5703
5704 /* properties */
5707}
5708
5710
5711/* -------------------------------------------------------------------- */
5714
5716{
5717 const Scene *scene = CTX_data_scene(C);
5718 const ToolSettings *ts = scene->toolsettings;
5719
5720 /* Use this operator only in vertex mode, since it is not guaranteed that pinned vertices may
5721 * form higher selection states (like edges/faces/islands) in other modes. */
5722 if (!uvedit_select_pin_ok_or_report(scene, op->reports)) {
5723 return OPERATOR_CANCELLED;
5724 }
5725
5726 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
5727 const Main *bmain = CTX_data_main(C);
5728 ViewLayer *view_layer = CTX_data_view_layer(C);
5729 BMFace *efa;
5730 BMLoop *l;
5731 BMIter iter, liter;
5732
5734 *bmain, scene, view_layer, nullptr);
5735
5736 for (Object *obedit : objects) {
5737 Mesh &mesh = *id_cast<Mesh *>(obedit->data);
5739
5740 const StringRef active_uv_name = mesh.active_uv_map_name();
5741 if (!BM_uv_map_attr_pin_exists(bm, active_uv_name)) {
5742 continue;
5743 }
5744
5745 bool changed = false;
5746 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
5748 }
5749 else {
5751 }
5752 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
5753
5754 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
5755 if (!uvedit_face_visible_test(scene, efa)) {
5756 continue;
5757 }
5758
5759 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
5760
5761 if (BM_ELEM_CD_GET_BOOL(l, offsets.pin)) {
5762 uvedit_uv_select_enable(scene, bm, l);
5763 changed = true;
5764 }
5765 }
5766 }
5767 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
5769 }
5770 else {
5772 }
5773
5774 if (changed) {
5775 uv_select_tag_update_for_object(depsgraph, ts, obedit);
5776 }
5777 }
5778
5779 return OPERATOR_FINISHED;
5780}
5781
5783{
5784 /* identifiers */
5785 ot->name = "Selected Pinned";
5786 ot->description = "Select all pinned UV vertices";
5787 ot->idname = "UV_OT_select_pinned";
5789
5790 /* API callbacks. */
5793}
5794
5796
5797/* -------------------------------------------------------------------- */
5800
5808static bool overlap_tri_tri_uv_test(const float t1[3][2],
5809 const float t2[3][2],
5810 const float endpoint_bias)
5811{
5812 float vi[2];
5813
5814 /* Don't use 'isect_tri_tri_v2' here
5815 * because it's important to ignore overlap at end-points. */
5816 if (isect_seg_seg_v2_point_ex(t1[0], t1[1], t2[0], t2[1], endpoint_bias, vi) == 1 ||
5817 isect_seg_seg_v2_point_ex(t1[0], t1[1], t2[1], t2[2], endpoint_bias, vi) == 1 ||
5818 isect_seg_seg_v2_point_ex(t1[0], t1[1], t2[2], t2[0], endpoint_bias, vi) == 1 ||
5819 isect_seg_seg_v2_point_ex(t1[1], t1[2], t2[0], t2[1], endpoint_bias, vi) == 1 ||
5820 isect_seg_seg_v2_point_ex(t1[1], t1[2], t2[1], t2[2], endpoint_bias, vi) == 1 ||
5821 isect_seg_seg_v2_point_ex(t1[1], t1[2], t2[2], t2[0], endpoint_bias, vi) == 1 ||
5822 isect_seg_seg_v2_point_ex(t1[2], t1[0], t2[0], t2[1], endpoint_bias, vi) == 1 ||
5823 isect_seg_seg_v2_point_ex(t1[2], t1[0], t2[1], t2[2], endpoint_bias, vi) == 1)
5824 {
5825 return true;
5826 }
5827
5828 /* When none of the segments intersect, checking if either of the triangles corners
5829 * is inside the others is almost always sufficient to test if the two triangles intersect.
5830 *
5831 * However, the `endpoint_bias` on segment intersections causes _exact_ overlapping
5832 * triangles not to be detected.
5833 *
5834 * Resolve this problem at the small cost of calculating the triangle center, see #85508. */
5835 mid_v2_v2v2v2(vi, UNPACK3(t1));
5836 if (isect_point_tri_v2(vi, UNPACK3(t2)) != 0) {
5837 return true;
5838 }
5839 mid_v2_v2v2v2(vi, UNPACK3(t2));
5840 if (isect_point_tri_v2(vi, UNPACK3(t1)) != 0) {
5841 return true;
5842 }
5843
5844 return false;
5845}
5846
5847static wmOperatorStatus uv_select_overlap(bContext *C, const bool extend, const bool select_island)
5848{
5849 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
5850 const Main *bmain = CTX_data_main(C);
5851 const Scene *scene = CTX_data_scene(C);
5852 const ToolSettings *ts = scene->toolsettings;
5853 const bool uv_select_sync = (ts->uv_flag & UV_FLAG_SELECT_SYNC);
5854 ViewLayer *view_layer = CTX_data_view_layer(C);
5855
5857 *bmain, scene, view_layer, nullptr);
5858
5859 struct ChangedInfo {
5860 uint has_changed : 1 = 0;
5861 uint has_overlap : 1 = 0;
5862 };
5863
5864 struct UVOverlapData {
5865 int ob_index;
5866 int face_index;
5867 float tri[3][2];
5868 };
5869
5870 struct UVOverlapQueryData {
5871 int src_index;
5872 const UVOverlapData *all_overlap_data;
5873 const Vector<Object *> *objects;
5874 Array<ChangedInfo> *objects_tag;
5875 bool found_overlap;
5876 };
5877
5878 Array<ChangedInfo> objects_tag(objects.size());
5879
5880 /* Calculate maximum number of tree nodes and prepare initial selection. */
5881 uint uv_tri_len = 0;
5882 for (const int i : IndexRange(objects.size())) {
5883 Object *obedit = objects[i];
5884
5886
5890 if (!extend) {
5891 ED_uvedit_deselect_all(scene, obedit, SEL_DESELECT);
5892 objects_tag[i].has_changed = true;
5893 }
5894
5895 BMIter iter;
5896 BMFace *efa;
5897 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
5898 if (!uvedit_face_visible_test_ex(scene->toolsettings, efa)) {
5899 continue;
5900 }
5901 uv_tri_len += efa->len - 2;
5902 }
5903 }
5904
5905 UVOverlapData *overlap_data = MEM_new_array_uninitialized<UVOverlapData>(uv_tri_len,
5906 "UvOverlapData");
5907 BVHTree *uv_tree = BLI_bvhtree_new(uv_tri_len, 0.0f, 4, 6);
5908
5909 /* Use a global data index when inserting into the BVH. */
5910 int data_index = 0;
5911
5912 int face_len_alloc = 3;
5913 float (*uv_verts)[2] = MEM_new_array_uninitialized<float[2]>(face_len_alloc, "UvOverlapCoords");
5914 uint(*indices)[3] = MEM_new_array_uninitialized<uint[3]>(face_len_alloc - 2, "UvOverlapTris");
5915
5918
5919 for (const int ob_index : objects.index_range()) {
5920 Object *obedit = objects[ob_index];
5922 BMIter iter, liter;
5923 BMFace *efa;
5924 BMLoop *l;
5925
5926 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
5927
5928 /* Triangulate each UV face and store it inside the BVH. */
5929 int face_index;
5930 BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, face_index) {
5931
5932 if (!uvedit_face_visible_test_ex(scene->toolsettings, efa)) {
5933 continue;
5934 }
5935
5936 const uint face_len = efa->len;
5937 const uint tri_len = face_len - 2;
5938
5939 if (face_len_alloc < face_len) {
5940 MEM_delete(uv_verts);
5941 MEM_delete(indices);
5942 uv_verts = MEM_new_array_uninitialized<float[2]>(face_len, "UvOverlapCoords");
5943 indices = MEM_new_array_uninitialized<uint[3]>(tri_len, "UvOverlapTris");
5944 face_len_alloc = face_len;
5945 }
5946
5947 int vert_index;
5948 BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, vert_index) {
5949 float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
5950 copy_v2_v2(uv_verts[vert_index], luv);
5951 }
5952
5953 /* The UV coordinates winding could be positive of negative,
5954 * determine it automatically. */
5955 const int coords_sign = 0;
5956 BLI_polyfill_calc_arena(uv_verts, face_len, coords_sign, indices, arena);
5957
5958 /* A beauty fill is necessary to remove degenerate triangles that may be produced from the
5959 * above poly-fill (see #103913), otherwise the overlap tests can fail. */
5960 BLI_polyfill_beautify(uv_verts, face_len, indices, arena, heap);
5961
5962 for (int t = 0; t < tri_len; t++) {
5963 overlap_data[data_index].ob_index = ob_index;
5964 overlap_data[data_index].face_index = face_index;
5965
5966 /* BVH needs 3D, overlap data uses 2D. */
5967 const float tri[3][3] = {
5968 {UNPACK2(uv_verts[indices[t][0]]), 0.0f},
5969 {UNPACK2(uv_verts[indices[t][1]]), 0.0f},
5970 {UNPACK2(uv_verts[indices[t][2]]), 0.0f},
5971 };
5972
5973 copy_v2_v2(overlap_data[data_index].tri[0], tri[0]);
5974 copy_v2_v2(overlap_data[data_index].tri[1], tri[1]);
5975 copy_v2_v2(overlap_data[data_index].tri[2], tri[2]);
5976
5977 BLI_bvhtree_insert(uv_tree, data_index, &tri[0][0], 3);
5978 data_index++;
5979 }
5980
5981 BLI_memarena_clear(arena);
5982 BLI_heap_clear(heap, nullptr);
5983 }
5984 }
5985 BLI_assert(data_index == uv_tri_len);
5986
5987 BLI_memarena_free(arena);
5988 BLI_heap_free(heap, nullptr);
5989 MEM_delete(uv_verts);
5990 MEM_delete(indices);
5991
5992 BLI_bvhtree_balance(uv_tree);
5993
5994 /* Use a reusable 1-leaf tree to probe the main tree for overlaps.
5995 *
5996 * #BLI_bvhtree_overlap_self calculates all overlapping pairs
5997 * which causes a freeze on dense meshes with many overlaps (see #150087).
5998 *
5999 * By using a single-leaf tree and updating it per-face,
6000 * we can use #BLI_bvhtree_overlap_ex with a `max_interactions` limit of 1.
6001 * This allows the search to exit immediately when the first overlap is found. */
6002 BVHTree *probe_tree = BLI_bvhtree_new(1, 0.0f, 4, 6);
6003
6004 /* Initializing the first node so we have valid memory to update later. */
6005 float dummy_co[3][3] = {{0.0f}};
6006 BLI_bvhtree_insert(probe_tree, 0, dummy_co[0], 3);
6007 BLI_bvhtree_balance(probe_tree);
6008
6009 UVOverlapQueryData query_data = {};
6010 query_data.all_overlap_data = overlap_data;
6011 query_data.objects = &objects;
6012 query_data.objects_tag = &objects_tag;
6013
6014 auto bvh_overlap_fn = [](void *userdata, int /*index_a*/, int index_b, int /*thread*/) -> bool {
6015 UVOverlapQueryData *data = static_cast<UVOverlapQueryData *>(userdata);
6016
6017 const int src_i = data->src_index;
6018 const int dst_i = index_b;
6019
6020 /* Skip self-intersection. */
6021 if (src_i == dst_i) {
6022 return false;
6023 }
6024
6025 const UVOverlapData *src = &data->all_overlap_data[src_i];
6026 const UVOverlapData *dst = &data->all_overlap_data[dst_i];
6027
6028 /* Skip triangles from the same face. */
6029 if (src->ob_index == dst->ob_index && src->face_index == dst->face_index) {
6030 return false;
6031 }
6032
6033 /* Check exact overlap. */
6034 const float endpoint_bias = -1e-4f;
6035 if (overlap_tri_tri_uv_test(src->tri, dst->tri, endpoint_bias)) {
6036 Object *ob_src = (*data->objects)[src->ob_index];
6037 Object *ob_dst = (*data->objects)[dst->ob_index];
6038
6039 BMesh *bm_src = BKE_editmesh_bmesh_get_for_write(ob_src);
6040 BMesh *bm_dst = BKE_editmesh_bmesh_get_for_write(ob_dst);
6041
6042 BMFace *face_src = bm_src->ftable[src->face_index];
6043 BMFace *face_dst = bm_dst->ftable[dst->face_index];
6044
6047
6048 (*data->objects_tag)[src->ob_index].has_overlap = true;
6049 (*data->objects_tag)[dst->ob_index].has_overlap = true;
6050
6051 data->found_overlap = true;
6052 return true;
6053 }
6054
6055 return false;
6056 };
6057
6058 for (int i = 0; i < uv_tri_len; i++) {
6059 UVOverlapData *src_data = &overlap_data[i];
6060 Object *ob = objects[src_data->ob_index];
6062 BMFace *face = bm->ftable[src_data->face_index];
6063
6064 if (BM_elem_flag_test(face, BM_ELEM_TAG)) {
6065 continue;
6066 }
6067
6068 /* Convert 2D UV tri to 3D for BVH update. */
6069 float tri_3d[3][3];
6070 for (int j = 0; j < 3; j++) {
6071 copy_v2_v2(tri_3d[j], src_data->tri[j]);
6072 tri_3d[j][2] = 0.0f;
6073 }
6074
6075 BLI_bvhtree_update_node(probe_tree, 0, &tri_3d[0][0], nullptr, 3);
6076 BLI_bvhtree_update_tree(probe_tree);
6077 query_data.src_index = i;
6078 query_data.found_overlap = false;
6079
6080 BLI_bvhtree_overlap_ex(probe_tree, uv_tree, nullptr, bvh_overlap_fn, &query_data, 1, 0);
6081 }
6082
6083 if (select_island) {
6084 for (const int i : IndexRange(objects.size())) {
6085 if (!objects_tag[i].has_overlap) {
6086 continue;
6087 }
6088
6089 Object *obedit = objects[i];
6091 UVSelectLinkedHelper linked_helper(scene, bm);
6092
6093 BMFace *efa;
6094 BMIter iter;
6095 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
6096 if (BM_elem_flag_test(efa, BM_ELEM_TAG)) {
6097 linked_helper.face_add(efa);
6098 }
6099 }
6100 linked_helper.tag_all();
6101 }
6102 }
6103
6104 for (const int i : IndexRange(objects.size())) {
6105 Object *obedit = objects[i];
6106 const ChangedInfo &tag_info = objects_tag[i];
6107 const bool select = true;
6108
6109 if (tag_info.has_overlap) {
6111
6112 if (uv_select_sync) {
6114 }
6115 else {
6117 }
6118 uv_select_flush_from_tag_face(scene, obedit, select);
6119
6120 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
6122 }
6123 else {
6125 }
6126 }
6127
6128 if (tag_info.has_changed || tag_info.has_overlap) {
6129 uv_select_tag_update_for_object(depsgraph, scene->toolsettings, obedit);
6130 }
6131 }
6132
6133 BLI_bvhtree_free(uv_tree);
6134 BLI_bvhtree_free(probe_tree);
6135
6136 MEM_delete(overlap_data);
6137
6138 return OPERATOR_FINISHED;
6139}
6140
6142{
6144 const bool use_select_linked = ED_uvedit_select_island_check(ts);
6145
6146 bool extend = RNA_boolean_get(op->ptr, "extend");
6147 return uv_select_overlap(C, extend, use_select_linked);
6148}
6149
6151{
6152 /* identifiers */
6153 ot->name = "Select Overlap";
6154 ot->description = "Select all UV faces which overlap each other";
6155 ot->idname = "UV_OT_select_overlap";
6157
6158 /* API callbacks. */
6161
6162 /* properties */
6164 "extend",
6165 false,
6166 "Extend",
6167 "Extend selection rather than clearing the existing selection");
6168}
6169
6170enum class UVWinding {
6173};
6174
6176{
6177 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
6178 const Main *bmain = CTX_data_main(C);
6179 Scene *scene = CTX_data_scene(C);
6180 const ToolSettings *ts = scene->toolsettings;
6181 ViewLayer *view_layer = CTX_data_view_layer(C);
6182 const bool extend = RNA_boolean_get(op->ptr, "extend");
6183 const int winding = RNA_enum_get(op->ptr, "winding");
6184 const float winding_sign = winding == int(UVWinding::Positive) ? -1.0f : 1.0f;
6185
6187 *bmain, scene, view_layer, nullptr);
6188
6189 if (!extend) {
6191 }
6192
6193 for (Object *obedit : objects) {
6195 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
6196
6198
6199 bool changed = false;
6200 BMFace *efa;
6201 BMIter iter;
6202 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
6203 if (!uvedit_face_visible_test(scene, efa)) {
6204 continue;
6205 }
6206 const float area = BM_face_calc_area_uv_signed(efa, offsets.uv);
6207 if (area * winding_sign > 0.0f) {
6209 changed = true;
6210 }
6211 }
6212
6213 if (changed) {
6214 uv_select_flush_from_tag_face(scene, obedit, true);
6215
6216 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
6218 }
6219 else {
6221 }
6222
6223 uv_select_tag_update_for_object(depsgraph, ts, obedit);
6224 }
6225 }
6226
6227 return OPERATOR_FINISHED;
6228}
6229
6231{
6232 static const EnumPropertyItem prop_winding_types[] = {
6233 {int(UVWinding::Positive), "POSITIVE", 0, "Positive", ""},
6234 {int(UVWinding::Negative), "NEGATIVE", 0, "Negative", ""},
6235 {0, nullptr, 0, nullptr, nullptr},
6236 };
6237
6238 /* identifiers */
6239 ot->name = "Select by Winding";
6240 ot->description = "Select UV faces by their winding";
6241 ot->idname = "UV_OT_select_by_winding";
6243
6244 /* API callbacks. */
6247
6248 /* properties */
6249 RNA_def_enum(ot->srna,
6250 "winding",
6251 prop_winding_types,
6253 "Winding",
6254 "Select faces with positive or negative winding");
6256 "extend",
6257 false,
6258 "Extend",
6259 "Extend selection rather than clearing the existing selection");
6260}
6261
6263
6264/* -------------------------------------------------------------------- */
6267
6268static float get_uv_vert_needle(const eUVSelectSimilar type,
6269 BMVert *vert,
6270 const float ob_m3[3][3],
6271 BMLoop *loop,
6272 const BMUVOffsets &offsets)
6273{
6274 BLI_assert(offsets.pin >= 0);
6275 BLI_assert(offsets.uv >= 0);
6276
6277 float result = 0.0f;
6278 switch (type) {
6279 case UV_SSIM_AREA_UV: {
6280 BMFace *f;
6281 BMIter iter;
6282 BM_ITER_ELEM (f, &iter, vert, BM_FACES_OF_VERT) {
6283 result += BM_face_calc_area_uv(f, offsets.uv);
6284 }
6285 break;
6286 }
6287 case UV_SSIM_AREA_3D: {
6288 BMFace *f;
6289 BMIter iter;
6290 BM_ITER_ELEM (f, &iter, vert, BM_FACES_OF_VERT) {
6292 }
6293 break;
6294 }
6295 case UV_SSIM_SIDES: {
6296 BMEdge *e;
6297 BMIter iter;
6298 BM_ITER_ELEM (e, &iter, vert, BM_EDGES_OF_VERT) {
6299 result += 1.0f;
6300 }
6301 break;
6302 }
6303 case UV_SSIM_PIN:
6304 return BM_ELEM_CD_GET_BOOL(loop, offsets.pin) ? 1.0f : 0.0f;
6305 default:
6307 return false;
6308 }
6309
6310 return result;
6311}
6312
6313static float get_uv_edge_needle(const eUVSelectSimilar type,
6314 BMEdge *edge,
6315 const float ob_m3[3][3],
6316 BMLoop *loop_a,
6317 BMLoop *loop_b,
6318 const BMUVOffsets &offsets)
6319{
6320 BLI_assert(offsets.pin >= 0);
6321 BLI_assert(offsets.uv >= 0);
6322 float result = 0.0f;
6323 switch (type) {
6324 case UV_SSIM_AREA_UV: {
6325 BMFace *f;
6326 BMIter iter;
6327 BM_ITER_ELEM (f, &iter, edge, BM_FACES_OF_EDGE) {
6328 result += BM_face_calc_area_uv(f, offsets.uv);
6329 }
6330 break;
6331 }
6332 case UV_SSIM_AREA_3D: {
6333 BMFace *f;
6334 BMIter iter;
6335 BM_ITER_ELEM (f, &iter, edge, BM_FACES_OF_EDGE) {
6337 }
6338 break;
6339 }
6340 case UV_SSIM_LENGTH_UV: {
6341 float *luv_a = BM_ELEM_CD_GET_FLOAT_P(loop_a, offsets.uv);
6342 float *luv_b = BM_ELEM_CD_GET_FLOAT_P(loop_b, offsets.uv);
6343 return len_v2v2(luv_a, luv_b);
6344 }
6345 case UV_SSIM_LENGTH_3D:
6346 return len_v3v3(edge->v1->co, edge->v2->co);
6347 case UV_SSIM_SIDES: {
6348 BMEdge *e;
6349 BMIter iter;
6350 BM_ITER_ELEM (e, &iter, edge, BM_FACES_OF_EDGE) {
6351 result += 1.0f;
6352 }
6353 break;
6354 }
6355 case UV_SSIM_PIN: {
6356 if (BM_ELEM_CD_GET_BOOL(loop_a, offsets.pin)) {
6357 result += 1.0f;
6358 }
6359 if (BM_ELEM_CD_GET_BOOL(loop_b, offsets.pin)) {
6360 result += 1.0f;
6361 }
6362 break;
6363 }
6364 default:
6366 return false;
6367 }
6368
6369 return result;
6370}
6371
6372static float get_uv_face_needle(const eUVSelectSimilar type,
6373 BMFace *face,
6374 const int ob_index,
6375 const float ob_m3[3][3],
6376 const BMUVOffsets &offsets,
6377 const Span<int> material_remap)
6378{
6379 BLI_assert(offsets.pin >= 0);
6380 BLI_assert(offsets.uv >= 0);
6381 float result = 0.0f;
6382 switch (type) {
6383 case UV_SSIM_AREA_UV:
6384 return BM_face_calc_area_uv(face, offsets.uv);
6385 case UV_SSIM_AREA_3D:
6386 return BM_face_calc_area_with_mat3(face, ob_m3);
6387 case UV_SSIM_SIDES:
6388 return face->len;
6389 case UV_SSIM_OBJECT:
6390 return ob_index;
6391 case UV_SSIM_PIN: {
6392 BMLoop *l;
6393 BMIter liter;
6394 BM_ITER_ELEM (l, &liter, face, BM_LOOPS_OF_FACE) {
6395 if (BM_ELEM_CD_GET_BOOL(l, offsets.pin)) {
6396 result += 1.0f;
6397 }
6398 }
6399 break;
6400 }
6401 case UV_SSIM_MATERIAL: {
6402 const int mat_nr = (uint(face->mat_nr) < material_remap.size()) ? face->mat_nr : 0;
6403 return material_remap[mat_nr];
6404 }
6405 case UV_SSIM_WINDING:
6406 return signum_i(BM_face_calc_area_uv_signed(face, offsets.uv));
6407 default:
6409 return false;
6410 }
6411 return result;
6412}
6413
6415 const FaceIsland *island,
6416 const float ob_m3[3][3],
6417 const BMUVOffsets &offsets)
6418
6419{
6420 BLI_assert(offsets.uv >= 0);
6421 float result = 0.0f;
6422 switch (type) {
6423 case UV_SSIM_AREA_UV:
6424 for (int i = 0; i < island->faces_len; i++) {
6425 result += BM_face_calc_area_uv(island->faces[i], offsets.uv);
6426 }
6427 break;
6428 case UV_SSIM_AREA_3D:
6429 for (int i = 0; i < island->faces_len; i++) {
6430 result += BM_face_calc_area_with_mat3(island->faces[i], ob_m3);
6431 }
6432 break;
6433 case UV_SSIM_FACE:
6434 return island->faces_len;
6435 default:
6437 return false;
6438 }
6439 return result;
6440}
6441
6443{
6444 const Main *bmain = CTX_data_main(C);
6445 Scene *scene = CTX_data_scene(C);
6446 ViewLayer *view_layer = CTX_data_view_layer(C);
6447 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
6449
6450 const eUVSelectSimilar type = eUVSelectSimilar(RNA_enum_get(op->ptr, "type"));
6451 const float threshold = RNA_float_get(op->ptr, "threshold");
6452 const eSimilarCmp compare = eSimilarCmp(RNA_enum_get(op->ptr, "compare"));
6453
6455 *bmain, scene, view_layer, nullptr);
6456
6457 int tree_index = 0;
6458 Map<float, int> points_1d;
6459
6460 for (Object *ob : objects) {
6462 if (bm->totvertsel == 0) {
6463 continue;
6464 }
6465
6466 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
6467 float ob_m3[3][3];
6468 copy_m3_m4(ob_m3, ob->object_to_world().ptr());
6469
6470 BMFace *face;
6471 BMIter iter;
6472 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
6473 if (!uvedit_face_visible_test(scene, face)) {
6474 continue;
6475 }
6476 BMLoop *l;
6477 BMIter liter;
6478 BM_ITER_ELEM (l, &liter, face, BM_LOOPS_OF_FACE) {
6479 if (!uvedit_uv_select_test(scene, bm, l, offsets)) {
6480 continue;
6481 }
6482 float needle = get_uv_vert_needle(type, l->v, ob_m3, l, offsets);
6483 points_1d.add(needle, tree_index++);
6484 }
6485 }
6486 }
6487
6488 KDTree<float> *tree_1d = kdtree_new<float>(points_1d.size());
6489 for (const auto &[pos, index] : points_1d.items()) {
6490 kdtree_insert(tree_1d, index, pos);
6491 }
6492 kdtree_balance<float>(tree_1d);
6493
6494 for (Object *ob : objects) {
6496 if (bm->totvertsel == 0) {
6497 /* No selection means no visible UV's unless sync-select is enabled. */
6498 if (!(ts->uv_flag & UV_FLAG_SELECT_SYNC)) {
6499 continue;
6500 }
6501 }
6502
6503 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
6505 }
6506
6507 bool changed = false;
6508
6509 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
6510 float ob_m3[3][3];
6511 copy_m3_m4(ob_m3, ob->object_to_world().ptr());
6512
6513 BMFace *face;
6514 BMIter iter;
6515 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
6516 if (!uvedit_face_visible_test(scene, face)) {
6517 continue;
6518 }
6519 BMLoop *l;
6520 BMIter liter;
6521 BM_ITER_ELEM (l, &liter, face, BM_LOOPS_OF_FACE) {
6522 if (uvedit_uv_select_test(scene, bm, l, offsets)) {
6523 continue; /* Already selected. */
6524 }
6525 const float needle = get_uv_vert_needle(type, l->v, ob_m3, l, offsets);
6526 bool select = ED_select_similar_compare_float_tree(tree_1d, needle, threshold, compare);
6527 if (select) {
6528 uvedit_uv_select_set(scene, bm, l, select);
6529 changed = true;
6530 }
6531 }
6532 }
6533 if (changed) {
6534 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
6535 if (bm->uv_select_sync_valid) {
6538 }
6539 else {
6541 }
6542 }
6543 else {
6544 uvedit_select_flush_from_verts(scene, bm, true);
6545 }
6546 uv_select_tag_update_for_object(depsgraph, ts, ob);
6547 }
6548 }
6549
6550 kdtree_free<float>(tree_1d);
6551 return OPERATOR_FINISHED;
6552}
6553
6555{
6556 const Main *bmain = CTX_data_main(C);
6557 Scene *scene = CTX_data_scene(C);
6558 ViewLayer *view_layer = CTX_data_view_layer(C);
6559 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
6561
6562 const eUVSelectSimilar type = eUVSelectSimilar(RNA_enum_get(op->ptr, "type"));
6563 const float threshold = RNA_float_get(op->ptr, "threshold");
6564 const eSimilarCmp compare = eSimilarCmp(RNA_enum_get(op->ptr, "compare"));
6565
6567 *bmain, scene, view_layer, nullptr);
6568
6569 int tree_index = 0;
6570 Map<float, int> points_1d;
6571
6572 for (Object *ob : objects) {
6574 if (bm->totvertsel == 0) {
6575 continue;
6576 }
6577
6578 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
6579 float ob_m3[3][3];
6580 copy_m3_m4(ob_m3, ob->object_to_world().ptr());
6581
6582 BMFace *face;
6583 BMIter iter;
6584 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
6585 if (!uvedit_face_visible_test(scene, face)) {
6586 continue;
6587 }
6588 BMLoop *l;
6589 BMIter liter;
6590 BM_ITER_ELEM (l, &liter, face, BM_LOOPS_OF_FACE) {
6591 if (!uvedit_edge_select_test(scene, bm, l, offsets)) {
6592 continue;
6593 }
6594
6595 float needle = get_uv_edge_needle(type, l->e, ob_m3, l, l->next, offsets);
6596 points_1d.add(needle, tree_index++);
6597 }
6598 }
6599 }
6600
6601 KDTree<float> *tree_1d = kdtree_new<float>(points_1d.size());
6602 for (const auto &[pos, index] : points_1d.items()) {
6603 kdtree_insert(tree_1d, index, pos);
6604 }
6605 kdtree_balance<float>(tree_1d);
6606
6607 for (Object *ob : objects) {
6609 if (bm->totvertsel == 0) {
6610 /* No selection means no visible UV's unless sync-select is enabled. */
6611 if (!(ts->uv_flag & UV_FLAG_SELECT_SYNC)) {
6612 continue;
6613 }
6614 }
6615
6616 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
6618 }
6619
6620 bool changed = false;
6621 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
6622 float ob_m3[3][3];
6623 copy_m3_m4(ob_m3, ob->object_to_world().ptr());
6624
6625 BMFace *face;
6626 BMIter iter;
6627 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
6628 if (!uvedit_face_visible_test(scene, face)) {
6629 continue;
6630 }
6631 BMLoop *l;
6632 BMIter liter;
6633 BM_ITER_ELEM (l, &liter, face, BM_LOOPS_OF_FACE) {
6634 if (uvedit_edge_select_test(scene, bm, l, offsets)) {
6635 continue; /* Already selected. */
6636 }
6637
6638 float needle = get_uv_edge_needle(type, l->e, ob_m3, l, l->next, offsets);
6639 bool select = ED_select_similar_compare_float_tree(tree_1d, needle, threshold, compare);
6640 if (select) {
6642 changed = true;
6643 }
6644 }
6645 }
6646 if (changed) {
6647 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
6648 if (bm->uv_select_sync_valid) {
6651 }
6652 else {
6654 }
6655 }
6656 else {
6657 uvedit_select_flush_from_verts(scene, bm, true);
6658 }
6659 uv_select_tag_update_for_object(depsgraph, ts, ob);
6660 }
6661 }
6662
6663 kdtree_free<float>(tree_1d);
6664 return OPERATOR_FINISHED;
6665}
6666
6668{
6669 const Main *bmain = CTX_data_main(C);
6670 Scene *scene = CTX_data_scene(C);
6671 ViewLayer *view_layer = CTX_data_view_layer(C);
6672 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
6674
6675 const eUVSelectSimilar type = eUVSelectSimilar(RNA_enum_get(op->ptr, "type"));
6676 const float threshold = RNA_float_get(op->ptr, "threshold");
6677 const eSimilarCmp compare = eSimilarCmp(RNA_enum_get(op->ptr, "compare"));
6678
6680 *bmain, scene, view_layer, nullptr);
6681
6682 /* Build a global material-to-index map so material indices are shared across all objects. */
6683 std::optional<Vector<Array<int>>> material_remaps_data;
6684 if (type == UV_SSIM_MATERIAL) {
6685 material_remaps_data.emplace(objects.size());
6686 Vector<Array<int>> &material_remaps = *material_remaps_data;
6687 Map<const Material *, int> material_map;
6688 for (const int ob_index : objects.index_range()) {
6689 Object *ob = objects[ob_index];
6690 const int totcol = std::max<int>(ob->totcol, 1);
6691 material_remaps[ob_index].reinitialize(totcol);
6692 for (int i = 0; i < totcol; i++) {
6693 const Material *ma = BKE_object_material_get(ob, i + 1);
6694 material_remaps[ob_index][i] = material_map.lookup_or_add(ma, material_map.size());
6695 }
6696 }
6697 }
6698
6699 int tree_index = 0;
6700 Map<float, int> points_1d;
6701
6702 for (const int ob_index : objects.index_range()) {
6703 Object *ob = objects[ob_index];
6705 if (bm->totvertsel == 0) {
6706 continue;
6707 }
6708
6709 float ob_m3[3][3];
6710 copy_m3_m4(ob_m3, ob->object_to_world().ptr());
6711
6712 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
6713 const Span<int> material_remap = material_remaps_data ?
6714 Span<int>((*material_remaps_data)[ob_index]) :
6715 Span<int>();
6716
6717 BMFace *face;
6718 BMIter iter;
6719 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
6720 if (!uvedit_face_visible_test(scene, face)) {
6721 continue;
6722 }
6723 if (!uvedit_face_select_test(scene, bm, face)) {
6724 continue;
6725 }
6726
6727 float needle = get_uv_face_needle(type, face, ob_index, ob_m3, offsets, material_remap);
6728 points_1d.add(needle, tree_index++);
6729 }
6730 }
6731
6732 KDTree<float> *tree_1d = kdtree_new<float>(points_1d.size());
6733 for (const auto &[pos, index] : points_1d.items()) {
6734 kdtree_insert(tree_1d, index, pos);
6735 }
6736 kdtree_balance<float>(tree_1d);
6737
6738 for (const int ob_index : objects.index_range()) {
6739 Object *ob = objects[ob_index];
6741 if (bm->totvertsel == 0) {
6742 /* No selection means no visible UV's unless sync-select is enabled. */
6743 if (!(ts->uv_flag & UV_FLAG_SELECT_SYNC)) {
6744 continue;
6745 }
6746 }
6747
6748 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
6750 }
6751
6752 bool changed = false;
6753
6754 float ob_m3[3][3];
6755 copy_m3_m4(ob_m3, ob->object_to_world().ptr());
6756
6757 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
6758 const Span<int> material_remap = material_remaps_data ?
6759 Span<int>((*material_remaps_data)[ob_index]) :
6760 Span<int>();
6761
6762 BMFace *face;
6763 BMIter iter;
6764 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
6765 if (!uvedit_face_visible_test(scene, face)) {
6766 continue;
6767 }
6768 if (uvedit_face_select_test(scene, bm, face)) {
6769 continue;
6770 }
6771
6772 float needle = get_uv_face_needle(type, face, ob_index, ob_m3, offsets, material_remap);
6773
6774 bool select = ED_select_similar_compare_float_tree(tree_1d, needle, threshold, compare);
6775 if (select) {
6776 uvedit_face_select_set(scene, bm, face, select);
6777 changed = true;
6778 }
6779 }
6780 if (changed) {
6781 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
6782 if (bm->uv_select_sync_valid) {
6785 }
6786 else {
6788 }
6789 }
6790 else {
6791 uvedit_select_flush_from_verts(scene, bm, true);
6792 }
6793 uv_select_tag_update_for_object(depsgraph, ts, ob);
6794 }
6795 }
6796
6797 kdtree_free<float>(tree_1d);
6798 return OPERATOR_FINISHED;
6799}
6800
6801static bool uv_island_selected(const Scene *scene, const BMesh *bm, FaceIsland *island)
6802{
6803 BLI_assert(island && island->faces_len);
6804 return uvedit_face_select_test(scene, bm, island->faces[0]);
6805}
6806
6808{
6809 const Main *bmain = CTX_data_main(C);
6810 Scene *scene = CTX_data_scene(C);
6811 ViewLayer *view_layer = CTX_data_view_layer(C);
6812 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
6814
6815 const eUVSelectSimilar type = eUVSelectSimilar(RNA_enum_get(op->ptr, "type"));
6816 const float threshold = RNA_float_get(op->ptr, "threshold");
6817 const eSimilarCmp compare = eSimilarCmp(RNA_enum_get(op->ptr, "compare"));
6818
6820 *bmain, scene, view_layer, nullptr);
6821
6822 ListBaseT<FaceIsland> *island_list_ptr = MEM_new_array_zeroed<ListBaseT<FaceIsland>>(
6823 objects.size(), __func__);
6824 int island_list_len = 0;
6825
6826 const bool face_selected = !(scene->toolsettings->uv_flag & UV_FLAG_SELECT_SYNC);
6827
6828 for (const int ob_index : objects.index_range()) {
6829 Object *obedit = objects[ob_index];
6831 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
6832 float aspect_y = 1.0f; /* Placeholder value, aspect doesn't change connectivity. */
6833 island_list_len += bm_mesh_calc_uv_islands(
6834 scene, bm, &island_list_ptr[ob_index], face_selected, false, false, aspect_y, offsets);
6835 }
6836
6837 FaceIsland **island_array = MEM_new_array_zeroed<FaceIsland *>(island_list_len, __func__);
6838
6839 int tree_index = 0;
6840 Map<float, int> points_1d;
6841
6842 for (const int ob_index : objects.index_range()) {
6843 Object *obedit = objects[ob_index];
6845
6846 float ob_m3[3][3];
6847 copy_m3_m4(ob_m3, obedit->object_to_world().ptr());
6848
6849 for (const auto [index, island] : island_list_ptr[ob_index].enumerate()) {
6850 island_array[index] = &island;
6851 if (!uv_island_selected(scene, bm, &island)) {
6852 continue;
6853 }
6854 float needle = get_uv_island_needle(type, &island, ob_m3, island.offsets);
6855 points_1d.add(needle, tree_index++);
6856 }
6857 }
6858
6859 KDTree<float> *tree_1d = kdtree_new<float>(points_1d.size());
6860 for (const auto &[pos, index] : points_1d.items()) {
6861 kdtree_insert(tree_1d, index, pos);
6862 }
6863 kdtree_balance<float>(tree_1d);
6864
6865 int tot_island_index = 0;
6866 for (const int ob_index : objects.index_range()) {
6867 Object *obedit = objects[ob_index];
6869
6870 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
6872 }
6873
6874 float ob_m3[3][3];
6875 copy_m3_m4(ob_m3, obedit->object_to_world().ptr());
6876
6877 bool changed = false;
6878
6879 for (const auto [index, island] : island_list_ptr[ob_index].enumerate()) {
6880 island_array[tot_island_index++] = &island; /* To deallocate later. */
6881 if (uv_island_selected(scene, bm, &island)) {
6882 continue;
6883 }
6884 float needle = get_uv_island_needle(type, &island, ob_m3, island.offsets);
6885 bool select = ED_select_similar_compare_float_tree(tree_1d, needle, threshold, compare);
6886 if (!select) {
6887 continue;
6888 }
6889 for (int j = 0; j < island.faces_len; j++) {
6890 uvedit_face_select_set(scene, bm, island.faces[j], select);
6891 }
6892 changed = true;
6893 }
6894
6895 if (changed) {
6896 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
6897 if (bm->uv_select_sync_valid) {
6900 }
6901 else {
6903 }
6904 }
6905 else {
6906 uvedit_select_flush_from_verts(scene, bm, true);
6907 }
6908 uv_select_tag_update_for_object(depsgraph, ts, obedit);
6909 }
6910 }
6911
6912 BLI_assert(tot_island_index == island_list_len);
6913 for (int i = 0; i < island_list_len; i++) {
6914 MEM_SAFE_DELETE(island_array[i]->faces);
6915 MEM_SAFE_DELETE(island_array[i]);
6916 }
6917
6918 MEM_SAFE_DELETE(island_array);
6919 MEM_SAFE_DELETE(island_list_ptr);
6920 kdtree_free<float>(tree_1d);
6921
6922 return OPERATOR_FINISHED;
6923}
6924
6925/* Select similar UV faces/edges/verts based on current selection. */
6927{
6929 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "threshold");
6930 const bool use_select_linked = ED_uvedit_select_island_check(ts);
6931
6932 if (!RNA_property_is_set(op->ptr, prop)) {
6934 }
6935 else {
6936 ts->select_thresh = RNA_property_float_get(op->ptr, prop);
6937 }
6938
6939 const int selectmode = (ts->uv_flag & UV_FLAG_SELECT_SYNC) ? ts->selectmode :
6940 int(ts->uv_selectmode);
6941 if (use_select_linked) {
6942 return uv_select_similar_island_exec(C, op);
6943 }
6944 if (selectmode & UV_SELECT_FACE) {
6945 return uv_select_similar_face_exec(C, op);
6946 }
6947 if (selectmode & UV_SELECT_EDGE) {
6948 return uv_select_similar_edge_exec(C, op);
6949 }
6950 /* #UV_SELECT_VERT */
6951 return uv_select_similar_vert_exec(C, op);
6952}
6953
6955 {UV_SSIM_PIN, "PIN", 0, "Pinned", ""},
6956 {UV_SSIM_LENGTH_UV, "LENGTH", 0, "Length", "Edge length in UV space"},
6957 {UV_SSIM_LENGTH_3D, "LENGTH_3D", 0, "Length 3D", "Length of edge in 3D space"},
6958 {UV_SSIM_AREA_UV, "AREA", 0, "Area", "Face area in UV space"},
6959 {UV_SSIM_AREA_3D, "AREA_3D", 0, "Area 3D", "Area of face in 3D space"},
6960 {UV_SSIM_MATERIAL, "MATERIAL", 0, "Material", ""},
6961 {UV_SSIM_OBJECT, "OBJECT", 0, "Object", ""},
6962 {UV_SSIM_SIDES, "SIDES", 0, "Polygon Sides", ""},
6964 "WINDING",
6965 0,
6966 "Winding",
6967 "Face direction defined by clockwise or anti-clockwise winding (facing up or facing down)"},
6968 {UV_SSIM_FACE, "FACE", 0, "Amount of Faces in Island", ""},
6969 {0}};
6970
6971static EnumPropertyItem prop_similar_compare_types[] = {{SIM_CMP_EQ, "EQUAL", 0, "Equal", ""},
6972 {SIM_CMP_GT, "GREATER", 0, "Greater", ""},
6973 {SIM_CMP_LT, "LESS", 0, "Less", ""},
6974 {0}};
6975
6977 PointerRNA * /*ptr*/,
6978 PropertyRNA * /*prop*/,
6979 bool *r_free)
6980{
6981 EnumPropertyItem *item = nullptr;
6982 int totitem = 0;
6983
6984 const ToolSettings *ts = (C) ? CTX_data_tool_settings(C) : nullptr;
6985 if (ts) {
6986 const bool use_select_linked = ED_uvedit_select_island_check(ts);
6987 const int selectmode = (ts->uv_flag & UV_FLAG_SELECT_SYNC) ? ts->selectmode :
6988 int(ts->uv_selectmode);
6989 /* TODO: co-exist with selection modes. */
6990 if (use_select_linked) {
6994 }
6995 else if (selectmode & UV_SELECT_FACE) {
7002 }
7003 else if (selectmode & UV_SELECT_EDGE) {
7007 }
7008 else {
7009 /* #UV_SELECT_VERT */
7011 }
7012 }
7013 else {
7015 }
7016
7017 RNA_enum_item_end(&item, &totitem);
7018 *r_free = true;
7019 return item;
7020}
7021
7023{
7024 /* identifiers */
7025 ot->name = "Select Similar";
7026 ot->description = "Select similar UVs by property types";
7027 ot->idname = "UV_OT_select_similar";
7028
7029 /* API callbacks. */
7030 ot->invoke = WM_menu_invoke;
7033
7034 /* flags */
7036
7037 /* properties */
7038 PropertyRNA *prop = ot->prop = RNA_def_enum(
7039 ot->srna, "type", uv_select_similar_type_items, SIMVERT_NORMAL, "Type", "");
7042 RNA_def_enum(ot->srna, "compare", prop_similar_compare_types, SIM_CMP_EQ, "Compare", "");
7043 RNA_def_float(ot->srna, "threshold", 0.0f, 0.0f, 1.0f, "Threshold", "", 0.0f, 1.0f);
7044}
7045
7047
7048/* -------------------------------------------------------------------- */
7054
7055BMFace **ED_uvedit_selected_faces(const Scene *scene, BMesh *bm, int len_max, int *r_faces_len)
7056{
7057 CLAMP_MAX(len_max, bm->totface);
7058 int faces_len = 0;
7059 BMFace **faces = MEM_new_array_uninitialized<BMFace *>(len_max, __func__);
7060
7061 BMIter iter;
7062 BMFace *f;
7063 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
7064 if (uvedit_face_visible_test(scene, f)) {
7065 if (uvedit_face_select_test(scene, bm, f)) {
7066 faces[faces_len++] = f;
7067 if (faces_len == len_max) {
7068 goto finally;
7069 }
7070 }
7071 }
7072 }
7073
7074finally:
7075 *r_faces_len = faces_len;
7076 if (faces_len != len_max) {
7077 faces = static_cast<BMFace **>(MEM_realloc_uninitialized(faces, sizeof(*faces) * faces_len));
7078 }
7079 return faces;
7080}
7081
7082BMLoop **ED_uvedit_selected_edges(const Scene *scene, BMesh *bm, int len_max, int *r_edges_len)
7083{
7084 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
7085 BLI_assert(offsets.uv >= 0);
7086
7087 CLAMP_MAX(len_max, bm->totloop);
7088 int edges_len = 0;
7089 BMLoop **edges = MEM_new_array_uninitialized<BMLoop *>(len_max, __func__);
7090
7091 BMIter iter;
7092 BMFace *f;
7093
7094 /* Clear tag. */
7095 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
7096 BMIter liter;
7097 BMLoop *l_iter;
7098 BM_ITER_ELEM (l_iter, &liter, f, BM_LOOPS_OF_FACE) {
7100 }
7101 }
7102
7103 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
7104 if (uvedit_face_visible_test(scene, f)) {
7105 BMIter liter;
7106 BMLoop *l_iter;
7107 BM_ITER_ELEM (l_iter, &liter, f, BM_LOOPS_OF_FACE) {
7108 if (!BM_elem_flag_test(l_iter, BM_ELEM_TAG)) {
7109 if (uvedit_edge_select_test(scene, bm, l_iter, offsets)) {
7111
7112 edges[edges_len++] = l_iter;
7113 if (edges_len == len_max) {
7114 goto finally;
7115 }
7116
7117 /* Tag other connected loops so we don't consider them separate edges. */
7118 if (l_iter != l_iter->radial_next) {
7119 BMLoop *l_radial_iter = l_iter->radial_next;
7120 do {
7121 if (BM_loop_uv_share_edge_check(l_iter, l_radial_iter, offsets.uv)) {
7122 BM_elem_flag_enable(l_radial_iter, BM_ELEM_TAG);
7123 }
7124 } while ((l_radial_iter = l_radial_iter->radial_next) != l_iter);
7125 }
7126 }
7127 }
7128 }
7129 }
7130 }
7131
7132finally:
7133 *r_edges_len = edges_len;
7134 if (edges_len != len_max) {
7135 edges = static_cast<BMLoop **>(MEM_realloc_uninitialized(edges, sizeof(*edges) * edges_len));
7136 }
7137 return edges;
7138}
7139
7140BMLoop **ED_uvedit_selected_verts(const Scene *scene, BMesh *bm, int len_max, int *r_verts_len)
7141{
7142 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
7143 BLI_assert(offsets.uv >= 0);
7144
7145 CLAMP_MAX(len_max, bm->totloop);
7146 int verts_len = 0;
7147 BMLoop **verts = MEM_new_array_uninitialized<BMLoop *>(len_max, __func__);
7148
7149 BMIter iter;
7150 BMFace *f;
7151
7152 /* Clear tag. */
7153 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
7154 BMIter liter;
7155 BMLoop *l_iter;
7156 BM_ITER_ELEM (l_iter, &liter, f, BM_LOOPS_OF_FACE) {
7158 }
7159 }
7160
7161 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
7162 if (uvedit_face_visible_test(scene, f)) {
7163 BMIter liter;
7164 BMLoop *l_iter;
7165 BM_ITER_ELEM (l_iter, &liter, f, BM_LOOPS_OF_FACE) {
7166 if (!BM_elem_flag_test(l_iter, BM_ELEM_TAG)) {
7167 if (uvedit_uv_select_test(scene, bm, l_iter, offsets)) {
7169
7170 verts[verts_len++] = l_iter;
7171 if (verts_len == len_max) {
7172 goto finally;
7173 }
7174
7175 /* Tag other connected loops so we don't consider them separate vertices. */
7176 BMIter liter_disk;
7177 BMLoop *l_disk_iter;
7178 BM_ITER_ELEM (l_disk_iter, &liter_disk, l_iter->v, BM_LOOPS_OF_VERT) {
7179 if (BM_loop_uv_share_vert_check(l_iter, l_disk_iter, offsets.uv)) {
7180 BM_elem_flag_enable(l_disk_iter, BM_ELEM_TAG);
7181 }
7182 }
7183 }
7184 }
7185 }
7186 }
7187 }
7188
7189finally:
7190 *r_verts_len = verts_len;
7191 if (verts_len != len_max) {
7192 verts = static_cast<BMLoop **>(MEM_realloc_uninitialized(verts, sizeof(*verts) * verts_len));
7193 }
7194 return verts;
7195}
7196
7198
7199/* -------------------------------------------------------------------- */
7202
7203void ED_uvedit_selectmode_clean(const Scene *scene, Object *obedit)
7204{
7205 const ToolSettings *ts = scene->toolsettings;
7208 char sticky = ts->uv_sticky;
7209
7211 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
7212 BMFace *efa;
7213 BMLoop *l;
7214 BMIter iter, liter;
7215
7216 if (ts->uv_selectmode == UV_SELECT_VERT) {
7217 /* Vertex mode. */
7218 if (sticky != UV_STICKY_DISABLE) {
7220 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
7221 if (!uvedit_face_visible_test(scene, efa)) {
7222 continue;
7223 }
7224 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
7225 if (uvedit_uv_select_test(scene, bm, l, offsets)) {
7227 }
7228 }
7229 }
7230 uv_select_flush_from_tag_loop(scene, obedit, true);
7231 }
7232 }
7233
7234 else if (ts->uv_selectmode == UV_SELECT_EDGE) {
7235 /* Edge mode. */
7236 if (sticky != UV_STICKY_DISABLE) {
7237 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
7238 if (!uvedit_face_visible_test(scene, efa)) {
7239 continue;
7240 }
7241 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
7242 if (uvedit_edge_select_test(scene, bm, l, offsets)) {
7243 uvedit_edge_select_set_noflush(scene, bm, l, true, sticky, offsets);
7244 }
7245 }
7246 }
7247 }
7249 }
7250
7251 else if (ts->uv_selectmode == UV_SELECT_FACE) {
7252 /* Face mode. */
7253 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
7255 if (uvedit_face_visible_test(scene, efa)) {
7256 if (uvedit_face_select_test(scene, bm, efa)) {
7258 }
7259 uvedit_face_select_set(scene, bm, efa, false);
7260 }
7261 }
7262 uv_select_flush_from_tag_face(scene, obedit, true);
7263 }
7264
7266}
7268{
7269 const Main *bmain = CTX_data_main(C);
7270 Scene *scene = CTX_data_scene(C);
7271 ToolSettings *ts = scene->toolsettings;
7272 ViewLayer *view_layer = CTX_data_view_layer(C);
7273 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
7274
7276 *bmain, scene, view_layer, nullptr);
7277 for (Object *obedit : objects) {
7278 ED_uvedit_selectmode_clean(scene, obedit);
7279
7280 uv_select_tag_update_for_object(depsgraph, ts, obedit);
7281 }
7282}
7283
7285{
7286 Scene *scene = CTX_data_scene(C);
7287 ToolSettings *ts = scene->toolsettings;
7288 if ((ts->uv_flag & UV_FLAG_SELECT_SYNC) == 0) {
7289 return;
7290 }
7291 /* Only for edge/face select modes. */
7292 if (ts->selectmode & SCE_SELECT_VERTEX) {
7293 return;
7294 }
7295
7296 const Main *bmain = CTX_data_main(C);
7297 ViewLayer *view_layer = CTX_data_view_layer(C);
7298 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
7300 *bmain, scene, view_layer, nullptr);
7301 for (Object *obedit : objects) {
7302 uv_select_tag_update_for_object(depsgraph, ts, obedit);
7303 }
7304}
7305
7310{
7311 const Scene *scene = CTX_data_scene(C);
7312 const ToolSettings *ts = scene->toolsettings;
7313 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
7314 return;
7315 }
7316
7317 const Main *bmain = CTX_data_main(C);
7318 ViewLayer *view_layer = CTX_data_view_layer(C);
7320 *bmain, scene, view_layer, nullptr);
7321 for (Object *obedit : objects) {
7322 uv_select_sync_update(scene, obedit);
7323 }
7324}
7325
7327{
7328 Scene *scene = CTX_data_scene(C);
7329 ToolSettings *ts = scene->toolsettings;
7330 const eTool_UvSelectMode new_uv_selectmode = eTool_UvSelectMode(RNA_enum_get(op->ptr, "type"));
7331
7332 /* Early exit if no change in current selection mode */
7333 if (new_uv_selectmode == ts->uv_selectmode) {
7334 return OPERATOR_CANCELLED;
7335 }
7336
7337 /* Set new UV select mode. */
7338 ts->uv_selectmode = new_uv_selectmode;
7339
7340 /* Handle UV selection states according to new select mode and sticky mode. */
7342
7345
7346 return OPERATOR_FINISHED;
7347}
7348
7350 wmOperator *op,
7351 const wmEvent * /*event*/)
7352{
7354 const SpaceImage *sima = CTX_wm_space_image(C);
7355
7356 /* Could be removed? - Already done in poll callback. */
7357 if ((!sima) || (sima->mode != SI_MODE_UV)) {
7358 return OPERATOR_CANCELLED;
7359 }
7360 /* Pass through when UV sync selection is enabled.
7361 * Allow for mesh select-mode key-map. */
7362 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
7363 return OPERATOR_PASS_THROUGH;
7364 }
7365
7366 return uv_select_mode_exec(C, op);
7367}
7368
7370{
7371 /* identifiers */
7372 ot->name = "UV Select Mode";
7373 ot->description = "Change UV selection mode";
7374 ot->idname = "UV_OT_select_mode";
7375
7376 /* API callbacks. */
7380
7381 /* flags */
7383
7384 /* RNA props */
7385 PropertyRNA *prop;
7386 ot->prop = prop = RNA_def_enum(
7387 ot->srna, "type", rna_enum_mesh_select_mode_uv_items, 0, "Type", "");
7389}
7390
7392{
7393 const Main *bmain = CTX_data_main(C);
7394 Scene *scene = CTX_data_scene(C);
7395 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
7396 ViewLayer *view_layer = CTX_data_view_layer(C);
7397 const ToolSettings *ts = scene->toolsettings;
7399 *bmain, scene, view_layer, nullptr);
7400
7401 int2 tile;
7402 RNA_int_get_array(op->ptr, "tile", tile);
7403 const rctf tile_rect = {
7404 /*xmin*/ float(tile.x),
7405 /*xmax*/ float(tile.x + 1),
7406 /*ymin*/ float(tile.y),
7407 /*ymax*/ float(tile.y + 1),
7408 };
7409 const bool extend = RNA_boolean_get(op->ptr, "extend");
7410
7411 for (Object *ob : objects) {
7413 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
7414
7415 bool changed = false;
7416 if (!extend) {
7418 changed = true;
7419 }
7420
7421 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
7423 }
7424 else {
7426 }
7427
7428 BMFace *f;
7429 BMIter iter;
7430 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
7431 if (!uvedit_face_visible_test(scene, f)) {
7432 continue;
7433 }
7434
7435 /* Center median does not work correctly for concave n-gons.
7436 * TODO: Tessellate UVs then check the center of each triangle with a non-zero area. */
7437 float2 center;
7438 BM_face_uv_calc_center_median(f, offsets.uv, center);
7439 if (BLI_rctf_isect_pt_v(&tile_rect, center)) {
7440 uvedit_face_select_set_with_sticky(scene, bm, f, true, offsets);
7441 changed = true;
7442 }
7443 }
7444 if (changed) {
7445 if (ts->uv_flag & UV_FLAG_SELECT_SYNC) {
7447 }
7448 else {
7450 }
7451 uv_select_tag_update_for_object(depsgraph, ts, ob);
7452 }
7453 }
7454
7455 /* Always return "finished" even if nothing changed because returning canceled
7456 * prevents the user changing values that *would* succeed in the "redo" panel. */
7457 return OPERATOR_FINISHED;
7458}
7459
7461 wmOperator *op,
7462 const wmEvent * /*event*/)
7463{
7464 PropertyRNA *prop_tile = RNA_struct_find_property(op->ptr, "tile");
7465 if (!RNA_property_is_set(op->ptr, prop_tile)) {
7466 if (const SpaceImage *sima = CTX_wm_space_image(C)) {
7467 const int2 tile = int2(int(sima->cursor[0]), int(sima->cursor[1]));
7468 RNA_property_int_set_array(op->ptr, prop_tile, tile);
7469 }
7470 }
7471 return uv_select_tile_exec(C, op);
7472}
7473
7475{
7476 /* identifiers */
7477 ot->name = "Select Tile";
7478 ot->description = "Select UVs in specified tile";
7479 ot->idname = "UV_OT_select_tile";
7480
7481 /* API callbacks. */
7485
7486 RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
7488 "tile",
7489 2,
7490 nullptr,
7491 std::numeric_limits<int>::min(),
7492 std::numeric_limits<int>::max(),
7493 "Tile",
7494 "Tile location to select UVs",
7495 std::numeric_limits<int>::min(),
7496 std::numeric_limits<int>::max());
7497
7498 /* flags */
7500}
7501
7514
7516{
7517 /* identifiers */
7518 ot->name = "Set User Region";
7519 ot->description = "Set the boundaries of the user region";
7520 ot->idname = "UV_OT_custom_region_set";
7521
7522 /* API callbacks. */
7528
7529 /* flags */
7531
7532 /* properties */
7534}
7535
7537
7538} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
General operations, lookup, etc. for materials.
#define ENUM_OPERATORS(_enum_type)
A min-heap / priority queue ADT.
A KD-tree for nearest neighbor search.
#define BLI_MEMARENA_STD_BUFSIZE
#define BLI_POLYFILL_ALLOC_NGON_RESERVE
#define BLT_I18NCONTEXT_ID_MESH
Object is a sort of wrapper for general info.
#define SEL_OP_USE_PRE_DESELECT(sel_op)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define V2D_IS_CLIPPED
Definition UI_view2d.hh:46
#define NC_GEOM
Definition WM_types.hh:406
#define NC_SCENE
Definition WM_types.hh:391
#define ND_TOOLSETTINGS
Definition WM_types.hh:468
#define ND_SPACE_IMAGE
Definition WM_types.hh:565
#define ND_SELECT
Definition WM_types.hh:551
#define NC_SPACE
Definition WM_types.hh:405
#define UNPACK2(a)
#define UNUSED_FUNCTION(x)
#define CLAMP_MAX(a, c)
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define UNPACK3(a)
#define ELEM(...)
#define BM_ELEM_CD_GET_BOOL(ele, offset)
#define BM_DISK_EDGE_NEXT(e, v)
#define BM_ELEM_SELECT_UV_EDGE
#define BM_FACE_FIRST_LOOP(p)
#define BM_ELEM_CD_GET_FLOAT_P(ele, offset)
#define BM_elem_index_get(ele)
#define BM_elem_flag_disable(ele, hflag)
#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_elem_flag_enable(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
#define BM_ITER_ELEM_INDEX(ele, iter, data, itype, indexvar)
#define BM_select_history_store_notest(bm, ele)
#define BM_select_history_store(bm, ele)
#define BM_select_history_remove(bm, ele)
#define MEM_realloc_uninitialized(vmemh, len)
bool is_empty() const
Definition BLI_array.hh:275
constexpr IndexRange()=default
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
int64_t size() const
Definition BLI_map.hh:976
ItemIterator items() const &
Definition BLI_map.hh:902
Value & lookup_or_add(const Key &key, const Value &value)
Definition BLI_map.hh:588
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
int64_t size() const
IndexRange index_range() const
void reinitialize(const int64_t new_size)
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
void vert_select_set(BMVert *v, bool value)
void face_select_set(BMFace *f, bool value)
void edge_select_set(BMEdge *f, bool value)
static std::unique_ptr< UVSyncSelectFromMesh > create_if_needed(const ToolSettings &ts, BMesh &bm)
#define FLT_MAX
#define shared
float3x3 scale(float3x3 mat, float2 scale)
const int state
const ccl_global KernelWorkTile * tile
void view2d_view_to_region_fl(const View2D *v2d, float x, float y, float *r_region_x, float *r_region_y) ATTR_NONNULL()
Definition view2d.cc:1720
bool view2d_view_to_region_segment_clip(const View2D *v2d, const float xy_a[2], const float xy_b[2], int r_region_a[2], int r_region_b[2]) ATTR_NONNULL()
Definition view2d.cc:1732
float view2d_scale_get_y(const View2D *v2d)
Definition view2d.cc:1906
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
bool view2d_view_to_region_clip(const View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL()
Definition view2d.cc:1684
float view2d_scale_get_x(const View2D *v2d)
Definition view2d.cc:1902
void view2d_region_to_view_rctf(const View2D *v2d, const rctf *rect_src, rctf *rect_dst) ATTR_NONNULL()
Definition view2d.cc:1657
void view2d_scale_get(const View2D *v2d, float *r_x, float *r_y)
Definition view2d.cc:1893
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
void EDBM_flag_disable_all(BMesh *bm, char hflag)
bool BM_loop_edge_uvselect_test(const BMLoop *l)
static bool uvedit_select_pin_ok_or_report(const Scene *scene, ReportList *reports)
UserDef U
Definition blender.cc:58
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
bool uv_find_nearest_vert(Scene *scene, Object *obedit, const float co[2], float penalty_dist, UvNearestHit *hit)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static bool uv_mouse_select(bContext *C, const float co[2], const SelectPick_Params &params)
static wmOperatorStatus uv_select_mode_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus uv_select_split_exec(bContext *C, wmOperator *op)
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
std::string ED_select_circle_get_name(wmOperatorType *ot, PointerRNA *ptr)
BVHTreeOverlap * BLI_bvhtree_overlap_ex(const BVHTree *tree1, const BVHTree *tree2, uint *r_overlap_num, BVHTree_OverlapCallback callback, void *userdata, uint max_interactions, int flag)
void kdtree_balance(KDTree< CoordT > *tree)
void ED_uvedit_sync_uvselect_ensure_if_needed(const ToolSettings *ts, BMesh *bm)
bool BM_uv_map_attr_pin_exists(const BMesh *bm, const StringRef uv_map_name)
void BM_loop_edge_uvselect_set_shared(BMesh *bm, BMLoop *l, bool select, const int cd_loop_uv_offset)
static wmOperatorStatus uv_select_by_winding_exec(bContext *C, wmOperator *op)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
bool uvedit_face_select_test_ex(const ToolSettings *ts, const BMesh *bm, const BMFace *efa)
static bool uv_island_selected(const Scene *scene, const BMesh *bm, FaceIsland *island)
void mid_v2_v2v2v2(float v[2], const float v1[2], const float v2[2], const float v3[2])
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
void ED_uvedit_sticky_selectmode_update(bContext *C)
bool ED_operator_uvedit(bContext *C)
@ UV_EDGE_LOOP_BOUNDARY_LOOP
@ UV_EDGE_LOOP_BOUNDARY_ALL
static void uv_select_edgeloop_double_side_tag(const Scene *scene, BMesh *bm, BMLoop *l_init_pair[2], const BMUVOffsets &offsets)
static wmOperatorStatus uv_select_edge_ring_exec(bContext *C, wmOperator *op)
Heap * BLI_heap_new_ex(unsigned int reserve_num) ATTR_WARN_UNUSED_RESULT
Definition BLI_heap.cc:173
void WM_operator_properties_gesture_circle(wmOperatorType *ot)
static wmOperatorStatus uv_mouse_select_loop_generic_multi(bContext *C, const Span< Object * > objects, const float co[2], const bool extend, enum eUVLoopGenericType loop_type)
void UV_OT_custom_region_set(wmOperatorType *ot)
int RNA_enum_get(PointerRNA *ptr, const char *name)
BMLoop * ED_uvedit_active_edge_loop_get(const ToolSettings *ts, BMesh *bm)
bool uv_find_nearest_face_multi_ex(Scene *scene, Span< Object * > objects, const float co[2], UvNearestHit *hit, bool only_in_face)
bool BM_edge_in_face(const BMEdge *e, const BMFace *f)
bool uvedit_edge_select_test(const Scene *scene, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
static wmOperatorStatus uv_lasso_select_exec(bContext *C, wmOperator *op)
bool BM_mesh_uvselect_clear(BMesh *bm)
int bm_mesh_calc_uv_islands(const Scene *scene, BMesh *bm, ListBaseT< FaceIsland > *island_list, const bool only_selected_faces, const bool only_selected_uvs, const bool use_seams, const float aspect_y, const BMUVOffsets &offsets)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void EDBM_selectmode_flush(BMesh *bm, short selectmode)
void EDBM_select_more(BMesh *bm, short selectmode, bool use_face_step)
static wmOperatorStatus uv_select_linked_exec(bContext *C, wmOperator *op)
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
bool uvedit_vert_select_get_no_sync(const ToolSettings *ts, const BMesh *bm, const BMLoop *l)
static bool UNUSED_FUNCTION bm_loop_select_vert_check_internal(const Scene *scene, BMesh *bm, BMLoop *l)
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2])
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
static wmOperatorStatus uv_select_tile_invoke(bContext *C, wmOperator *op, const wmEvent *)
void BM_loop_edge_uvselect_set_noflush(BMesh *bm, BMLoop *l, bool select)
void UV_OT_select_linked(wmOperatorType *ot)
wmOperatorStatus WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus WM_operator_flag_only_pass_through_on_press(wmOperatorStatus retval, const wmEvent *event)
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static bool uv_select_linked_delimit_check(const BMFace *f_src, const BMLoop *l_vert_step, const BMFace *f_dst, const UVDelimitMode delimit_mode)
eSelectOp ED_select_op_modal(eSelectOp sel_op, bool is_first)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
static BMLoop * uvedit_loop_find_other_radial_loop_with_visible_face(const Scene *scene, BMLoop *l_src, const BMUVOffsets &offsets)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
static wmOperatorStatus uv_select_tile_exec(bContext *C, wmOperator *op)
void uv_nearest_hit_elem_set_from_face(const float co[2], UvNearestHit *hit, short uv_selectmode)
void ED_uvedit_selectmode_clean_multi(bContext *C)
static BMLoop * bm_select_edgeloop_single_side_next(const Scene *scene, BMLoop *l_step, BMVert *v_from, const BMUVOffsets &offsets)
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
bool uvedit_face_visible_test(const Scene *scene, const BMFace *efa)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
void ED_uvedit_select_sync_multi(bContext *C)
MINLINE void copy_v2_v2(float r[2], const float a[2])
void ED_uvedit_active_edge_loop_set(BMesh *bm, BMLoop *l)
Material * BKE_object_material_get(Object *ob, short act)
void uvedit_select_prepare_custom_data(const Scene *scene, BMesh *bm)
float BM_face_calc_area_uv(const BMFace *f, int cd_loop_uv_offset)
void BLI_bvhtree_free(BVHTree *tree)
void WM_gesture_lasso_cancel(bContext *C, wmOperator *op)
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 uvedit_face_select_disable(const Scene *scene, BMesh *bm, BMFace *efa)
void uvedit_vert_select_set_no_sync(const ToolSettings *ts, const BMesh *bm, BMLoop *l, bool select)
bool uvedit_select_is_any_selected_multi(const Scene *scene, Span< Object * > objects)
void ED_uvedit_selectmode_flush(const Scene *scene, BMesh *bm)
UV Select Mode Flush.
void uvedit_uv_select_set_with_sticky(const Scene *scene, BMesh *bm, BMLoop *l, bool select, const BMUVOffsets &offsets)
static const EnumPropertyItem * uv_select_similar_type_itemf(bContext *C, PointerRNA *, PropertyRNA *, bool *r_free)
void uvedit_loop_vert_select_set(const ToolSettings *ts, const BMesh *bm, BMLoop *l, const bool select)
void ED_space_image_get_size(SpaceImage *sima, int *r_width, int *r_height)
static float get_uv_face_needle(const eUVSelectSimilar type, BMFace *face, const int ob_index, const float ob_m3[3][3], const BMUVOffsets &offsets, const Span< int > material_remap)
static const EnumPropertyItem prop_similar_compare_types[]
int isect_seg_seg_v2_point_ex(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float endpoint_bias, float r_vi[2])
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void BLI_bvhtree_balance(BVHTree *tree)
bool uvedit_edge_is_face_select_any_other(const ToolSettings *ts, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
void UV_OT_select_similar(wmOperatorType *ot)
BMLoop * BM_face_edge_share_loop(BMFace *f, BMEdge *e)
Return the Loop Shared by Face and Edge.
void UV_OT_select_linked_pick(wmOperatorType *ot)
static wmOperatorStatus uv_circle_select_exec(bContext *C, wmOperator *op)
void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp) ATTR_NONNULL(1)
Definition BLI_heap.cc:193
bool uvedit_face_visible_test_ex(const ToolSettings *ts, const BMFace *efa)
bool BM_loop_edge_uvselect_check_other_face(BMLoop *l, const char hflag, const int cd_loop_uv_offset)
int RNA_int_get(PointerRNA *ptr, const char *name)
const float * uvedit_first_selected_uv_from_vertex(Scene *scene, const BMesh *bm, BMVert *eve, const BMUVOffsets &offsets)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
bool BM_face_uv_point_inside_test(const BMFace *f, const float co[2], const int cd_loop_uv_offset)
void BM_mesh_elem_hflag_disable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
static bool uv_circle_select_is_edge_inside(const float uv_a[2], const float uv_b[2], const float offset[2], const float ellipse[2])
static wmOperatorStatus uv_mouse_select_loop_generic(bContext *C, const float co[2], const bool extend, enum eUVLoopGenericType loop_type)
static wmOperatorStatus uv_select_more_less(bContext *C, const bool select)
void BLI_polyfill_calc_arena(const float(*coords)[2], unsigned int coords_num, int coords_sign, unsigned int(*r_tris)[3], struct MemArena *arena)
ATTR_WARN_UNUSED_RESULT const BMVert * v
bool uv_find_nearest_edge_multi(Scene *scene, Span< Object * > objects, const float co[2], float penalty, UvNearestHit *hit)
wmOperatorStatus WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void uv_select_tag_update_for_object(Depsgraph *depsgraph, const ToolSettings *ts, Object *obedit)
BMLoop * ED_uvedit_active_vert_loop_get(const ToolSettings *ts, BMesh *bm)
int isect_point_tri_v2(const float pt[2], const float v1[2], const float v2[2], const float v3[2])
static wmOperatorStatus uv_select_similar_exec(bContext *C, wmOperator *op)
static float get_uv_vert_needle(const eUVSelectSimilar type, BMVert *vert, const float ob_m3[3][3], BMLoop *loop, const BMUVOffsets &offsets)
bool BLI_lasso_is_point_inside(Span< int2 > mcoords, int sx, int sy, int error_value)
Definition lasso_2d.cc:42
BMLoop * uv_find_nearest_loop_from_vert(Scene *scene, Object *obedit, BMVert *v, const float co[2])
void WM_gesture_circle_cancel(bContext *C, wmOperator *op)
void UV_OT_select_by_winding(wmOperatorType *ot)
void BM_mesh_uvselect_flush_from_faces_only_deselect(BMesh *bm)
void uvedit_face_select_set_with_sticky(const Scene *scene, BMesh *bm, BMFace *efa, bool select, const BMUVOffsets &offsets)
void BM_mesh_select_mode_flush(BMesh *bm)
bool BLI_bvhtree_update_node(BVHTree *tree, int index, const float co[3], const float co_moving[3], int numpoints)
bool ED_uvedit_sync_uvselect_is_valid_or_ignore(const ToolSettings *ts, const BMesh *bm)
static bool uv_mouse_select_multi(bContext *C, const Span< Object * > objects, const float co[2], const SelectPick_Params &params)
static wmOperatorStatus uv_select_mode_exec(bContext *C, wmOperator *op)
BLI_INLINE bool BM_vert_in_edge(const BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
BLI_INLINE BMVert * BM_edge_other_vert(BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void uvedit_select_prepare(const Scene *scene, BMesh *bm)
void BM_mesh_uvselect_flush_from_loop_verts_only_deselect(BMesh *bm)
ViewLayer * CTX_data_view_layer(const bContext *C)
static void uv_select_edgeloop_single_side_tag(const Scene *scene, BMesh *bm, BMLoop *l_init, const BMUVOffsets &offsets, enum eUVEdgeLoopBoundaryMode boundary_mode, int r_count_by_select[2])
void WM_operator_properties_select_all(wmOperatorType *ot)
bool BM_loop_uv_share_vert_check(const BMLoop *l_a, const BMLoop *l_b, const int cd_loop_uv_offset)
static wmOperatorStatus uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent *event, bool pick)
void uvedit_edge_select_disable(const Scene *scene, BMesh *bm, BMLoop *l)
MINLINE void mul_v2_v2(float r[2], const float a[2])
static void uv_select_toggle_all(const Scene *scene, BMesh *bm)
static void uvedit_sync_uvselect_flush_from_v3d(const ToolSettings *ts, BMesh *bm)
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
Definition math_geom.cc:307
void uvedit_edge_select_set(const Scene *scene, BMesh *bm, BMLoop *l, bool select)
Select UV Edge.
bool uvedit_uv_select_test(const Scene *scene, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
bool uv_find_nearest_vert_multi(Scene *scene, Span< Object * > objects, const float co[2], float penalty_dist, UvNearestHit *hit)
KDTree< CoordT > * kdtree_new(uint nodes_len_capacity)
Definition BLI_kdtree.hh:65
static bool uvedit_nearest_uv(const Scene *scene, Object *obedit, const float co[2], const float scale[2], const bool ignore_selected, float *dist_sq, float r_uv[2])
void WM_operator_properties_border_to_rctf(wmOperator *op, rctf *r_rect)
static void uv_select_flush_from_tag_loop(const Scene *scene, Object *obedit, const bool select)
BMFace ** ED_uvedit_selected_faces(const Scene *scene, BMesh *bm, int len_max, int *r_faces_len)
void BLI_bvhtree_update_tree(BVHTree *tree)
void uvedit_face_select_shared_vert(const Scene *scene, BMesh *bm, BMFace *efa, const bool select, const BMUVOffsets &offsets)
static wmOperatorStatus uv_select_loop_exec(bContext *C, wmOperator *op)
static void uvedit_vertex_select_tagged(BMesh *bm, const Scene *scene, bool select)
bool uv_find_nearest_edge(Scene *scene, Object *obedit, const float co[2], float penalty, UvNearestHit *hit)
void UV_OT_select_circle(wmOperatorType *ot)
UvNearestHit uv_nearest_hit_init_dist_px(const View2D *v2d, float dist_px)
void uvedit_edge_select_set_no_sync(const ToolSettings *ts, const BMesh *bm, BMLoop *l, bool select)
bool BM_loop_vert_uvselect_check_other_face(BMLoop *l, const char hflag, const int cd_loop_uv_offset)
void uvedit_uv_select_enable(const Scene *scene, BMesh *bm, BMLoop *l)
void BM_mesh_uvselect_mode_flush_update(BMesh *bm, const short selectmode_old, const short selectmode_new, const int cd_loop_uv_offset)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void uvedit_uv_select_disable(const Scene *scene, BMesh *bm, BMLoop *l)
bool ED_select_similar_compare_float_tree(const KDTree< float > *tree, float length, float thresh, eSimilarCmp compare)
static wmOperatorStatus uv_select_edge_ring_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool uvedit_select_is_any_selected(const Scene *scene, BMesh *bm)
void ED_uvedit_select_sync_flush(const ToolSettings *ts, BMesh *bm, bool select)
void uvedit_uv_select_shared_vert(const Scene *scene, BMesh *bm, BMLoop *l, const bool select, const int sticky_flag, const BMUVOffsets &offsets)
void ED_uvedit_selectmode_clean(const Scene *scene, Object *obedit)
UV Select Mode set.
void UV_OT_select_mode(wmOperatorType *ot)
char ED_uvedit_select_mode_get(const Scene *scene)
void UV_OT_select_loop(wmOperatorType *ot)
void BM_uv_vert_map_free(UvVertMap *vmap)
void UV_OT_select(wmOperatorType *ot)
void BM_mesh_uvselect_sync_from_mesh_sticky_disabled(BMesh *bm)
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
MINLINE int signum_i(float a)
BMLoop * uv_find_nearest_loop_from_edge(Scene *scene, Object *obedit, BMEdge *e, const float co[2])
BMesh const char void * data
static wmOperatorStatus uv_select_less_exec(bContext *C, wmOperator *)
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
void BM_loop_vert_uvselect_set_noflush(BMesh *bm, BMLoop *l, bool select)
void BKE_mesh_batch_cache_dirty_tag(Mesh *mesh, eMeshBatchDirtyMode mode)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
bool uv_find_nearest_face_ex(Scene *scene, Object *obedit, const float co[2], UvNearestHit *hit, bool only_in_face)
static BMLoop * bm_select_edgeloop_double_side_next(const Scene *scene, BMLoop *l_step, BMVert *v_from, const BMUVOffsets &offsets)
static bool uv_nearest_between(const BMLoop *l, const float co[2], const int cd_loop_uv_offset)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
void BLI_memarena_clear(MemArena *ma) ATTR_NONNULL(1)
void BM_mesh_uvselect_sync_from_mesh_sticky_location(BMesh *bm, const int cd_loop_uv_offset)
static wmOperatorStatus uv_select_similar_vert_exec(bContext *C, wmOperator *op)
void kdtree_insert(KDTree< CoordT > *tree, int index, const CoordT &co)
Definition BLI_kdtree.hh:96
bool uvedit_vert_is_face_select_any_other(const ToolSettings *ts, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
void BM_face_select_set(BMesh *bm, BMFace *f, const bool select)
Select Face.
void UV_OT_select_box(wmOperatorType *ot)
void BM_face_uv_calc_center_median(const BMFace *f, const int cd_loop_uv_offset, float r_cent[2])
bool uvedit_face_select_test(const Scene *scene, const BMesh *bm, const BMFace *efa)
BVHTree * BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis)
wmOperatorStatus WM_gesture_circle_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static float get_uv_island_needle(const eUVSelectSimilar type, const FaceIsland *island, const float ob_m3[3][3], const BMUVOffsets &offsets)
bool uvedit_vert_is_all_other_faces_selected(const ToolSettings *ts, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
static bool uv_circle_select_is_point_inside(const float uv[2], const float offset[2], const float ellipse[2])
void WM_operator_properties_mouse_select(wmOperatorType *ot)
UvNearestHit uv_nearest_hit_init_max(const View2D *v2d)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void ED_uvedit_deselect_all(const Scene *scene, Object *obedit, int action)
bool ED_uvedit_select_island_check(const ToolSettings *ts)
static BMLoop * uvedit_loop_find_other_boundary_loop_with_visible_face(const Scene *scene, BMLoop *l_edge, BMVert *v_pivot, const BMUVOffsets &offsets)
static bool do_lasso_select_mesh_uv_is_point_inside(const ARegion *region, const rcti *clip_rect, const Span< int2 > mcoords, const float co_test[2])
bool uvedit_vert_is_edge_select_any_other(const ToolSettings *ts, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
bool uv_find_nearest_face(Scene *scene, Object *obedit, const float co[2], UvNearestHit *hit)
void uvedit_face_select_set_no_sync(const ToolSettings *ts, const BMesh *bm, BMFace *f, bool select)
void uvedit_face_select_set(const Scene *scene, BMesh *bm, BMFace *efa, bool select)
Select UV Face.
static int uv_select_faceloop(Scene *scene, Object *obedit, UvNearestHit *hit, const bool extend)
static wmOperatorStatus uv_select_all_exec(bContext *C, wmOperator *op)
void WM_operator_properties_gesture_box(wmOperatorType *ot)
static wmOperatorStatus uv_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_enum_items_add_value(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item, int value)
void BM_mesh_uvselect_flush_from_faces_only_select(BMesh *bm)
static wmOperatorStatus uv_select_overlap_exec(bContext *C, wmOperator *op)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
ToolSettings * CTX_data_tool_settings(const bContext *C)
void BM_mesh_uvselect_flush_from_loop_edges(BMesh *bm, bool flush_down)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static bool do_lasso_select_mesh_uv_is_edge_inside(const ARegion *region, const rcti *clip_rect, const Span< int2 > mcoords, const float co_test_a[2], const float co_test_b[2])
bool uvedit_loop_vert_select_get(const ToolSettings *ts, const BMesh *bm, const BMLoop *l)
void UV_OT_select_overlap(wmOperatorType *ot)
bool ED_uvedit_sync_uvselect_ignore(const ToolSettings *ts)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bool ED_operator_uvedit_space_image(bContext *C)
void uvedit_loop_edge_select_set(const ToolSettings *ts, const BMesh *bm, BMLoop *l, const bool select)
void BM_vert_select_set(BMesh *bm, BMVert *v, const bool select)
Select Vert.
static EnumPropertyItem uv_select_similar_type_items[]
bool uvedit_edge_select_get_no_sync(const ToolSettings *ts, const BMesh *bm, const BMLoop *l)
float BM_face_calc_area_uv_signed(const BMFace *f, int cd_loop_uv_offset)
void BM_mesh_uvselect_flush_from_loop_verts_only_select(BMesh *bm)
void UV_OT_select_edge_ring(wmOperatorType *ot)
void uvedit_edge_select_set_with_sticky(const Scene *scene, BMesh *bm, BMLoop *l, bool select, const BMUVOffsets &offsets)
static wmOperatorStatus uv_select_similar_island_exec(bContext *C, wmOperator *op)
void EDBM_flag_enable_all(BMesh *bm, char hflag)
void BM_face_uvselect_set_noflush(BMesh *bm, BMFace *f, bool select)
void BM_select_history_validate(BMesh *bm)
void UV_OT_select_pinned(wmOperatorType *ot)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void UV_OT_select_tile(wmOperatorType *ot)
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:59
static int uv_select_edgeloop(Scene *scene, Object *obedit, UvNearestHit *hit, const bool extend)
static wmOperatorStatus uv_select_similar_edge_exec(bContext *C, wmOperator *op)
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
void BM_loop_vert_uvselect_set_shared(BMesh *bm, BMLoop *l, bool select, const int cd_loop_uv_offset)
SpaceImage * CTX_wm_space_image(const bContext *C)
void UV_OT_select_more(wmOperatorType *ot)
MINLINE float len_squared_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
void kdtree_free(KDTree< CoordT > *tree)
Definition BLI_kdtree.hh:84
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
static bool overlap_tri_tri_uv_test(const float t1[3][2], const float t2[3][2], const float endpoint_bias)
static void uv_select_all_perform_multi(const Scene *scene, Span< Object * > objects, int action)
void uvedit_edge_select_shared_vert(const Scene *scene, BMesh *bm, BMLoop *l, const bool select, const int sticky_flag, const BMUVOffsets &offsets)
bool BLI_rcti_isect_segment(const struct rcti *rect, const int s1[2], const int s2[2])
void EDBM_select_swap(BMEditMesh *em, BMesh *bm)
void UV_OT_select_all(wmOperatorType *ot)
void uvedit_edge_select_set_noflush(const Scene *scene, BMesh *bm, BMLoop *l, const bool select, const int sticky_flag, const BMUVOffsets &offsets)
Main * CTX_data_main(const bContext *C)
static void uv_select_invert(const Scene *scene, BMEditMesh *em, BMesh *bm)
void uvedit_uv_select_set(const Scene *scene, BMesh *bm, BMLoop *l, bool select)
Select UV Vertex.
wmOperatorStatus WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
UvNearestHit uv_nearest_hit_init_max_default()
static void bm_loop_tags_clear(BMesh *bm)
static void uv_select_flush_from_loop_edge_flag(const Scene *scene, BMesh *bm)
static void uv_select_linked_multi(const Scene *scene, const Span< Object * > objects, UvNearestHit *hit, const bool extend, bool deselect, const bool toggle, const bool select_faces, const UVDelimitMode delimit_mode, const char hflag)
static void uv_select_all(const Scene *scene, BMesh *bm, bool select_all)
void BM_mesh_uvselect_mode_flush(BMesh *bm)
static bool do_lasso_select_mesh_uv(bContext *C, const Span< int2 > mcoords, const eSelectOp sel_op)
void uvedit_edge_select_enable(const Scene *scene, BMesh *bm, BMLoop *l)
static wmOperatorStatus uv_select_overlap(bContext *C, const bool extend, const bool select_island)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
UvMapVert * BM_uv_vert_map_at_index(UvVertMap *vmap, unsigned int v)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
Array< int2 > WM_gesture_lasso_path_to_array(bContext *, wmOperator *op)
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints)
void uvedit_face_select_enable(const Scene *scene, BMesh *bm, BMFace *efa)
MINLINE float square_f(float a)
const EnumPropertyItem rna_enum_mesh_select_mode_uv_items[]
Definition rna_scene.cc:142
PropertyRNA * RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
int CustomData_get_active_layer(const CustomData *data, eCustomDataType type)
PropertyRNA * RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2]) ATTR_WARN_UNUSED_RESULT
static wmOperatorStatus uv_select_exec(bContext *C, wmOperator *op)
void ED_space_image_get_zoom(SpaceImage *sima, const ARegion *region, float *r_zoomx, float *r_zoomy)
void BM_mesh_uvselect_sync_from_mesh_sticky_vert(BMesh *bm)
void BM_select_history_clear(BMesh *bm)
void WM_operator_properties_select_operation_simple(wmOperatorType *ot)
bool BM_loop_uv_share_edge_check(const BMLoop *l_a, const BMLoop *l_b, const int cd_loop_uv_offset)
bool EDBM_uvselect_clear(BMesh *bm)
static float get_uv_edge_needle(const eUVSelectSimilar type, BMEdge *edge, const float ob_m3[3][3], BMLoop *loop_a, BMLoop *loop_b, const BMUVOffsets &offsets)
BMLoop * BM_face_vert_share_loop(BMFace *f, BMVert *v)
Return the Loop Shared by Face and Vertex.
Scene * CTX_data_scene(const bContext *C)
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
static wmOperatorStatus uv_select_more_exec(bContext *C, wmOperator *)
MINLINE void sub_v2_v2(float r[2], const float a[2])
MINLINE void mul_v2_v2v2(float r[2], const float a[2], const float b[2])
bool uvedit_edge_select_test_ex(const ToolSettings *ts, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_DEPENDS_ON_CURSOR
Definition WM_types.hh:228
UvVertMap * BM_uv_vert_map_create(BMesh *bm, bool use_select, bool respect_hide)
static wmOperatorStatus uv_box_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void BM_mesh_select_flush_from_verts(BMesh *bm, const bool select)
BLI_INLINE BMFace * BM_face_at_index(BMesh *bm, const int index)
static void uv_select_sync_update(const Scene *scene, Object *obedit)
BMUVOffsets BM_uv_map_offsets_get(const BMesh *bm)
static wmOperatorStatus uv_select_loop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool uvedit_uv_select_test_ex(const ToolSettings *ts, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
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)
bool WM_gesture_is_modal_first(const wmGesture *gesture)
BMLoop ** ED_uvedit_selected_verts(const Scene *scene, BMesh *bm, int len_max, int *r_verts_len)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
SelectPick_Params ED_select_pick_params_from_operator(PointerRNA *ptr) ATTR_NONNULL(1)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void uvedit_select_prepare_sync_select(const Scene *scene, BMesh *bm)
static bool bm_loop_select_edge_check_internal(const Scene *scene, BMesh *bm, BMLoop *l)
static const EnumPropertyItem uv_delimit_mode_items[]
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
@ BKE_MESH_BATCH_DIRTY_UVEDIT_SELECT
Definition BKE_mesh.h:53
bool BLI_lasso_is_edge_inside(Span< int2 > mcoords, int x0, int y0, int x1, int y1, int error_value)
Definition lasso_2d.cc:56
wmOperatorStatus WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
void uvedit_select_flush_from_verts(const Scene *scene, BMesh *bm, bool select)
void BM_mesh_uvselect_set_elem_from_mesh(BMesh *bm, const bool select, const BMUVSelectPickParams &params, const VectorList< BMVert * > &verts, const VectorList< BMEdge * > &edges, const VectorList< BMFace * > &faces)
float closest_to_line_segment_v2(float r_close[2], const float p[2], const float l1[2], const float l2[2])
Definition math_geom.cc:381
void UV_OT_select_lasso(wmOperatorType *ot)
void BM_face_uvselect_set(BMesh *bm, BMFace *f, bool select)
static void bm_clear_uv_vert_selection(const Scene *scene, BMesh *bm)
static void uv_select_flush_from_tag_face(const Scene *scene, Object *obedit, const bool select)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
static wmOperatorStatus uv_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
@ BM_ELEM_SELECT_UV
std::string ED_select_pick_get_name(wmOperatorType *ot, PointerRNA *ptr)
ARegion * CTX_wm_region(const bContext *C)
bool uvedit_loop_edge_select_get(const ToolSettings *ts, const BMesh *bm, const BMLoop *l)
static wmOperatorStatus uv_select_pinned_exec(bContext *C, wmOperator *op)
bool BLI_rctf_isect_segment(const struct rctf *rect, const float s1[2], const float s2[2])
void UV_OT_select_split(wmOperatorType *ot)
void BLI_lasso_boundbox(rcti *rect, Span< int2 > mcoords)
Definition lasso_2d.cc:21
void BLI_heap_clear(Heap *heap, HeapFreeFP ptrfreefp) ATTR_NONNULL(1)
Definition BLI_heap.cc:215
void BM_loop_edge_uvselect_set(BMesh *bm, BMLoop *l, bool select)
float RNA_float_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus uv_box_select_exec(bContext *C, wmOperator *op)
static wmOperatorStatus uv_select_similar_face_exec(bContext *C, wmOperator *op)
void BM_mesh_uvselect_flush_shared_only_select(BMesh *bm, const int cd_loop_uv_offset)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
static void uv_circle_select_state_free(void *data)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static int uv_select_edgering(Scene *scene, Object *obedit, UvNearestHit *hit, const bool extend)
bool uvedit_face_select_get_no_sync(const ToolSettings *ts, const BMesh *bm, const BMFace *f)
void BM_mesh_uvselect_sync_to_mesh(BMesh *bm)
bool ED_uvedit_nearest_uv_multi(const View2D *v2d, const Scene *scene, Span< Object * > objects, const float mval_fl[2], const bool ignore_selected, float *dist_sq, float r_uv[2])
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
void BLI_polyfill_beautify(const float(*coords)[2], unsigned int coords_num, unsigned int(*tris)[3], struct MemArena *arena, struct Heap *eheap)
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
float BM_face_calc_area_with_mat3(const BMFace *f, const float mat3[3][3])
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void uv_select_all_perform_multi_ex(const Scene *scene, Span< Object * > objects, int action, const Object *ob_exclude)
void EDBM_select_less(BMesh *bm, short selectmode, bool use_face_step)
void WM_operator_properties_gesture_lasso(wmOperatorType *ot)
void UV_OT_select_less(wmOperatorType *ot)
static wmOperatorStatus uv_select_linked_pick_exec(bContext *C, wmOperator *op)
static wmOperatorStatus uv_custom_region_set_exec(bContext *C, wmOperator *op)
void BM_edge_select_set(BMesh *bm, BMEdge *e, const bool select)
Select Edge.
#define sqrtf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct BMLoop * l
struct BMEditSelection * prev
struct BMLoop * next
struct BMLoop * prev
struct BMEdge * e
struct BMVert * v
struct BMLoop * radial_next
struct BMFace * f
CustomData ldata
BMFace ** ftable
bool uv_select_sync_valid
struct ToolSettings * toolsettings
eSpaceImage_Mode mode
eTool_UvSelectMode uv_selectmode
UVCircleSelectState(const Scene *scene, Vector< Object * > objects, const bool use_select_linked)
std::optional< Array< UVSelectLinkedHelper > > linked_helpers
bool face_check(BMFace *efa) const
void init(const Scene *scene, BMesh *bm)
void select_all(const bool select)
UVSelectLinkedHelper(const Scene *scene, BMesh *bm)
struct BMLoop * radial_next
ListBaseT< BMEditSelection > selected
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
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
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
std::string(*) get_name(wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1191
struct ReportList * reports
#define SET_SELECTION(value)
#define NEIGHBORING_FACE_IS_SEL
#define CURR_FACE_IS_UNSEL