Blender V5.3
bmesh_uvselect.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "MEM_guardedalloc.h"
10
11#include "DNA_scene_types.h"
12
13#include "BLI_listbase.hh"
14#include "BLI_math_bits.hh"
15
16#include "bmesh.hh"
17#include "bmesh_structure.hh"
18
19namespace blender {
20
21/* -------------------------------------------------------------------- */
24
26{
27 /* In practically all cases it's best to check #BM_ELEM_HIDDEN
28 * In this case the intent is to re-generate the selection, so clear all. */
29 BMIter iter;
30 BMFace *f;
31 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
32 BMLoop *l_iter, *l_first;
33 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
34 do {
36 } while ((l_iter = l_iter->next) != l_first);
38 }
39}
40
42
43/* -------------------------------------------------------------------- */
46
56
61
63
64/* -------------------------------------------------------------------- */
67
69 const char hflag,
70 const int cd_loop_uv_offset)
71{
73 BMVert *v = l->v;
74 BLI_assert(v->e);
75 const BMEdge *e_iter, *e_first;
76 e_iter = e_first = v->e;
77 do {
78 if (e_iter->l == nullptr) {
79 continue;
80 }
81 BMLoop *l_first = e_iter->l;
82 BMLoop *l_iter = l_first;
83 do {
84 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
85 continue;
86 }
87 if (l_iter->v != v) {
88 continue;
89 }
90 if (l_iter != l) {
91 if (BM_elem_flag_test(l_iter, hflag)) {
92 if (BM_loop_uv_share_vert_check(l, l_iter, cd_loop_uv_offset)) {
93 return true;
94 }
95 }
96 }
97 } while ((l_iter = l_iter->radial_next) != l_first);
98 } while ((e_iter = bmesh_disk_edge_next(e_iter, v)) != e_first);
99 return false;
100}
101
103 const char hflag,
104 const int cd_loop_uv_offset)
105{
107 BMVert *v = l->v;
108 BLI_assert(v->e);
109 const BMEdge *e_iter, *e_first;
110 e_iter = e_first = v->e;
111 do {
112 if (e_iter->l == nullptr) {
113 continue;
114 }
115 BMLoop *l_first = e_iter->l;
116 BMLoop *l_iter = l_first;
117 do {
118 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
119 continue;
120 }
121 if (l_iter->v != v) {
122 continue;
123 }
124 /* Connected to a selected edge. */
125 if (l_iter != l) {
126 if (BM_elem_flag_test(l_iter, hflag) || BM_elem_flag_test(l_iter->prev, hflag)) {
127 if (BM_loop_uv_share_vert_check(l, l_iter, cd_loop_uv_offset)) {
128 return true;
129 }
130 }
131 }
132 } while ((l_iter = l_iter->radial_next) != l_first);
133 } while ((e_iter = bmesh_disk_edge_next(e_iter, v)) != e_first);
134 return false;
135}
136
138 const char hflag,
139 const int cd_loop_uv_offset)
140{
142 BMVert *v = l->v;
143 BLI_assert(v->e);
144 const BMEdge *e_iter, *e_first;
145 e_iter = e_first = v->e;
146 do {
147 if (e_iter->l == nullptr) {
148 continue;
149 }
150 BMLoop *l_first = e_iter->l;
151 BMLoop *l_iter = l_first;
152 do {
153 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
154 continue;
155 }
156 if (l_iter->v != v) {
157 continue;
158 }
159 /* Connected to a selected edge. */
160 if (l_iter != l) {
161 if (((!BM_elem_flag_test(l_iter->e, BM_ELEM_HIDDEN)) &&
162 BM_elem_flag_test(l_iter->e, hflag)) ||
163 ((!BM_elem_flag_test(l_iter->prev->e, BM_ELEM_HIDDEN)) &&
164 BM_elem_flag_test(l_iter->prev->e, hflag)))
165 {
166 if (BM_loop_uv_share_vert_check(l, l_iter, cd_loop_uv_offset)) {
167 return true;
168 }
169 }
170 }
171 } while ((l_iter = l_iter->radial_next) != l_first);
172 } while ((e_iter = bmesh_disk_edge_next(e_iter, v)) != e_first);
173 return false;
174}
175
177 const char hflag,
178 const int cd_loop_uv_offset)
179{
181 BMVert *v = l->v;
182 BLI_assert(v->e);
183 const BMEdge *e_iter, *e_first;
184 e_iter = e_first = v->e;
185 do {
186 if (e_iter->l == nullptr) {
187 continue;
188 }
189 BMLoop *l_first = e_iter->l;
190 BMLoop *l_iter = l_first;
191 do {
192 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
193 continue;
194 }
195 if (l_iter->v != v) {
196 continue;
197 }
198 if (l_iter != l) {
199 if (BM_elem_flag_test(l_iter->f, hflag)) {
200 if (BM_loop_uv_share_vert_check(l, l_iter, cd_loop_uv_offset)) {
201 return true;
202 }
203 }
204 }
205 } while ((l_iter = l_iter->radial_next) != l_first);
206 } while ((e_iter = bmesh_disk_edge_next(e_iter, v)) != e_first);
207 return false;
208}
209
211 const char hflag,
212 const int cd_loop_uv_offset)
213{
215 BMLoop *l_iter = l;
216 do {
217 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
218 continue;
219 }
220 if (l_iter != l) {
221 if (BM_elem_flag_test(l_iter, hflag)) {
222 if (BM_loop_uv_share_edge_check(l, l_iter, cd_loop_uv_offset)) {
223 return true;
224 }
225 }
226 }
227 } while ((l_iter = l_iter->radial_next) != l);
228 return false;
229}
230
232 const char hflag,
233 const int cd_loop_uv_offset)
234{
236 BMLoop *l_iter = l;
237 do {
238 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
239 continue;
240 }
241 if (l_iter != l) {
242 if (BM_elem_flag_test(l_iter->f, hflag)) {
243 if (BM_loop_uv_share_edge_check(l, l_iter, cd_loop_uv_offset)) {
244 return true;
245 }
246 }
247 }
248 } while ((l_iter = l_iter->radial_next) != l);
249 return false;
250}
251
253{
255 return false;
256 }
257 BMLoop *l_iter, *l_first;
258 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
259 do {
261 return false;
262 }
263 } while ((l_iter = l_iter->next) != l_first);
264 return true;
265}
266
268
269/* -------------------------------------------------------------------- */
272
274{
275 /* Only select if it's valid, otherwise the result wont be used. */
278
279 /* Selecting when hidden must be prevented by the caller.
280 * Allow de-selecting as this may be useful at times. */
282
283 /* NOTE: don't do any flushing here as it's too expensive to walk over connected geometry.
284 * These can be handled in separate operations. */
286}
287
289{
290 /* Only select if it's valid, otherwise the result wont be used. */
293
294 /* Selecting when hidden must be prevented by the caller.
295 * Allow de-selecting as this may be useful at times. */
297
298 /* NOTE: don't do any flushing here as it's too expensive to walk over connected geometry.
299 * These can be handled in separate operations. */
301}
302
310
312{
313 /* Only select if it's valid, otherwise the result wont be used. */
316
317 /* Selecting when hidden must be prevented by the caller.
318 * Allow de-selecting as this may be useful at times. */
320
321 /* NOTE: don't do any flushing here as it's too expensive to walk over connected geometry.
322 * These can be handled in separate operations. */
324}
325
327{
329 BMLoop *l_iter, *l_first;
330 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
331 do {
334 } while ((l_iter = l_iter->next) != l_first);
335}
336
338{
339 if (bm->uv_select_sync_valid == false) {
340 return false;
341 }
342 bm->uv_select_sync_valid = false;
343 return true;
344}
345
347
348/* -------------------------------------------------------------------- */
351
353 BMLoop *l,
354 bool select,
355 const int cd_loop_uv_offset)
356{
358
359 BMVert *v = l->v;
360 BLI_assert(v->e);
361 const BMEdge *e_iter, *e_first;
362 e_iter = e_first = v->e;
363 do {
364 if (e_iter->l == nullptr) {
365 continue;
366 }
367 BMLoop *l_first = e_iter->l;
368 BMLoop *l_iter = l_first;
369 do {
370 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
371 continue;
372 }
373 if (l_iter->v != v) {
374 continue;
375 }
376 if (l_iter != l) {
378 if (BM_loop_uv_share_vert_check(l, l_iter, cd_loop_uv_offset)) {
380 }
381 }
382 }
383 } while ((l_iter = l_iter->radial_next) != l_first);
384 } while ((e_iter = bmesh_disk_edge_next(e_iter, v)) != e_first);
385}
386
388 BMLoop *l,
389 bool select,
390 const int cd_loop_uv_offset)
391{
393
394 BMLoop *l_iter = l->radial_next;
395 /* Check it's not a boundary. */
396 if (l_iter != l) {
397 do {
398 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
399 continue;
400 }
402 if (BM_loop_uv_share_edge_check(l, l_iter, cd_loop_uv_offset)) {
404 }
405 }
406 } while ((l_iter = l_iter->radial_next) != l);
407 }
408}
409
410void BM_face_uvselect_set_shared(BMesh *bm, BMFace *f, bool select, const int cd_loop_uv_offset)
411{
413 BMLoop *l_iter, *l_first;
414 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
415 do {
416 BM_loop_vert_uvselect_set_shared(bm, l_iter, select, cd_loop_uv_offset);
417 BM_loop_edge_uvselect_set_shared(bm, l_iter, select, cd_loop_uv_offset);
418 } while ((l_iter = l_iter->next) != l_first);
419}
420
422 bool select,
423 const int cd_loop_uv_offset,
424 const Span<BMLoop *> loop_verts,
425 const Span<BMLoop *> loop_edges,
426 const Span<BMFace *> faces)
427{
428 /* TODO: this could be optimized to reduce traversal of connected UV's for every element. */
429
430 for (BMLoop *l_vert : loop_verts) {
431 BM_loop_vert_uvselect_set_shared(bm, l_vert, select, cd_loop_uv_offset);
432 }
433 for (BMLoop *l_edge : loop_edges) {
434 BM_loop_edge_uvselect_set_shared(bm, l_edge, select, cd_loop_uv_offset);
435
436 if (select) {
437 BM_loop_vert_uvselect_set_shared(bm, l_edge, select, cd_loop_uv_offset);
438 BM_loop_vert_uvselect_set_shared(bm, l_edge->next, select, cd_loop_uv_offset);
439 }
440 }
441 for (BMFace *f : faces) {
442 if (select) {
443 BM_face_uvselect_set_shared(bm, f, select, cd_loop_uv_offset);
444 }
445 else {
447 }
448 }
449
450 /* Only de-select shared elements if they are no longer connected to a selection. */
451 if (!select) {
452 for (BMLoop *l_edge : loop_edges) {
453 if (BM_elem_flag_test(l_edge->f, BM_ELEM_HIDDEN)) {
454 continue;
455 }
456 /* If any of the vertices from the edges are no longer connected to a selected edge
457 * de-select the entire vertex.. */
458 for (BMLoop *l_edge_vert : {l_edge, l_edge->next}) {
459 /* The other edge of this loop connected to the vertex. */
460 const BMLoop *l_edge_other = (l_edge_vert == l_edge) ? l_edge->prev : l_edge->next;
461 if (!BM_elem_flag_test(l_edge_other, BM_ELEM_SELECT_UV_EDGE) &&
463 l_edge_vert, BM_ELEM_SELECT_UV_EDGE, cd_loop_uv_offset))
464 {
465 BM_loop_vert_uvselect_set_shared(bm, l_edge_vert, false, cd_loop_uv_offset);
466 }
467 }
468 }
469
470 /* De-select edge pass. */
471 for (BMFace *f : faces) {
473 continue;
474 }
475
476 BMLoop *l_iter, *l_first;
477 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
478 do {
480 /* Already handled. */
481 continue;
482 }
483 if (!BM_loop_edge_uvselect_check_other_face(l_iter, BM_ELEM_SELECT_UV, cd_loop_uv_offset))
484 {
485 BM_loop_edge_uvselect_set_shared(bm, l_iter, false, cd_loop_uv_offset);
486 }
487 } while ((l_iter = l_iter->next) != l_first);
488 }
489
490 /* De-select vert pass. */
491 for (BMFace *f : faces) {
493 continue;
494 }
495 BMLoop *l_iter, *l_first;
496 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
497 do {
498 if (!BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV)) {
499 /* Already handled. */
500 continue;
501 }
502 /* Keep vertices of selected edges. */
505 {
506 continue;
507 }
509 l_iter, BM_ELEM_SELECT_UV_EDGE, cd_loop_uv_offset))
510 {
511 BM_loop_vert_uvselect_set_shared(bm, l_iter, false, cd_loop_uv_offset);
512 }
513 } while ((l_iter = l_iter->next) != l_first);
514 }
515 }
516}
517
519
520/* -------------------------------------------------------------------- */
540
542 BMVert *v,
543 const bool select,
544 const BMUVSelectPickParams & /*uv_pick_params*/,
545 bool caller_handles_edge_or_face_mode)
546{
547 if (caller_handles_edge_or_face_mode == false) {
548 /* With de-selection, isolated vertices/edges wont be de-selected.
549 * In practice users should not be picking edges when in face select mode. */
551 "Picking verts in edge or face-select mode is not supported.");
552 }
553 /* NOTE: it doesn't make sense to check `uv_pick_params.shared` in this context because,
554 * unlike edges and faces, a vertex is logically connected to all corners that use it,
555 * so there is no way to use the UV coordinates to differentiate one UV region from another. */
556
558 return;
559 }
560
561 /* Must be connected to edges. */
562 if (v->e == nullptr) {
563 return;
564 }
565
566 if (select) {
567 const BMEdge *e_iter, *e_first;
568 e_iter = e_first = v->e;
569 do {
570 if (e_iter->l == nullptr) {
571 continue;
572 }
573 BMLoop *l_radial_iter, *l_radial_first;
574 l_radial_iter = l_radial_first = e_iter->l;
575 do {
576 if (BM_elem_flag_test(l_radial_iter->f, BM_ELEM_HIDDEN)) {
577 continue;
578 }
579 if (v != l_radial_iter->v) {
580 continue;
581 }
582 /* Select vertex. */
583 BM_loop_vert_uvselect_set_noflush(bm, l_radial_iter, true);
584
585 /* Select edges if adjacent vertices are selected. */
586 if (BM_elem_flag_test(l_radial_iter->next, BM_ELEM_SELECT_UV)) {
587 BM_loop_edge_uvselect_set_noflush(bm, l_radial_iter, true);
588 }
589 if (BM_elem_flag_test(l_radial_iter->prev, BM_ELEM_SELECT_UV)) {
590 BM_loop_edge_uvselect_set_noflush(bm, l_radial_iter->prev, true);
591 }
592 /* Select face if all edges are selected. */
593 if (!BM_elem_flag_test(l_radial_iter->f, BM_ELEM_HIDDEN) &&
594 !BM_elem_flag_test(l_radial_iter->f, BM_ELEM_SELECT_UV))
595 {
596 if (BM_face_uvselect_check_edges_all(l_radial_iter->f)) {
597 BM_face_uvselect_set_noflush(bm, l_radial_iter->f, true);
598 }
599 }
600 } while ((l_radial_iter = l_radial_iter->radial_next) != l_radial_first);
601 } while ((e_iter = bmesh_disk_edge_next(e_iter, v)) != e_first);
602 }
603 else {
604 const BMEdge *e_iter, *e_first;
605 e_iter = e_first = v->e;
606 do {
607 if (e_iter->l == nullptr) {
608 continue;
609 }
610 BMLoop *l_radial_iter, *l_radial_first;
611 l_radial_iter = l_radial_first = e_iter->l;
612 do {
613 if (BM_elem_flag_test(l_radial_iter->f, BM_ELEM_HIDDEN)) {
614 continue;
615 }
616 if (v != l_radial_iter->v) {
617 continue;
618 }
619 /* Deselect vertex. */
620 BM_loop_vert_uvselect_set_noflush(bm, l_radial_iter, false);
621 /* Deselect edges. */
622 BM_loop_edge_uvselect_set_noflush(bm, l_radial_iter, false);
623 BM_loop_edge_uvselect_set_noflush(bm, l_radial_iter->prev, false);
624 /* Deselect connected face. */
625 BM_face_uvselect_set_noflush(bm, l_radial_iter->f, false);
626 } while ((l_radial_iter = l_radial_iter->radial_next) != l_radial_first);
627 } while ((e_iter = bmesh_disk_edge_next(e_iter, v)) != e_first);
628 }
629}
630
632 BMEdge *e,
633 const bool select,
634 const BMUVSelectPickParams &uv_pick_params,
635 const bool caller_handles_face_mode)
636{
637 if (caller_handles_face_mode == false) {
638 /* With de-selection, isolated vertices/edges wont be de-selected.
639 * In practice users should not be picking edges when in face select mode. */
641 "Picking edges in face-select mode is not supported.");
642 }
643
645 return;
646 }
647
648 if (select == false) {
650 /* Match #BM_edge_select_set which de-selects the vertices in this mode. */
651 bm_vert_uvselect_set_pick(bm, e->v1, false, uv_pick_params, false);
652 bm_vert_uvselect_set_pick(bm, e->v2, false, uv_pick_params, false);
653 return;
654 }
655 }
656
657 /* Must be connected to faces.
658 * NOTE: this check runs after de-selecting vertices as wire edges have no loops
659 * although de-selecting them still de-selects their vertices. */
660 if (e->l == nullptr) {
661 return;
662 }
663
664 if (uv_pick_params.shared == false) {
665 BMLoop *l_iter, *l_first;
666
667 if (select) {
668 bool any_faces_unselected = false;
669 l_iter = l_first = e->l;
670 do {
671 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
672 continue;
673 }
674
676
679
680 if (any_faces_unselected == false) {
681 if (!BM_elem_flag_test(l_iter->f, BM_ELEM_SELECT_UV)) {
682 any_faces_unselected = true;
683 }
684 }
685 } while ((l_iter = l_iter->radial_next) != l_first);
686
687 /* Flush selection to faces when all edges in connected faces are now selected. */
688 if (any_faces_unselected) {
689 l_iter = l_first = e->l;
690 do {
691 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
692 continue;
693 }
694 if (!BM_elem_flag_test(l_iter->f, BM_ELEM_SELECT_UV)) {
695 if (BM_face_uvselect_check_edges_all(l_iter->f)) {
696 BM_face_uvselect_set_noflush(bm, l_iter->f, true);
697 }
698 }
699 } while ((l_iter = l_iter->radial_next) != l_first);
700 }
701 }
702 else {
703 l_iter = l_first = e->l;
704 do {
705 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
706 continue;
707 }
711 }
714 }
715 BM_face_uvselect_set_noflush(bm, l_iter->f, false);
716 } while ((l_iter = l_iter->radial_next) != l_first);
717 }
718 return;
719 }
720
721 /* NOTE(@ideasman42): this is awkward as the edge may reference multiple island bounds.
722 * - De-selecting will de-select all which makes sense.
723 * - Selecting will also select all which is not likely to be all that useful for users.
724 *
725 * We could attempt to use the surrounding selection to *guess* which UV island selection
726 * to extend but this seems error prone as it depends on the order elements are selected
727 * so it's it only likely to work in some situations.
728 *
729 * To *properly* solve this we would be better off to support picking edge+face (loop)
730 * combinations from the 3D viewport, so picking the edge would determine the loop which would
731 * be selected, but this is a much bigger change.
732 *
733 * In practice users are likely to prefer face selection when working with UV islands anyway. */
734
735 BMLoop *l_iter, *l_first;
736
737 if (select) {
738 bool any_faces_unselected = false;
739 l_iter = l_first = e->l;
740 do {
741 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
742 continue;
743 }
744
746
747 BM_loop_vert_uvselect_set_shared(bm, l_iter, true, uv_pick_params.cd_loop_uv_offset);
748 BM_loop_vert_uvselect_set_shared(bm, l_iter->next, true, uv_pick_params.cd_loop_uv_offset);
749
750 if (any_faces_unselected == false) {
751 if (!BM_elem_flag_test(l_iter->f, BM_ELEM_SELECT_UV)) {
752 any_faces_unselected = true;
753 }
754 }
755 } while ((l_iter = l_iter->radial_next) != l_first);
756
757 /* Flush selection to faces when all edges in connected faces are now selected. */
758 if (any_faces_unselected) {
759 l_iter = l_first = e->l;
760 do {
761 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
762 continue;
763 }
764 if (!BM_elem_flag_test(l_iter->f, BM_ELEM_SELECT_UV)) {
765 if (BM_face_uvselect_check_edges_all(l_iter->f)) {
766 BM_face_uvselect_set_noflush(bm, l_iter->f, true);
767 }
768 }
769 } while ((l_iter = l_iter->radial_next) != l_first);
770 }
771 }
772 else {
773 l_iter = l_first = e->l;
774 do {
775 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
776 continue;
777 }
781 }
784 }
785 BM_face_uvselect_set_noflush(bm, l_iter->f, false);
786 } while ((l_iter = l_iter->radial_next) != l_first);
787
788 /* Ensure connected vertices remain selected when they are connected to selected edges. */
789 l_iter = l_first = e->l;
790 do {
791 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
792 continue;
793 }
794 for (BMLoop *l_edge_vert : {l_iter, l_iter->next}) {
795 if (BM_elem_flag_test(l_edge_vert, BM_ELEM_SELECT_UV)) {
796 /* This was not de-selected. */
797 continue;
798 }
800 l_edge_vert, BM_ELEM_SELECT_UV_EDGE, uv_pick_params.cd_loop_uv_offset))
801 {
802 BM_loop_vert_uvselect_set_noflush(bm, l_edge_vert, true);
803 }
804 else {
805 /* It's possible there are isolated selected vertices,
806 * although in edge select mode this should not happen. */
808 bm, l_edge_vert, false, uv_pick_params.cd_loop_uv_offset);
809 }
810 }
811 } while ((l_iter = l_iter->radial_next) != l_first);
812 }
813}
814
816 BMFace *f,
817 const bool select,
818 const BMUVSelectPickParams &uv_pick_params)
819{
820 /* Picking faces is valid in all selection modes. */
822 return;
823 }
824
825 BMLoop *l_iter, *l_first;
826
827 if (select == false) {
828 /* Match #BM_face_select_set which de-selects the vertices or edges in these modes. */
830 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
831 do {
832 bm_vert_uvselect_set_pick(bm, l_iter->v, false, uv_pick_params, false);
833 } while ((l_iter = l_iter->next) != l_first);
834 return;
835 }
837 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
838 do {
839 bm_edge_uvselect_set_pick(bm, l_iter->e, false, uv_pick_params, false);
840 } while ((l_iter = l_iter->next) != l_first);
841 return;
842 }
843 }
844
845 if (uv_pick_params.shared == false) {
847 return;
848 }
849
850 if (select) {
852
853 /* Setting these values first. */
854 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
855 do {
858 } while ((l_iter = l_iter->next) != l_first);
859
860 /* Set other values. */
861 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
862 do {
863 BM_loop_vert_uvselect_set_shared(bm, l_iter, true, uv_pick_params.cd_loop_uv_offset);
864 BM_loop_edge_uvselect_set_shared(bm, l_iter, true, uv_pick_params.cd_loop_uv_offset);
865 } while ((l_iter = l_iter->next) != l_first);
866 }
867 else {
869
870 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
871 do {
874 /* Vertex. */
876 l_iter, BM_ELEM_SELECT_UV, uv_pick_params.cd_loop_uv_offset))
877 {
879 }
880 else {
881 BM_loop_vert_uvselect_set_shared(bm, l_iter, false, uv_pick_params.cd_loop_uv_offset);
882 }
883 /* Edge. */
885 l_iter, BM_ELEM_SELECT_UV, uv_pick_params.cd_loop_uv_offset))
886 {
888 }
889 else {
890 BM_loop_edge_uvselect_set_shared(bm, l_iter, false, uv_pick_params.cd_loop_uv_offset);
891 }
892 } while ((l_iter = l_iter->next) != l_first);
893 }
894}
895
897 BMVert *v,
898 bool select,
899 const BMUVSelectPickParams &params)
900{
901 const bool caller_handles_edge_or_face_mode = false;
902 bm_vert_uvselect_set_pick(bm, v, select, params, caller_handles_edge_or_face_mode);
903}
905 BMEdge *e,
906 bool select,
907 const BMUVSelectPickParams &params)
908{
909 const bool caller_handles_face_mode = false;
910 bm_edge_uvselect_set_pick(bm, e, select, params, caller_handles_face_mode);
911}
913 BMFace *f,
914 bool select,
915 const BMUVSelectPickParams &params)
916{
917 /* Picking faces is valid in all modes. */
919}
920
934 const short select_mode,
935 const int cd_loop_uv_offset,
936 const bool shared,
937 const bool check_verts,
938 const bool check_edges)
939{
940 if (!(check_verts || check_edges)) {
941 return;
942 }
943
944 /* No additional work needed. */
945 bool do_check = false;
946 if (select_mode & SCE_SELECT_VERTEX) {
947 /* Pass. */
948 }
949 else if (select_mode & SCE_SELECT_EDGE) {
950 if (check_verts) {
951 do_check = true;
952 }
953 }
954 else if (select_mode & SCE_SELECT_FACE) {
955 if (check_verts || check_edges) {
956 do_check = true;
957 }
958 }
959
960 if (do_check == false) {
961 return;
962 }
963
964 /* This requires a fairly specific kind of flushing.
965 * - It's only necessary to flush down (faces -> edges, edges -> verts).
966 * - Only select/deselect is needed.
967 * Do this inline.
968 */
969 if (select_mode & SCE_SELECT_EDGE) {
970 /* Deselect isolated vertices. */
971 BMIter iter;
972 BMFace *f;
973 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
975 continue;
976 }
977 /* Only handle faces that are partially selected. */
979 continue;
980 }
981 BMLoop *l_iter, *l_first;
982 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
983 do {
985 /* Skip the UV check if either edge is selected. */
988 {
990 l_iter, BM_ELEM_SELECT_UV_EDGE, cd_loop_uv_offset))
991 {
993 }
994 }
995 } while ((l_iter = l_iter->next) != l_first);
996 }
997 }
998 else if (select_mode & SCE_SELECT_FACE) {
999 /* Deselect isolated vertices & edges. */
1000 BMIter iter;
1001 BMFace *f;
1002 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1004 continue;
1005 }
1006 /* Only handle faces that are partially selected. */
1008 continue;
1009 }
1010 BMLoop *l_iter, *l_first;
1011 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1012 do {
1015 l_iter, BM_ELEM_SELECT_UV, cd_loop_uv_offset))
1016 {
1018 }
1019 }
1020 } while ((l_iter = l_iter->next) != l_first);
1021 bool e_prev_select = BM_elem_flag_test(l_iter->prev, BM_ELEM_SELECT_UV_EDGE);
1022 l_iter = l_first;
1023 do {
1024 const bool e_iter_select = BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV_EDGE);
1025 /* Skip the UV check if either edge is selected. */
1026 if (BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV) && !(e_prev_select || e_iter_select)) {
1028 l_iter, BM_ELEM_SELECT_UV, cd_loop_uv_offset))
1029 {
1031 }
1032 }
1033 e_prev_select = e_iter_select;
1034 } while ((l_iter = l_iter->next) != l_first);
1035 }
1036 }
1037}
1038
1040 const bool select,
1041 const BMUVSelectPickParams &params,
1042 const VectorList<BMVert *> &verts,
1043 const VectorList<BMEdge *> &edges,
1044 const VectorList<BMFace *> &faces)
1045{
1046 const bool check_verts = !verts.is_empty();
1047 const bool check_edges = !edges.is_empty();
1048 const bool check_faces = !faces.is_empty();
1049 if (!(check_verts || check_edges || check_faces)) {
1050 return;
1051 }
1052
1053 /* TODO(@ideasman42): select picking may be slow because it does flushing too.
1054 * Although in practice it seems fast-enough. This should be handled more efficiently. */
1055
1056 for (BMVert *v : verts) {
1057 bm_vert_uvselect_set_pick(bm, v, select, params, true);
1058 }
1059 for (BMEdge *e : edges) {
1060 bm_edge_uvselect_set_pick(bm, e, select, params, true);
1061 }
1062 for (BMFace *f : faces) {
1063 bm_face_uvselect_set_pick(bm, f, select, params);
1064 }
1065
1066 if (select) {
1067 /* Match the mesh selection which flushes up. */
1069 }
1070
1072 bm, bm->selectmode, params.cd_loop_uv_offset, params.shared, check_verts, check_edges);
1073}
1074
1076 bool select,
1077 const BMUVSelectPickParams &params,
1078 Span<BMVert *> verts,
1079 Span<BMEdge *> edges,
1080 Span<BMFace *> faces)
1081{
1082 const bool check_verts = !verts.is_empty();
1083 const bool check_edges = !edges.is_empty();
1084 const bool check_faces = !faces.is_empty();
1085 if (!(check_verts || check_edges || check_faces)) {
1086 return;
1087 }
1088
1089 for (BMVert *v : verts) {
1091 }
1092 for (BMEdge *e : edges) {
1094 }
1095 for (BMFace *f : faces) {
1096 BM_face_uvselect_set_pick(bm, f, select, params);
1097 }
1098
1099 if (select) {
1100 /* Match the mesh selection which flushes up. */
1102 }
1103
1105 bm, bm->selectmode, params.cd_loop_uv_offset, params.shared, check_verts, check_edges);
1106}
1107
1109
1110/* -------------------------------------------------------------------- */
1113
1115{
1116 BMIter iter;
1117 BMFace *f;
1118 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1120 continue;
1121 }
1122
1123 BMLoop *l_iter, *l_first;
1124 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1125 bool all_select = true;
1126 do {
1127 if (BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV) &&
1129 {
1131 }
1132 else {
1133 all_select = false;
1134 }
1135 } while ((l_iter = l_iter->next) != l_first);
1136 if (all_select) {
1138 }
1139 }
1140}
1141
1143{
1144 BMIter iter;
1145 BMFace *f;
1146 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1148 continue;
1149 }
1150
1151 BMLoop *l_iter, *l_first;
1152 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1153 bool all_select = true;
1154 do {
1155 if (BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV) &&
1157 {
1158 /* Pass. */
1159 }
1160 else {
1161 BM_loop_edge_uvselect_set_noflush(bm, l_iter, false);
1162 all_select = false;
1163 }
1164 } while ((l_iter = l_iter->next) != l_first);
1165 if (all_select == false) {
1167 }
1168 }
1169}
1170
1172{
1173 BMIter iter;
1174 BMFace *f;
1175 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1177 continue;
1178 }
1179
1180 BMLoop *l_iter, *l_first;
1181 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1182 bool all_select = true;
1183 do {
1185 BM_loop_edge_uvselect_set(bm, l_iter, true);
1186 }
1187 else {
1188 all_select = false;
1189 }
1190 } while ((l_iter = l_iter->next) != l_first);
1191 if (all_select) {
1193 }
1194 }
1195}
1196
1198{
1199 BMIter iter;
1200 BMFace *f;
1201 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1203 continue;
1204 }
1205
1206 BMLoop *l_iter, *l_first;
1207 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1208 bool all_select = true;
1209 do {
1211 l_iter,
1214
1216 /* Pass. */
1217 }
1218 else {
1219 BM_loop_edge_uvselect_set_noflush(bm, l_iter, false);
1220 all_select = false;
1221 }
1222 } while ((l_iter = l_iter->next) != l_first);
1223 if (all_select == false) {
1225 }
1226 }
1227}
1228
1230{
1231 BMIter iter;
1232 BMFace *f;
1233 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1235 continue;
1236 }
1237
1239 continue;
1240 }
1241 BMLoop *l_iter, *l_first;
1242 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1243 do {
1246 } while ((l_iter = l_iter->next) != l_first);
1247 }
1248}
1249
1251{
1252 BMIter iter;
1253 BMFace *f;
1254 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1256 continue;
1257 }
1258
1260 continue;
1261 }
1262 BMLoop *l_iter, *l_first;
1263 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1264 do {
1265 BM_loop_vert_uvselect_set_noflush(bm, l_iter, false);
1266 BM_loop_edge_uvselect_set_noflush(bm, l_iter, false);
1267 } while ((l_iter = l_iter->next) != l_first);
1268 }
1269}
1270
1271void BM_mesh_uvselect_flush_shared_only_select(BMesh *bm, const int cd_loop_uv_offset)
1272{
1273 BLI_assert(cd_loop_uv_offset >= 0);
1274 BMIter iter;
1275 BMFace *f;
1276 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1278 continue;
1279 }
1280
1281 BMLoop *l_iter, *l_first;
1282 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1283 do {
1284 if (!BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV)) {
1286 l_iter, BM_ELEM_SELECT_UV, cd_loop_uv_offset))
1287 {
1289 }
1290 }
1293 l_iter, BM_ELEM_SELECT_UV_EDGE, cd_loop_uv_offset))
1294 {
1296 }
1297 }
1298 } while ((l_iter = l_iter->next) != l_first);
1299 }
1300}
1301
1302void BM_mesh_uvselect_flush_shared_only_deselect(BMesh *bm, const int cd_loop_uv_offset)
1303{
1304 BLI_assert(cd_loop_uv_offset >= 0);
1305 BMIter iter;
1306 BMFace *f;
1307 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1309 continue;
1310 }
1311
1312 BMLoop *l_iter, *l_first;
1313 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1314 do {
1315 if (BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV)) {
1317 l_iter, BM_ELEM_SELECT_UV, cd_loop_uv_offset))
1318 {
1319 BM_loop_vert_uvselect_set_noflush(bm, l_iter, false);
1320 }
1321 }
1324 l_iter, BM_ELEM_SELECT_UV_EDGE, cd_loop_uv_offset))
1325 {
1326 BM_loop_edge_uvselect_set_noflush(bm, l_iter, false);
1327 }
1328 }
1329 } while ((l_iter = l_iter->next) != l_first);
1330 }
1331}
1332
1334
1335/* -------------------------------------------------------------------- */
1338
1340{
1341 BMIter iter;
1342 BMFace *f;
1343 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1345 continue;
1346 }
1347
1348 bool select_all = true;
1349 BMLoop *l_iter, *l_first;
1350 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1351 do {
1352 const bool select = (BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV) &&
1355 if (select == false) {
1356 select_all = false;
1357 }
1358 } while ((l_iter = l_iter->next) != l_first);
1359 BM_face_uvselect_set_noflush(bm, f, select_all);
1360 }
1361}
1362
1364{
1365 BMIter iter;
1366 BMFace *f;
1367
1368 /* Clear vert/face select. */
1369 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1371 continue;
1372 }
1373
1374 if (flush_down) {
1375 BMLoop *l_iter, *l_first;
1376 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1377 do {
1378 BM_loop_vert_uvselect_set_noflush(bm, l_iter, false);
1379 } while ((l_iter = l_iter->next) != l_first);
1380 }
1382 }
1383
1384 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1386 continue;
1387 }
1388
1389 bool select_all = true;
1390 BMLoop *l_iter, *l_first;
1391 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1392 do {
1393 const bool select_edge = BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV_EDGE);
1394 if (select_edge) {
1395 if (flush_down) {
1398 }
1399 }
1400 else {
1401 select_all = false;
1402 }
1403 } while ((l_iter = l_iter->next) != l_first);
1404 if (select_all) {
1406 }
1407 }
1408}
1409
1411{
1412 if (!flush_down) {
1413 return; /* NOP. */
1414 }
1415
1416 BMIter iter;
1417 BMFace *f;
1418 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1420 continue;
1421 }
1422
1423 const bool select_face = BM_elem_flag_test(f, BM_ELEM_SELECT_UV);
1424 BMLoop *l_iter, *l_first;
1425 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1426 do {
1427 BM_loop_vert_uvselect_set_noflush(bm, l_iter, select_face);
1428 BM_loop_edge_uvselect_set_noflush(bm, l_iter, select_face);
1429 } while ((l_iter = l_iter->next) != l_first);
1430 }
1431}
1432
1442
1444
1445/* -------------------------------------------------------------------- */
1448
1449void BM_mesh_uvselect_mode_flush_ex(BMesh *bm, const short selectmode, const bool flush_down)
1450{
1451 if (selectmode & SCE_SELECT_VERTEX) {
1453 }
1454 else if (selectmode & SCE_SELECT_EDGE) {
1456 }
1457 else {
1459 }
1460}
1461
1466
1468{
1471 }
1472 else if (bm->selectmode & SCE_SELECT_EDGE) {
1474 }
1475 else {
1476 /* Pass (nothing to do for faces). */
1477 }
1478}
1479
1481 const short selectmode_old,
1482 const short selectmode_new,
1483 const int cd_loop_uv_offset)
1484{
1485
1486 if (highest_order_bit_s(selectmode_old) >= highest_order_bit_s(selectmode_new)) {
1487
1488 if ((selectmode_old & SCE_SELECT_VERTEX) == 0 && (selectmode_new & SCE_SELECT_VERTEX)) {
1489 /* When changing from edge/face to vertex selection,
1490 * new edges/faces may be selected based on the vertex selection. */
1492 }
1493 else if ((selectmode_old & SCE_SELECT_EDGE) == 0 && (selectmode_new & SCE_SELECT_EDGE)) {
1494 /* When changing from face to edge selection,
1495 * new faces may be selected based on the edge selection. */
1497 }
1498
1499 /* Pass, no need to do anything when moving from edge to vertex mode (for e.g.). */
1500 return;
1501 }
1502
1503 bool do_flush_deselect_down = false;
1504 if (selectmode_old & SCE_SELECT_VERTEX) {
1505 if ((selectmode_new & SCE_SELECT_VERTEX) == 0) {
1506 do_flush_deselect_down = true;
1507 }
1508 }
1509 else if (selectmode_old & SCE_SELECT_EDGE) {
1510 if ((selectmode_new & SCE_SELECT_EDGE) == 0) {
1511 do_flush_deselect_down = true;
1512 }
1513 }
1514
1515 if (do_flush_deselect_down == false) {
1516 return;
1517 }
1518
1519 /* Perform two passes:
1520 *
1521 * - De-select all elements where the underlying elements are not selected.
1522 * - De select any isolated elements.
1523 *
1524 * NOTE: As the mesh will have already had it's isolated elements de-selected,
1525 * it may seem like this pass shouldn't be needed in UV space,
1526 * however a vert/edge may be isolated in UV space while being connected to a
1527 * selected edge/face in 3D space.
1528 */
1529
1530 /* First pass: match underlying mesh. */
1531 BMIter iter;
1532 BMFace *f;
1533 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1535 continue;
1536 }
1537
1538 BMLoop *l_iter, *l_first;
1539 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1540 bool select_face = true;
1541 do {
1542 if (BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV)) {
1543 if (!BM_elem_flag_test(l_iter->v, BM_ELEM_SELECT)) {
1545 }
1546 }
1548 if (!BM_elem_flag_test(l_iter->e, BM_ELEM_SELECT)) {
1550 select_face = false;
1551 }
1552 }
1553 else {
1554 select_face = false;
1555 }
1556 } while ((l_iter = l_iter->next) != l_first);
1557
1558 if (select_face == false) {
1560 }
1561 }
1562
1563 /* Second Pass: Ensure isolated elements are not selected. */
1564 if (cd_loop_uv_offset != -1) {
1565 const bool shared = true;
1566 const bool check_verts = (bm->totvertsel != 0);
1567 const bool check_edges = (bm->totedgesel != 0);
1569 bm, selectmode_new, cd_loop_uv_offset, shared, check_verts, check_edges);
1570 }
1571}
1572
1573void BM_mesh_uvselect_flush_post_subdivide(BMesh *bm, const int cd_loop_uv_offset)
1574{
1575 {
1576 BMIter iter;
1577 BMFace *f;
1578 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1580 BM_face_uvselect_set(bm, f, true);
1581 }
1582 }
1583 }
1584
1585 const bool use_edges = bm->selectmode & (SCE_SELECT_VERTEX | SCE_SELECT_EDGE);
1586 if (use_edges) {
1587 BMIter iter;
1588 BMEdge *e;
1589 BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
1590 if (e->l == nullptr) {
1591 continue;
1592 }
1594 /* This will have been handled if an attached face is selected. */
1596 {
1597 BMLoop *l_radial_iter, *l_radial_first;
1598 l_radial_iter = l_radial_first = e->l;
1599 do {
1600 if (BM_elem_flag_test(l_radial_iter->f, BM_ELEM_HIDDEN)) {
1601 continue;
1602 }
1603 BM_loop_edge_uvselect_set(bm, l_radial_iter, true);
1604 } while ((l_radial_iter = l_radial_iter->radial_next) != l_radial_first);
1605 }
1606 }
1607 }
1608
1609 /* Now select any "shared" UV's that are connected to an edge or face. */
1610 if (cd_loop_uv_offset != -1) {
1611 BMIter iter;
1612 BMFace *f;
1613 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1615 continue;
1616 }
1618 continue;
1619 }
1620 BMLoop *l_iter, *l_first;
1621
1622 /* Setting these values first. */
1623 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1624 do {
1625 /* With vertex select mode, only handle vertices, then flush to edges -> faces. */
1626 if ((bm->selectmode & SCE_SELECT_VERTEX) == 0) {
1627 /* Check edges first, since a selected edge also indicates a selected vertex. */
1630 l_iter, BM_ELEM_SELECT_UV_EDGE, cd_loop_uv_offset))
1631 {
1632 /* Check the other radial edge. */
1633 BM_loop_edge_uvselect_set(bm, l_iter, true);
1634 }
1635 }
1636 /* Check the other radial vertex (a selected edge will have done this). */
1637 if (!BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV)) {
1639 l_iter, BM_ELEM_SELECT_UV, cd_loop_uv_offset))
1640 {
1642 }
1643 }
1644 } while ((l_iter = l_iter->next) != l_first);
1645 }
1646 }
1647
1648 /* It's possible selecting a vertex or edge will cause other elements to have become selected.
1649 * Flush up if necessary. */
1651}
1652
1654
1655/* -------------------------------------------------------------------- */
1658
1659/* Sticky Vertex. */
1660
1662{
1663 BMIter iter;
1664 BMFace *f;
1665
1666 /* UV select flags may be dirty, overwrite all. */
1667 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1669 continue;
1670 }
1671 BMLoop *l_iter, *l_first;
1672 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1673 do {
1674 const bool v_select = BM_elem_flag_test(l_iter->v, BM_ELEM_SELECT);
1675 const bool e_select = BM_elem_flag_test(l_iter->e, BM_ELEM_SELECT);
1676 BM_elem_flag_set(l_iter, BM_ELEM_SELECT_UV, v_select);
1677 BM_elem_flag_set(l_iter, BM_ELEM_SELECT_UV_EDGE, e_select);
1678 } while ((l_iter = l_iter->next) != l_first);
1680 }
1681 bm->uv_select_sync_valid = true;
1682}
1683
1685{
1686 BMIter iter;
1687 BMFace *f;
1688
1689 /* Clearing all makes the following logic simpler as
1690 * since we only need to select UV's connected to selected edges. */
1692
1693 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1695 continue;
1696 }
1697
1698 BMLoop *l_iter, *l_first;
1699 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1700 do {
1701 if (BM_elem_flag_test(l_iter->e, BM_ELEM_SELECT)) {
1703 for (BMLoop *l_edge_vert : {l_iter, l_iter->next}) {
1704 if (!BM_elem_flag_test(l_edge_vert, BM_ELEM_SELECT_UV)) {
1706 }
1707 }
1708 }
1709 } while ((l_iter = l_iter->next) != l_first);
1710
1713 }
1714 }
1715 bm->uv_select_sync_valid = true;
1716}
1717
1719{
1720 BMIter iter;
1721 BMFace *f;
1722
1723 /* Clearing all makes the following logic simpler as
1724 * since we only need to select UV's connected to selected edges. */
1726
1727 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1729 continue;
1730 }
1731
1733 BMLoop *l_iter, *l_first;
1734 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1735 do {
1738
1739 } while ((l_iter = l_iter->next) != l_first);
1741 }
1742 }
1743 bm->uv_select_sync_valid = true;
1744}
1745
1746/* Sticky Location. */
1747
1749 BMesh *bm, const int /*cd_loop_uv_offset*/)
1750{
1751 /* In this particular case use the same logic for sticky vertices,
1752 * unlike faces & edges we can't know which island a selected vertex belongs to.
1753 *
1754 * NOTE: arguably this is only true for an isolated vertex selection,
1755 * if there are surrounding selected edges/faces the vertex could only select UV's
1756 * connected to those selected regions. However, if this logic was followed (at-run-time)
1757 * it would mean that de-selecting a face could suddenly cause the vertex
1758 * (attached to that face on another UV island) to become selected.
1759 * Since that would be unexpected for users - just use this simple logic here. */
1761}
1762
1764 BMesh *bm, const int cd_loop_uv_offset)
1765{
1766 BMIter iter;
1767 BMFace *f;
1768
1769 /* UV select flags may be dirty, overwrite all. */
1770 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1772 continue;
1773 }
1774
1775 BMLoop *l_iter, *l_first;
1776 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1777 bool e_prev_select = BM_elem_flag_test(l_iter->prev->e, BM_ELEM_SELECT);
1778 do {
1779 const bool e_iter_select = BM_elem_flag_test(l_iter->e, BM_ELEM_SELECT);
1780 const bool v_iter_select = (BM_elem_flag_test(l_iter->v, BM_ELEM_SELECT) &&
1781 ((e_prev_select || e_iter_select) ||
1782 /* This is a more expensive check, order last. */
1784 l_iter, BM_ELEM_SELECT, cd_loop_uv_offset)));
1785
1786 BM_elem_flag_set(l_iter, BM_ELEM_SELECT_UV, v_iter_select);
1787 BM_elem_flag_set(l_iter, BM_ELEM_SELECT_UV_EDGE, e_iter_select);
1788 e_prev_select = e_iter_select;
1789 } while ((l_iter = l_iter->next) != l_first);
1790
1791 const bool f_select = BM_elem_flag_test(f, BM_ELEM_SELECT);
1792 BM_elem_flag_set(f, BM_ELEM_SELECT_UV, f_select);
1793 }
1794 bm->uv_select_sync_valid = true;
1795}
1796
1798 BMesh *bm, const int cd_loop_uv_offset)
1799{
1800 BMIter iter;
1801 BMFace *f;
1802
1803 /* UV select flags may be dirty, overwrite all. */
1804 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1806 continue;
1807 }
1808
1810 BMLoop *l_iter, *l_first;
1811 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1812 do {
1814 } while ((l_iter = l_iter->next) != l_first);
1816 }
1817 else {
1818 BMLoop *l_iter, *l_first;
1819 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1820 do {
1821 const bool v_iter_select = (BM_elem_flag_test(l_iter->v, BM_ELEM_SELECT) &&
1823 l_iter, BM_ELEM_SELECT, cd_loop_uv_offset));
1824 const bool e_iter_select = (BM_elem_flag_test(l_iter->e, BM_ELEM_SELECT) &&
1826 l_iter, BM_ELEM_SELECT, cd_loop_uv_offset));
1827
1828 BM_elem_flag_set(l_iter, BM_ELEM_SELECT_UV, v_iter_select);
1829 BM_elem_flag_set(l_iter, BM_ELEM_SELECT_UV_EDGE, e_iter_select);
1830 } while ((l_iter = l_iter->next) != l_first);
1832 }
1833 }
1834 bm->uv_select_sync_valid = true;
1835}
1836
1837/* Public API. */
1838
1840{
1843 }
1844 else if (bm->selectmode & SCE_SELECT_EDGE) {
1846 }
1847 else { /* `SCE_SELECT_FACE` */
1849 }
1850
1852}
1853
1855{
1856 /* The mode is ignored when sticky selection is disabled,
1857 * Always use the selection from the mesh. */
1860}
1861
1875
1877{
1879
1880 /* Prevent clearing the selection from removing all selection history.
1881 * This will be validated after flushing. */
1883
1885
1887 /* Simple, no need to worry about edge selection. */
1888
1889 /* Copy loop-vert to vert, then flush. */
1890 BMIter iter;
1891 BMFace *f;
1892 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1894 continue;
1895 }
1896
1897 BMLoop *l_iter, *l_first;
1898 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1899 do {
1900 if (BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV)) {
1901 BM_vert_select_set(bm, l_iter->v, true);
1902 }
1903 } while ((l_iter = l_iter->next) != l_first);
1904 }
1905
1907 }
1908 else if (bm->selectmode & SCE_SELECT_EDGE) {
1909 BMIter iter;
1910 BMFace *f;
1911 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1913 continue;
1914 }
1915
1916 BMLoop *l_iter, *l_first;
1917 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1918 /* Technically this should only need to check the edge
1919 * because when a vertex isn't selected, it's connected edges shouldn't be.
1920 * Check both in the unlikely case of an invalid selection. */
1921 bool face_select = true;
1922
1923 do {
1924 /* This requires the edges to have already been flushed to the vertices (assert next). */
1925 if (BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV)) {
1926 BM_vert_select_set(bm, l_iter->v, true);
1927 }
1928 else {
1929 face_select = false;
1930 }
1931
1933 /* If this fails, we've missed flushing. */
1936 BM_edge_select_set(bm, l_iter->e, true);
1937 }
1938 else {
1939 face_select = false;
1940 }
1941 } while ((l_iter = l_iter->next) != l_first);
1942 if (face_select) {
1944 }
1945 }
1946
1947 /* It's possible that a face which is *not* UV-selected
1948 * ends up with all it's edges selected.
1949 * Perform the edge to face flush inline. */
1950 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1952 continue;
1953 }
1954
1955 /* If the face is hidden, we can't selected,
1956 * If the face is already selected, it can be skipped here. */
1958 continue;
1959 }
1960 bool face_select = true;
1961 BMLoop *l_iter, *l_first;
1962 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1963 do {
1964 if (!BM_elem_flag_test(l_iter->e, BM_ELEM_SELECT)) {
1965 face_select = false;
1966 break;
1967 }
1968 } while ((l_iter = l_iter->next) != l_first);
1969
1970 if (face_select) {
1972 }
1973 }
1974 }
1975 else { /* `bm->selectmode & SCE_SELECT_FACE` */
1976 BMIter iter;
1977 BMFace *f;
1978 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1980 continue;
1981 }
1983 BM_face_select_set(bm, f, true);
1984 }
1985 }
1986 }
1987
1989
1991}
1992
1994
1995/* -------------------------------------------------------------------- */
2023
2024/* Asserting can be useful to inspect the values while debugging. */
2025#if 0 /* Useful when debugging. */
2026# define MAYBE_ASSERT BLI_assert(0)
2027#elif 0 /* Can also be useful. */
2028# define MAYBE_ASSERT printf(AT "\n")
2029#else
2030# define MAYBE_ASSERT
2031#endif
2032
2033#define INCF_MAYBE_ASSERT(var) \
2034 { \
2035 MAYBE_ASSERT; \
2036 (var) += 1; \
2037 } \
2038 ((void)0)
2039
2041{
2042 BMIter fiter;
2043 BMFace *f;
2044 BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
2045 BMLoop *l_iter, *l_first;
2046 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
2047 do {
2049 } while ((l_iter = l_iter->next) != l_first);
2050 }
2051}
2052
2059{
2060 bool is_valid = true;
2061
2062 /* Vertices. */
2063 {
2064 int &error_count = info_sub.count_uv_vert_any_selected_with_vert_unselected;
2065 BLI_assert(error_count == 0);
2066 BMIter fiter;
2067 BMFace *f;
2068 BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
2070 continue;
2071 }
2072
2073 BMLoop *l_iter, *l_first;
2074 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
2075 do {
2076 if (BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV)) {
2077 if (!BM_elem_flag_test(l_iter->v, BM_ELEM_SELECT)) {
2078 INCF_MAYBE_ASSERT(error_count);
2079 }
2080 }
2081 } while ((l_iter = l_iter->next) != l_first);
2082 }
2083 if (error_count) {
2084 is_valid = false;
2085 }
2086 }
2087
2088 {
2089 int &error_count = info_sub.count_uv_vert_none_selected_with_vert_selected;
2090 BLI_assert(error_count == 0);
2091 BMIter viter;
2092 BMIter liter;
2093
2094 BMVert *v;
2095 BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) {
2097 continue;
2098 }
2100 continue;
2101 }
2102
2103 bool any_loop_selected = false;
2104 {
2105 BMLoop *l;
2106 BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) {
2108 any_loop_selected = true;
2109 break;
2110 }
2111 }
2112 }
2113
2114 if (any_loop_selected == false) {
2115 INCF_MAYBE_ASSERT(error_count);
2116 }
2117 }
2118 if (error_count) {
2119 is_valid = false;
2120 }
2121 }
2122
2123 /* Edges. */
2124 {
2125 int &error_count = info_sub.count_uv_edge_any_selected_with_edge_unselected;
2126 BLI_assert(error_count == 0);
2127 BMIter fiter;
2128 BMFace *f;
2129 BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
2131 continue;
2132 }
2133
2134 BMLoop *l_iter, *l_first;
2135 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
2136 do {
2138 if (!BM_elem_flag_test(l_iter->e, BM_ELEM_SELECT)) {
2139 INCF_MAYBE_ASSERT(error_count);
2140 }
2141 }
2142 } while ((l_iter = l_iter->next) != l_first);
2143 }
2144 if (error_count) {
2145 is_valid = false;
2146 }
2147 }
2148
2149 /* When vertex selection is enabled, it's possible for UV's
2150 * that don't form a selected UV edge to form a selected viewport edge.
2151 * So, it only makes sense to perform this check in edge selection mode. */
2152 if ((bm->selectmode & SCE_SELECT_VERTEX) == 0) {
2153 int &error_count = info_sub.count_uv_edge_none_selected_with_edge_selected;
2154 BLI_assert(error_count == 0);
2155 BMIter eiter;
2156
2157 BMEdge *e;
2158 BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) {
2160 continue;
2161 }
2163 continue;
2164 }
2165 if (e->l == nullptr) {
2166 continue;
2167 }
2168 bool any_loop_selected = false;
2169 BMLoop *l_iter = e->l;
2170 do {
2171 if (BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
2172 continue;
2173 }
2175 any_loop_selected = true;
2176 break;
2177 }
2178 } while ((l_iter = l_iter->radial_next) != e->l);
2179 if (any_loop_selected == false) {
2180 INCF_MAYBE_ASSERT(error_count);
2181 }
2182 }
2183 if (error_count) {
2184 is_valid = false;
2185 }
2186 }
2187
2188 return is_valid;
2189}
2190
2192{
2193 bool is_valid = true;
2194
2195 /* Vertices are flushed to edges. */
2196 {
2197 int &error_count_selected = info_sub.count_uv_edge_selected_with_any_verts_unselected;
2198 int &error_count_unselected = info_sub.count_uv_edge_unselected_with_all_verts_selected;
2199 BLI_assert(error_count_selected == 0 && error_count_unselected == 0);
2200 BMIter fiter;
2201 BMFace *f;
2202 BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
2204 continue;
2205 }
2206 BMLoop *l_iter, *l_first;
2207 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
2208 do {
2209 const bool v_curr_select = BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV);
2210 const bool v_next_select = BM_elem_flag_test(l_iter->next, BM_ELEM_SELECT_UV);
2212 if (!v_curr_select || !v_next_select) {
2213 INCF_MAYBE_ASSERT(error_count_selected);
2214 }
2215 }
2216 else {
2217 if (v_curr_select && v_next_select) {
2218 /* Only an error in with vertex selection mode. */
2220 INCF_MAYBE_ASSERT(error_count_unselected);
2221 }
2222 }
2223 }
2224 } while ((l_iter = l_iter->next) != l_first);
2225 }
2226 if (error_count_selected || error_count_unselected) {
2227 is_valid = false;
2228 }
2229 }
2230
2231 /* Vertices & edges are flushed to faces. */
2232 {
2233 int &error_count_verts_selected = info_sub.count_uv_face_selected_with_any_verts_unselected;
2234 int &error_count_verts_unselected = info_sub.count_uv_face_unselected_with_all_verts_selected;
2235
2236 int &error_count_edges_selected = info_sub.count_uv_face_selected_with_any_edges_unselected;
2237 int &error_count_edges_unselected = info_sub.count_uv_face_unselected_with_all_edges_selected;
2238
2239 BLI_assert(error_count_verts_selected == 0 && error_count_verts_unselected == 0);
2240 BLI_assert(error_count_edges_selected == 0 && error_count_edges_unselected == 0);
2241 BMIter fiter;
2242 BMFace *f;
2243 BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
2245 continue;
2246 }
2247 int uv_vert_select = 0;
2248 int uv_edge_select = 0;
2249 BMLoop *l_iter, *l_first;
2250 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
2251 do {
2252 if (BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV)) {
2253 uv_vert_select += 1;
2254 }
2255
2257 uv_edge_select += 1;
2258 }
2259 } while ((l_iter = l_iter->next) != l_first);
2260
2262 if (uv_vert_select != f->len) {
2263 INCF_MAYBE_ASSERT(error_count_verts_selected);
2264 }
2265 if (uv_edge_select != f->len) {
2266 INCF_MAYBE_ASSERT(error_count_edges_selected);
2267 }
2268 }
2269 else {
2270 /* Only an error with vertex or edge selection modes. */
2272 if (uv_vert_select == f->len) {
2273 INCF_MAYBE_ASSERT(error_count_verts_unselected);
2274 }
2275 }
2276 else if (bm->selectmode & SCE_SELECT_EDGE) {
2277 if (uv_edge_select == f->len) {
2278 INCF_MAYBE_ASSERT(error_count_edges_unselected);
2279 }
2280 }
2281 }
2282 }
2283
2284 if (error_count_verts_selected || error_count_verts_unselected) {
2285 is_valid = false;
2286 }
2287 if (error_count_edges_selected || error_count_edges_unselected) {
2288 is_valid = false;
2289 }
2290 }
2291
2292 return is_valid;
2293}
2294
2296 const int cd_loop_uv_offset,
2298{
2299 bool is_valid = true;
2300 enum {
2301 UV_IS_SELECTED = 1 << 0,
2302 UV_IS_UNSELECTED = 1 << 1,
2303 };
2304
2305 BLI_assert(cd_loop_uv_offset != -1);
2306
2307 /* Handle vertices. */
2308 {
2309 int &error_count = info_sub.count_uv_vert_non_contiguous_selected;
2310 BLI_assert(error_count == 0);
2311
2313
2314 auto loop_vert_select_test_fn = [&cd_loop_uv_offset](BMLoop *l_base) -> int {
2315 BMIter liter;
2316 BMLoop *l_other;
2317
2319
2320 int select_test = 0;
2321
2322 BM_ITER_ELEM (l_other, &liter, l_base->v, BM_LOOPS_OF_VERT) {
2323 /* Ignore all hidden. */
2324 if (BM_elem_flag_test(l_other->f, BM_ELEM_HIDDEN)) {
2325 continue;
2326 }
2327 if (BM_elem_flag_test(l_other, BM_ELEM_TAG)) {
2328 continue;
2329 }
2330 if (!BM_loop_uv_share_vert_check(l_base, l_other, cd_loop_uv_offset)) {
2331 continue;
2332 }
2333 select_test |= BM_elem_flag_test(l_other, BM_ELEM_SELECT_UV) ? UV_IS_SELECTED :
2334 UV_IS_UNSELECTED;
2335 if (select_test == (UV_IS_SELECTED | UV_IS_UNSELECTED)) {
2336 break;
2337 }
2338 }
2339 return select_test;
2340 };
2341 BMIter fiter;
2342 BMFace *f;
2343 BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
2345 continue;
2346 }
2347 BMLoop *l_iter, *l_first;
2348 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
2349 do {
2350 if (BM_elem_flag_test(l_iter, BM_ELEM_TAG)) {
2351 continue;
2352 }
2353 if (loop_vert_select_test_fn(l_iter) == (UV_IS_SELECTED | UV_IS_UNSELECTED)) {
2354 INCF_MAYBE_ASSERT(error_count);
2355 }
2356 } while ((l_iter = l_iter->next) != l_first);
2357 }
2358 if (error_count) {
2359 is_valid = false;
2360 }
2361 }
2362
2363 /* Handle edges. */
2364 {
2365 int &error_count = info_sub.count_uv_edge_non_contiguous_selected;
2366 BLI_assert(error_count == 0);
2368
2369 auto loop_edge_select_test_fn = [&cd_loop_uv_offset](BMLoop *l_base) -> int {
2371
2372 int select_test = 0;
2373 if (l_base->radial_next != l_base) {
2374 BMLoop *l_other = l_base->radial_next;
2375 do {
2376 /* Ignore all hidden. */
2377 if (BM_elem_flag_test(l_other->f, BM_ELEM_HIDDEN)) {
2378 continue;
2379 }
2380 if (BM_elem_flag_test(l_other, BM_ELEM_TAG)) {
2381 continue;
2382 }
2383 if (!BM_loop_uv_share_edge_check(l_base, l_other, cd_loop_uv_offset)) {
2384 continue;
2385 }
2386
2387 select_test |= BM_elem_flag_test(l_other, BM_ELEM_SELECT_UV_EDGE) ? UV_IS_SELECTED :
2388 UV_IS_UNSELECTED;
2389 if (select_test == (UV_IS_SELECTED | UV_IS_UNSELECTED)) {
2390 break;
2391 }
2392 } while ((l_other = l_other->radial_next) != l_base);
2393 }
2394 return select_test;
2395 };
2396 BMIter fiter;
2397 BMFace *f;
2398 BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
2400 continue;
2401 }
2402 BMLoop *l_iter, *l_first;
2403 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
2404 do {
2405 if (BM_elem_flag_test(l_iter, BM_ELEM_TAG)) {
2406 continue;
2407 }
2408 if (loop_edge_select_test_fn(l_iter) == (UV_IS_SELECTED | UV_IS_UNSELECTED)) {
2409 INCF_MAYBE_ASSERT(error_count);
2410 }
2411 } while ((l_iter = l_iter->next) != l_first);
2412 }
2413 if (error_count) {
2414 is_valid = false;
2415 }
2416 }
2417 return is_valid;
2418}
2419
2424 BMesh *bm, const int cd_loop_uv_offset, UVSelectValidateInfo_FlushAndContiguous &info_sub)
2425{
2426 bool is_valid = true;
2427
2428 /* Check isolated selection. */
2430 int &error_count = info_sub.count_uv_vert_isolated_in_edge_or_face_mode;
2431 BLI_assert(error_count == 0);
2432
2433 if (bm->selectmode & SCE_SELECT_EDGE) {
2434 /* All selected UV's must have at least one selected edge. */
2435 BMIter fiter;
2436 BMFace *f;
2437 BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
2439 continue;
2440 }
2441 BMLoop *l_iter, *l_first;
2442 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
2443 do {
2444 /* Only check selected vertices. */
2445 if (BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV)) {
2449 l_iter, BM_ELEM_SELECT_UV_EDGE, cd_loop_uv_offset))
2450 {
2451 INCF_MAYBE_ASSERT(error_count);
2452 }
2453 }
2454 } while ((l_iter = l_iter->next) != l_first);
2455 }
2456 }
2457 if (error_count) {
2458 is_valid = false;
2459 }
2460 }
2461
2462 if ((bm->selectmode & SCE_SELECT_FACE) &&
2464 {
2465 int &error_count_vert = info_sub.count_uv_vert_isolated_in_face_mode;
2466 int &error_count_edge = info_sub.count_uv_edge_isolated_in_face_mode;
2467 BLI_assert(error_count_vert == 0 && error_count_edge == 0);
2468
2469 /* All selected UV's must have at least one selected edge. */
2470 BMIter fiter;
2471 BMFace *f;
2472 BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
2474 continue;
2475 }
2476 /* If this face is selected, there is no need to search over it's verts. */
2478 continue;
2479 }
2480 BMLoop *l_iter, *l_first;
2481 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
2482 do {
2483 /* Only check selected vertices. */
2484 if (BM_elem_flag_test(l_iter, BM_ELEM_SELECT_UV)) {
2486 l_iter, BM_ELEM_SELECT_UV, cd_loop_uv_offset))
2487 {
2488 INCF_MAYBE_ASSERT(error_count_vert);
2489 }
2490 }
2491 /* Only check selected edges. */
2494 l_iter, BM_ELEM_SELECT_UV, cd_loop_uv_offset))
2495 {
2496 INCF_MAYBE_ASSERT(error_count_edge);
2497 }
2498 }
2499 } while ((l_iter = l_iter->next) != l_first);
2500 }
2501
2502 if (error_count_vert || error_count_edge) {
2503 is_valid = false;
2504 }
2505 }
2506 return is_valid;
2507}
2508
2509#undef INCF_MAYBE_ASSERT
2510#undef MAYBE_ASSERT
2511
2513 const int cd_loop_uv_offset,
2514 const bool check_sync,
2515 const bool check_flush,
2516 const bool check_contiguous,
2517 UVSelectValidateInfo *info_p)
2518{
2519 /* Correctness is as follows:
2520 *
2521 * - UV selection must match the viewport selection.
2522 * - If a vertex is selected at least one if it's UV verts must be selected.
2523 * - If an edge is selected at least one of it's UV verts must be selected.
2524 *
2525 * - UV selection must be flushed.
2526 *
2527 * Notes:
2528 * - When all vertices of a face are selected in the viewport
2529 * (and therefore the face) is selected, it's possible the UV face is *not* selected,
2530 * because the vertices in the viewport may be selected because of other selected UV's,
2531 * not part of the UV's associated with the face.
2532 *
2533 * Therefore it is possible for a viewport face to be selected
2534 * with an unselected UV face.
2535 */
2536
2537 UVSelectValidateInfo _info_fallback = {};
2538 UVSelectValidateInfo &info = info_p ? *info_p : _info_fallback;
2539
2540 bool is_valid = true;
2541 if (check_sync) {
2544 is_valid = false;
2545 }
2546 }
2547
2548 if (check_flush) {
2550 is_valid = false;
2551 }
2552 }
2553
2554 if (check_contiguous) {
2555 if (!bm_mesh_uvselect_check_contiguous(bm, cd_loop_uv_offset, info.contiguous)) {
2556 is_valid = false;
2557 }
2558 }
2559
2560 if (check_flush && check_contiguous) {
2562 {
2563 is_valid = false;
2564 }
2565 }
2566 return is_valid;
2567}
2568
2570
2571} // namespace blender
Read Blender memory allocation and freeing.
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define BM_ELEM_SELECT_UV_EDGE
#define BM_FACE_FIRST_LOOP(p)
#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_SELECT_HISTORY_BACKUP(bm)
#define BM_SELECT_HISTORY_RESTORE(bm)
#define INCF_MAYBE_ASSERT(var)
constexpr bool is_empty() const
Definition BLI_span.hh:264
#define shared
BMesh Iterators.
bool BM_loop_edge_uvselect_test(const BMLoop *l)
bool BM_loop_vert_uvselect_check_other_edge(BMLoop *l, const char hflag, const int cd_loop_uv_offset)
void BM_edge_uvselect_set_pick(BMesh *bm, BMEdge *e, bool select, const BMUVSelectPickParams &params)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BM_mesh_uvselect_mode_flush_ex(BMesh *bm, const short selectmode, const bool flush_down)
void BM_loop_edge_uvselect_set_shared(BMesh *bm, BMLoop *l, bool select, const int cd_loop_uv_offset)
bool BM_face_uvselect_test(const BMFace *f)
bool BM_loop_vert_uvselect_check_other_loop_vert(BMLoop *l, const char hflag, const int cd_loop_uv_offset)
static void bm_mesh_loop_clear_tag(BMesh *bm)
static void bm_mesh_uvselect_mode_flush_down_deselect_only(BMesh *bm, const short select_mode, const int cd_loop_uv_offset, const bool shared, const bool check_verts, const bool check_edges)
bool BM_mesh_uvselect_clear(BMesh *bm)
void BM_loop_edge_uvselect_set_noflush(BMesh *bm, BMLoop *l, bool select)
bool BM_mesh_uvselect_is_valid(BMesh *bm, const int cd_loop_uv_offset, const bool check_sync, const bool check_flush, const bool check_contiguous, UVSelectValidateInfo *info_p)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void BM_mesh_uvselect_mode_flush_only_select(BMesh *bm)
static void bm_mesh_uvselect_flush_from_mesh_sticky_location_for_edge_mode(BMesh *bm, const int cd_loop_uv_offset)
bool BM_edge_is_any_face_flag_test(const BMEdge *e, const char hflag)
void BM_mesh_uvselect_flush_from_loop_verts(BMesh *bm)
bool BM_loop_edge_uvselect_check_other_face(BMLoop *l, const char hflag, const int cd_loop_uv_offset)
void BM_mesh_elem_hflag_disable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
ATTR_WARN_UNUSED_RESULT const BMVert * v
static void bm_edge_uvselect_set_pick(BMesh *bm, BMEdge *e, const bool select, const BMUVSelectPickParams &uv_pick_params, const bool caller_handles_face_mode)
void BM_mesh_uvselect_set_elem_shared(BMesh *bm, bool select, const int cd_loop_uv_offset, const Span< BMLoop * > loop_verts, const Span< BMLoop * > loop_edges, const Span< BMFace * > faces)
void BM_mesh_uvselect_flush_from_faces_only_deselect(BMesh *bm)
void BM_face_uvselect_set_shared(BMesh *bm, BMFace *f, bool select, const int cd_loop_uv_offset)
void BM_mesh_uvselect_flush_from_faces(BMesh *bm, bool flush_down)
static void bm_vert_uvselect_set_pick(BMesh *bm, BMVert *v, const bool select, const BMUVSelectPickParams &, bool caller_handles_edge_or_face_mode)
void BM_vert_uvselect_set_pick(BMesh *bm, BMVert *v, bool select, const BMUVSelectPickParams &params)
void BM_mesh_uvselect_flush_from_loop_verts_only_deselect(BMesh *bm)
bool BM_loop_uv_share_vert_check(const BMLoop *l_a, const BMLoop *l_b, const int cd_loop_uv_offset)
bool BM_loop_vert_uvselect_check_other_face(BMLoop *l, const char hflag, const int cd_loop_uv_offset)
void BM_mesh_uvselect_mode_flush_update(BMesh *bm, const short selectmode_old, const short selectmode_new, const int cd_loop_uv_offset)
void BM_face_select_set_noflush(BMesh *bm, BMFace *f, const bool select)
void BM_mesh_uvselect_flush_from_loop_edges_only_select(BMesh *bm)
bool BM_loop_vert_uvselect_check_other_loop_edge(BMLoop *l, const char hflag, const int cd_loop_uv_offset)
void BM_mesh_uvselect_sync_from_mesh_sticky_disabled(BMesh *bm)
void BM_loop_vert_uvselect_set_noflush(BMesh *bm, BMLoop *l, bool select)
static void bm_mesh_uvselect_flush_from_mesh_sticky_vert_for_vert_mode(BMesh *bm)
static bool bm_mesh_uvselect_check_viewport_sync(BMesh *bm, UVSelectValidateInfo_Sync &info_sub)
void BM_mesh_uvselect_sync_from_mesh_sticky_location(BMesh *bm, const int cd_loop_uv_offset)
static void bm_mesh_uvselect_disable_all(BMesh *bm)
void BM_face_select_set(BMesh *bm, BMFace *f, const bool select)
Select Face.
static void bm_face_uvselect_set_pick(BMesh *bm, BMFace *f, const bool select, const BMUVSelectPickParams &uv_pick_params)
static void bm_mesh_uvselect_flush_from_mesh_sticky_location_for_vert_mode(BMesh *bm, const int)
static void bm_mesh_uvselect_flush_from_mesh_sticky_vert_for_edge_mode(BMesh *bm)
static void bm_mesh_uvselect_flush_from_mesh_sticky_vert_for_face_mode(BMesh *bm)
void BM_mesh_uvselect_flush_from_faces_only_select(BMesh *bm)
void BM_mesh_uvselect_flush_from_loop_edges(BMesh *bm, bool flush_down)
MINLINE unsigned short highest_order_bit_s(unsigned short n)
static bool bm_mesh_uvselect_check_flush(BMesh *bm, UVSelectValidateInfo_Flush &info_sub)
static void bm_mesh_uvselect_flush_from_mesh_sticky_location_for_face_mode(BMesh *bm, const int cd_loop_uv_offset)
void BM_vert_select_set(BMesh *bm, BMVert *v, const bool select)
Select Vert.
void BM_mesh_uvselect_flush_from_loop_verts_only_select(BMesh *bm)
void BM_face_uvselect_set_noflush(BMesh *bm, BMFace *f, bool select)
void BM_select_history_validate(BMesh *bm)
void BM_mesh_uvselect_flush_post_subdivide(BMesh *bm, const int cd_loop_uv_offset)
void BM_loop_vert_uvselect_set_shared(BMesh *bm, BMLoop *l, bool select, const int cd_loop_uv_offset)
void BM_face_uvselect_set_pick(BMesh *bm, BMFace *f, bool select, const BMUVSelectPickParams &params)
bool BM_loop_edge_uvselect_check_other_loop_edge(BMLoop *l, const char hflag, const int cd_loop_uv_offset)
bool BM_face_uvselect_check_edges_all(BMFace *f)
void BM_mesh_uvselect_mode_flush(BMesh *bm)
bool BM_loop_vert_uvselect_test(const BMLoop *l)
void BM_mesh_uvselect_flush_from_verts(BMesh *bm, const bool select)
static bool bm_mesh_uvselect_check_flush_and_contiguous(BMesh *bm, const int cd_loop_uv_offset, UVSelectValidateInfo_FlushAndContiguous &info_sub)
void BM_mesh_uvselect_sync_from_mesh_sticky_vert(BMesh *bm)
bool BM_loop_uv_share_edge_check(const BMLoop *l_a, const BMLoop *l_b, const int cd_loop_uv_offset)
BLI_INLINE BMEdge * bmesh_disk_edge_next(const BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BM_mesh_select_flush_from_verts(BMesh *bm, const bool select)
static bool bm_mesh_uvselect_check_contiguous(BMesh *bm, const int cd_loop_uv_offset, UVSelectValidateInfo_Contiguous &info_sub)
void BM_mesh_uvselect_flush_from_loop_edges_only_deselect(BMesh *bm)
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)
void BM_face_uvselect_set(BMesh *bm, BMFace *f, bool select)
@ BM_ELEM_SELECT_UV
void BM_loop_edge_uvselect_set(BMesh *bm, BMLoop *l, bool select)
void BM_mesh_uvselect_flush_shared_only_select(BMesh *bm, const int cd_loop_uv_offset)
void BM_mesh_uvselect_flush_shared_only_deselect(BMesh *bm, const int cd_loop_uv_offset)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void BM_mesh_uvselect_sync_to_mesh(BMesh *bm)
void BM_edge_select_set(BMesh *bm, BMEdge *e, const bool select)
Select Edge.
struct BMLoop * l
struct BMLoop * next
struct BMLoop * prev
struct BMEdge * e
struct BMVert * v
struct BMLoop * radial_next
struct BMFace * f
UVSelectValidateInfo_Contiguous contiguous
UVSelectValidateInfo_Sync sync
UVSelectValidateInfo_Flush flush
UVSelectValidateInfo_FlushAndContiguous flush_contiguous
struct BMLoop * radial_next