Blender V5.3
editmesh_utils.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_key_types.h"
14#include "DNA_mesh_types.h"
15#include "DNA_object_types.h"
16
17#include "BLI_array.hh"
18#include "BLI_kdtree.hh"
19#include "BLI_listbase.hh"
20#include "BLI_math_matrix_c.hh"
21#include "BLI_math_vector_c.hh"
22
23#include "BKE_attribute.h"
24#include "BKE_context.hh"
25#include "BKE_customdata.hh"
26#include "BKE_editmesh.hh"
27#include "BKE_editmesh_bvh.hh"
28#include "BKE_layer.hh"
29#include "BKE_mesh.hh"
30#include "BKE_mesh_mapping.hh"
31#include "BKE_report.hh"
32
33#include "DEG_depsgraph.hh"
34
35#include "WM_api.hh"
36#include "WM_types.hh"
37
38#include "ED_mesh.hh"
39#include "ED_screen.hh"
41#include "ED_uvedit.hh"
42#include "ED_view3d.hh"
43
44#include "mesh_intern.hh" /* own include */
45
46namespace blender {
47
48/* -------------------------------------------------------------------- */
51
52/* Mesh backup implementation.
53 * This would greatly benefit from some sort of binary diffing
54 * just as the undo stack would.
55 * So leaving this as an interface for further work */
56
58{
59 BMBackup backup;
60 backup.bmcopy = BM_mesh_copy(bm);
61 return backup;
62}
63
64void EDBM_redo_state_restore(BMBackup *backup, BMEditMesh *em, BMesh *bm, bool recalc_looptris)
65{
67 BMesh *tmpbm = BM_mesh_copy(backup->bmcopy);
68 *bm = *tmpbm;
69 MEM_delete(tmpbm);
70 tmpbm = nullptr;
71
72 if (recalc_looptris) {
74 }
75}
76
78 BMEditMesh *em,
79 BMesh *bm,
80 bool recalc_looptris)
81{
83 *bm = *backup->bmcopy;
84 MEM_delete(backup->bmcopy);
85 backup->bmcopy = nullptr;
86 if (recalc_looptris) {
88 }
89}
90
92{
93 if (backup->bmcopy) {
95 MEM_delete(backup->bmcopy);
96 }
97}
98
100
101/* -------------------------------------------------------------------- */
104
105bool EDBM_op_init(BMesh *bm, BMOperator *bmop, wmOperator *op, const char *fmt, ...)
106{
107 va_list list;
108
109 va_start(list, fmt);
110
111 if (!BMO_op_vinitf(bm, bmop, BMO_FLAG_DEFAULTS, fmt, list)) {
112 BKE_reportf(op->reports, RPT_ERROR, "Parse error in %s", __func__);
113 va_end(list);
114 return false;
115 }
116
117 va_end(list);
118
119 return true;
120}
121
122bool EDBM_op_finish(BMesh *bm, BMOperator *bmop, wmOperator *op, const bool do_report)
123{
124 const char *errmsg;
125
126#ifndef NDEBUG
127 struct StatePrev {
128 int verts_len, edges_len, loops_len, faces_len;
129 };
130 StatePrev em_state_prev = {
131 bm->totvert,
132 bm->totedge,
133 bm->totloop,
134 bm->totface,
135 };
136#endif
137
138 BMO_op_finish(bm, bmop);
139
140 bool changed = false;
141 bool changed_was_set = false;
142
143 eBMOpErrorLevel level;
144 while (BMO_error_pop(bm, &errmsg, nullptr, &level)) {
145 eReportType type = RPT_INFO;
146 switch (level) {
147 case BMO_ERROR_CANCEL: {
148 changed_was_set = true;
149 break;
150 }
151 case BMO_ERROR_WARN: {
152 type = RPT_WARNING;
153 changed_was_set = true;
154 changed = true;
155 break;
156 }
157 case BMO_ERROR_FATAL: {
158 type = RPT_ERROR;
159 changed_was_set = true;
160 changed = true;
161 break;
162 }
163 }
164
165 if (do_report) {
166 BKE_report(op->reports, type, errmsg);
167 }
168 }
169 if (changed_was_set == false) {
170 changed = true;
171 }
172
173#ifndef NDEBUG
174 if (changed == false) {
176 (em_state_prev.verts_len == bm->totvert) && (em_state_prev.edges_len == bm->totedge) &&
177 (em_state_prev.loops_len == bm->totloop) && (em_state_prev.faces_len == bm->totface));
178 }
179#endif
180
181 return changed;
182}
183
184bool EDBM_op_callf(BMesh *bm, wmOperator *op, const char *fmt, ...)
185{
186 BMOperator bmop;
187 va_list list;
188
189 va_start(list, fmt);
190
191 if (!BMO_op_vinitf(bm, &bmop, BMO_FLAG_DEFAULTS, fmt, list)) {
192 BKE_reportf(op->reports, RPT_ERROR, "Parse error in %s", __func__);
193 va_end(list);
194 return false;
195 }
196
197 BMO_op_exec(bm, &bmop);
198
199 va_end(list);
200 return EDBM_op_finish(bm, &bmop, op, true);
201}
202
204 wmOperator *op,
205 const char *select_slot_out,
206 const bool select_extend,
207 const char *fmt,
208 va_list list)
209{
210 BMOperator bmop;
211
212 if (!BMO_op_vinitf(bm, &bmop, BMO_FLAG_DEFAULTS, fmt, list)) {
213 BKE_reportf(op->reports, RPT_ERROR, "Parse error in %s", __func__);
214 return false;
215 }
216
217 BMO_op_exec(bm, &bmop);
218
219 BMOpSlot *slot_select_out = BMO_slot_get(bmop.slots_out, select_slot_out);
220 char hflag = slot_select_out->slot_subtype.elem & BM_ALL_NOLOOP;
221 BLI_assert(hflag != 0);
222
223 if (select_extend == false) {
225 }
226
227 BMO_slot_buffer_hflag_enable(bm, bmop.slots_out, select_slot_out, hflag, BM_ELEM_SELECT, true);
228
229 return EDBM_op_finish(bm, &bmop, op, true);
230}
231
233 wmOperator *op,
234 const char *select_slot_out,
235 const bool select_extend,
236 const char *fmt,
237 ...)
238{
239 va_list list;
240 va_start(list, fmt);
241 const bool result = EDBM_op_vcall_and_selectf(bm, op, select_slot_out, select_extend, fmt, list);
242 va_end(list);
243 return result;
244}
245
246bool EDBM_op_call_silentf(BMesh *bm, const char *fmt, ...)
247{
248 BMOperator bmop;
249 va_list list;
250
251 va_start(list, fmt);
252
253 if (!BMO_op_vinitf(bm, &bmop, BMO_FLAG_DEFAULTS, fmt, list)) {
254 va_end(list);
255 return false;
256 }
257
258 BMO_op_exec(bm, &bmop);
259
260 va_end(list);
261 return EDBM_op_finish(bm, &bmop, nullptr, false);
262}
263
265
266/* -------------------------------------------------------------------- */
271
283{
284 const Mesh *mesh = id_cast<const Mesh *>(ob->data);
285 if ((ob->shapenr == 0) && (mesh->key && !mesh->key->block.is_empty())) [[unlikely]] {
286 return 1;
287 }
288 return ob->shapenr;
289}
290
291void EDBM_mesh_make(Object *ob, const int select_mode, const bool add_key_index)
292{
293 Mesh *mesh = id_cast<Mesh *>(ob->data);
294 EDBM_mesh_make_from_mesh(ob, mesh, select_mode, add_key_index);
295}
296
298 Mesh *src_mesh,
299 const int select_mode,
300 const bool add_key_index)
301{
302 Mesh *mesh = id_cast<Mesh *>(ob->data);
303 BMeshCreateParams create_params{};
304 create_params.use_toolflags = true;
305 /* Clamp the index, so the behavior of enter & exit edit-mode matches, see #43998. */
306 const int shapenr = object_shapenr_basis_index_ensured(ob);
307
308 AttributeOwner owner = AttributeOwner::from_id(const_cast<ID *>(&mesh->id));
309 const std::string attributes_active_name = BKE_attributes_active_name_get(owner).value_or("");
310
311 BMesh *bm = BKE_mesh_to_bmesh(src_mesh, shapenr, add_key_index, &create_params);
312
313 if (mesh->runtime->edit_mesh) {
314 /* this happens when switching shape keys */
315 EDBM_mesh_free_data(mesh->runtime->edit_mesh.get());
316 mesh->runtime->edit_mesh.reset();
317 }
318
319 /* Executing operators re-tessellates,
320 * so we can avoid doing here but at some point it may need to be added back. */
321 mesh->runtime->edit_mesh = std::make_shared<BMEditMesh>();
322 mesh->runtime->edit_mesh->bm = bm;
323
324 mesh->runtime->edit_mesh->selectmode = bm->selectmode = select_mode;
325 mesh->runtime->edit_mesh->mat_nr = (ob->actcol > 0) ? ob->actcol - 1 : 0;
326
327 /* we need to flush selection because the mode may have changed from when last in editmode */
328 EDBM_selectmode_flush(bm, select_mode);
329
331 if (select_mode & (SCE_SELECT_VERTEX | SCE_SELECT_EDGE)) {
332 /* Flush the UV selection too, so it matches the mesh. */
334 }
335 else {
336 /* The select mode may also have changed to face only, where a separate UV selection can't
337 * be represented, matching what #EDBM_selectmode_set does when switching mode in edit-mode.
338 */
340 }
341 }
342
343 /* Conversion to edit-mesh may have modified the attribute layers.
344 * Re-resolve the active attribute by name to keep it stable. */
345 if (!attributes_active_name.empty()) {
346 BLI_assert(bke::allow_procedural_attribute_access(attributes_active_name));
347 BKE_attributes_active_set(owner, attributes_active_name);
348 }
349 else {
350 BLI_assert(mesh->attributes_active_index == -1);
351 mesh->attributes_active_index = -1;
352 }
353}
354
355void EDBM_mesh_load_ex(Main *bmain, Object *ob, bool free_data)
356{
357 Mesh *mesh = id_cast<Mesh *>(ob->data);
359
360 /* Workaround for #42360, 'ob->shapenr' should be 1 in this case.
361 * however this isn't synchronized between objects at the moment. */
362 if ((ob->shapenr == 0) && (object_shapenr_basis_index_ensured(ob) > 0)) [[unlikely]] {
363 bm->shapenr = 1;
364 }
365
366 BMeshToMeshParams params{};
367 params.calc_object_remap = true;
368 params.update_shapekey_indices = !free_data;
369 BM_mesh_bm_to_me(bmain, bm, mesh, &params);
370}
371
372void EDBM_mesh_load(Main *bmain, Object *ob)
373{
374 EDBM_mesh_load_ex(bmain, ob, true);
375}
376
378{
379 /* These tables aren't used yet, so it's not strictly necessary
380 * to 'end' them but if someone tries to start using them,
381 * having these in place will save a lot of pain. */
384
386}
387
389
390/* -------------------------------------------------------------------- */
393
395{
396 Scene *scene = CTX_data_scene(C);
397 Object *obedit = CTX_data_edit_object(C);
399
400 if (!em) {
401 return;
402 }
403
404 scene->toolsettings->selectmode = em->selectmode;
405
406 /* Request redraw of header buttons (to show new select mode) */
408}
409
410void EDBM_selectmode_flush_ex(BMesh *bm, const short selectmode)
411{
413}
414
415void EDBM_selectmode_flush(BMesh *bm, const short selectmode)
416{
417 EDBM_selectmode_flush_ex(bm, selectmode);
418}
419
420void EDBM_select_flush_from_verts(BMesh *bm, const short selectmode, const bool select)
421{
422 /* Function below doesn't use. just do this to keep the values in sync. */
423 bm->selectmode = selectmode;
425}
426
427void EDBM_select_more(BMesh *bm, const short selectmode, const bool use_face_step)
428{
429 BMOperator bmop;
430 const bool use_faces = (selectmode == SCE_SELECT_FACE);
431
433 &bmop,
435 "region_extend geom=%hvef use_contract=%b use_faces=%b use_face_step=%b",
437 false,
438 use_faces,
439 use_face_step);
440 BMO_op_exec(bm, &bmop);
441 /* Don't flush selection in edge/vertex mode. */
443 bm, bmop.slots_out, "geom.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, use_faces ? true : false);
444 BMO_op_finish(bm, &bmop);
445
446 EDBM_selectmode_flush(bm, selectmode);
448}
449
450void EDBM_select_less(BMesh *bm, const short selectmode, const bool use_face_step)
451{
452 BMOperator bmop;
453 const bool use_faces = (selectmode == SCE_SELECT_FACE);
454
456 &bmop,
458 "region_extend geom=%hvef use_contract=%b use_faces=%b use_face_step=%b",
460 true,
461 use_faces,
462 use_face_step);
463 BMO_op_exec(bm, &bmop);
464 /* Don't flush selection in edge/vertex mode. */
466 bm, bmop.slots_out, "geom.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, use_faces ? true : false);
467 BMO_op_finish(bm, &bmop);
468
469 EDBM_selectmode_flush(bm, selectmode);
471
472 /* only needed for select less, ensure we don't have isolated elements remaining */
474}
475
476void EDBM_flag_disable_all(BMesh *bm, const char hflag)
477{
479
480 /* Keep this as there is no need to maintain UV selection when all are disabled. */
481 if (hflag & BM_ELEM_SELECT) {
483 }
484}
485
486void EDBM_flag_enable_all(BMesh *bm, const char hflag)
487{
489
490 /* Keep this as there is no need to maintain UV selection when all are enabled. */
491 if (hflag & BM_ELEM_SELECT) {
493 }
494}
495
500
502
503/* -------------------------------------------------------------------- */
506
507UvVertMap *BM_uv_vert_map_create(BMesh *bm, const bool use_select, const bool respect_hide)
508{
509 /* NOTE: delimiting on alternate face-winding was once supported and could be useful
510 * in some cases. If this is need see: D17137 to restore support. */
511 BMVert *ev;
512 BMFace *efa;
513 BMLoop *l;
514 BMIter iter, liter;
515 uint a;
516 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
517
519
520 const int totverts = bm->totvert;
521 int totuv = 0;
522
523 /* generate UvMapVert array */
524 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
525 if (use_select && !BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
526 continue;
527 }
528 if (respect_hide && BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
529 continue;
530 }
531 totuv += efa->len;
532 }
533
534 if (totuv == 0) {
535 return nullptr;
536 }
537 UvVertMap *vmap = MEM_new_zeroed<UvVertMap>("UvVertMap");
538 if (!vmap) {
539 return nullptr;
540 }
541
542 vmap->vert = MEM_new_array_zeroed<UvMapVert *>(totverts, "UvMapVert_pt");
543 UvMapVert *buf = vmap->buf = MEM_new_array_zeroed<UvMapVert>(totuv, "UvMapVert");
544
545 if (!vmap->vert || !vmap->buf) {
547 return nullptr;
548 }
549
550 BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, a) {
551 if (use_select && !BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
552 continue;
553 }
554 if (respect_hide && BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
555 continue;
556 }
557 int i;
558 BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
559 buf->loop_of_face_index = i;
560 buf->face_index = a;
561 buf->separate = false;
562
563 buf->next = vmap->vert[BM_elem_index_get(l->v)];
564 vmap->vert[BM_elem_index_get(l->v)] = buf;
565 buf++;
566 }
567 }
568
569 /* sort individual uvs for each vert */
570 BM_ITER_MESH_INDEX (ev, &iter, bm, BM_VERTS_OF_MESH, a) {
571 UvMapVert *newvlist = nullptr, *vlist = vmap->vert[a];
572 UvMapVert *iterv, *v, *lastv, *next;
573 const float *uv, *uv2;
574
575 while (vlist) {
576 v = vlist;
577 vlist = vlist->next;
578 v->next = newvlist;
579 newvlist = v;
580
581 efa = BM_face_at_index(bm, v->face_index);
582
583 l = static_cast<BMLoop *>(
584 BM_iter_at_index(bm, BM_LOOPS_OF_FACE, efa, v->loop_of_face_index));
585 uv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
586
587 lastv = nullptr;
588 iterv = vlist;
589
590 while (iterv) {
591 next = iterv->next;
592 efa = BM_face_at_index(bm, iterv->face_index);
593 l = static_cast<BMLoop *>(
595 uv2 = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
596
597 if (compare_v2v2(uv2, uv, STD_UV_CONNECT_LIMIT)) {
598 if (lastv) {
599 lastv->next = next;
600 }
601 else {
602 vlist = next;
603 }
604 iterv->next = newvlist;
605 newvlist = iterv;
606 }
607 else {
608 lastv = iterv;
609 }
610
611 iterv = next;
612 }
613
614 newvlist->separate = true;
615 }
616
617 vmap->vert[a] = newvlist;
618 }
619
620 return vmap;
621}
622
624{
625 return vmap->vert[v];
626}
627
629{
630 if (element_map->head_table) {
631 return element_map->head_table;
632 }
633
634 /* For each UvElement, locate the "separate" UvElement that precedes it in the linked list. */
636 __func__);
637 UvElement **head_table = element_map->head_table;
638 for (int i = 0; i < element_map->total_uvs; i++) {
639 UvElement *head = element_map->storage + i;
640 if (head->separate) {
641 UvElement *element = head;
642 while (element) {
643 head_table[element - element_map->storage] = head;
644 element = element->next;
645 if (element && element->separate) {
646 break;
647 }
648 }
649 }
650 }
651 return element_map->head_table;
652}
653
655{
656 if (!element_map->unique_index_table) {
657 element_map->unique_index_table = MEM_new_array_zeroed<int>(element_map->total_uvs, __func__);
658
659 int j = 0;
660 for (int i = 0; i < element_map->total_uvs; i++) {
661 UvElement *element = element_map->storage + i;
662 if (!element->separate) {
663 continue;
664 }
665 BLI_assert(0 <= j);
666 BLI_assert(j < element_map->total_unique_uvs);
667 while (element) {
668 element_map->unique_index_table[element - element_map->storage] = j;
669 element = element->next;
670 if (!element || element->separate) {
671 break;
672 }
673 }
674 j++;
675 }
676 BLI_assert(j == element_map->total_unique_uvs);
677 }
678
679 return element_map->unique_index_table;
680}
681
683{
684 int *unique_index = BM_uv_element_map_ensure_unique_index(element_map);
685 int index = child - element_map->storage;
686 BLI_assert(0 <= index);
687 BLI_assert(index < element_map->total_uvs);
688 return unique_index[index];
689}
690
691#define INVALID_ISLAND uint(-1)
692
693static void bm_uv_assign_island(UvElementMap *element_map,
695 int nisland,
696 uint *map,
697 UvElement *islandbuf,
698 int islandbufsize)
699{
700 element->island = nisland;
701 map[element - element_map->storage] = islandbufsize;
702
703 /* Copy *element to islandbuf[islandbufsize]. */
704 islandbuf[islandbufsize].l = element->l;
705 islandbuf[islandbufsize].separate = element->separate;
706 islandbuf[islandbufsize].loop_of_face_index = element->loop_of_face_index;
707 islandbuf[islandbufsize].island = element->island;
708 islandbuf[islandbufsize].flag = element->flag;
709}
710
712 const Scene *scene,
713 const BMesh *bm,
714 UvElement *islandbuf,
715 uint *map,
716 bool uv_selected,
717 const BMUVOffsets &offsets)
718{
720
721 int total_uvs = element_map->total_uvs;
722
723 /* Depth first search the graph, building islands as we go. */
724 int nislands = 0;
725 int islandbufsize = 0;
726 int stack_upper_bound = total_uvs;
727 UvElement **stack_uv = MEM_new_array_uninitialized<UvElement *>(stack_upper_bound, __func__);
728 int stacksize_uv = 0;
729 for (int i = 0; i < total_uvs; i++) {
730 UvElement *element = element_map->storage + i;
731 if (element->island != INVALID_ISLAND) {
732 /* Unique UV (element and all its children) are already part of an island. */
733 continue;
734 }
735
736 /* Create a new island, i.e. nislands++. */
737
738 BLI_assert(element->separate); /* Ensure we're the head of this unique UV. */
739
740 /* Seed the graph search. */
741 stack_uv[stacksize_uv++] = element;
742 while (element) {
743 bm_uv_assign_island(element_map, element, nislands, map, islandbuf, islandbufsize++);
744 element = element->next;
745 if (element && element->separate) {
746 break;
747 }
748 }
749
750 /* Traverse the graph. */
751 while (stacksize_uv) {
752 BLI_assert(stacksize_uv < stack_upper_bound);
753 element = stack_uv[--stacksize_uv];
754 while (element) {
755
756 /* Scan forwards around the BMFace that contains element->l. */
757 if (!uv_selected || uvedit_edge_select_test(scene, bm, element->l, offsets)) {
758 UvElement *next = BM_uv_element_get(element_map, element->l->next);
759 if (next && next->island == INVALID_ISLAND) {
760 UvElement *tail = element_map->head_table[next - element_map->storage];
761 stack_uv[stacksize_uv++] = tail;
762 while (tail) {
763 bm_uv_assign_island(element_map, tail, nislands, map, islandbuf, islandbufsize++);
764 tail = tail->next;
765 if (tail && tail->separate) {
766 break;
767 }
768 }
769 }
770 }
771
772 /* Scan backwards around the BMFace that contains element->l. */
773 if (!uv_selected || uvedit_edge_select_test(scene, bm, element->l->prev, offsets)) {
774 UvElement *prev = BM_uv_element_get(element_map, element->l->prev);
775 if (prev && prev->island == INVALID_ISLAND) {
776 UvElement *tail = element_map->head_table[prev - element_map->storage];
777 stack_uv[stacksize_uv++] = tail;
778 while (tail) {
779 bm_uv_assign_island(element_map, tail, nislands, map, islandbuf, islandbufsize++);
780 tail = tail->next;
781 if (tail && tail->separate) {
782 break;
783 }
784 }
785 }
786 }
787
788 /* The same for all the UvElements in this unique UV. */
789 element = element->next;
790 if (element && element->separate) {
791 break;
792 }
793 }
794 }
795 nislands++;
796 }
797 BLI_assert(islandbufsize == total_uvs);
798
799 MEM_SAFE_DELETE(stack_uv);
800 MEM_SAFE_DELETE(element_map->head_table);
801
802 return nislands;
803}
804
805static void bm_uv_build_islands(UvElementMap *element_map,
806 BMesh *bm,
807 const Scene *scene,
808 bool uv_selected)
809{
810 int totuv = element_map->total_uvs;
811 int nislands = 0;
812 int islandbufsize = 0;
813
814 /* map holds the map from current vmap->buf to the new, sorted map */
815 uint *map = MEM_new_array_uninitialized<uint>(totuv, __func__);
817 UvElement *islandbuf = MEM_new_array_zeroed<UvElement>(totuv, __func__);
818 /* Island number for BMFaces. */
819 int *island_number = MEM_new_array_zeroed<int>(bm->totface, __func__);
820 std::fill_n(island_number, bm->totface, INVALID_ISLAND);
821
822 const BMUVOffsets uv_offsets = BM_uv_map_offsets_get(bm);
823
824 const bool use_uv_edge_connectivity = scene->toolsettings->uv_flag & UV_FLAG_SELECT_SYNC ?
827 if (use_uv_edge_connectivity) {
829 element_map, scene, bm, islandbuf, map, uv_selected, uv_offsets);
830 islandbufsize = totuv;
831 }
832
833 for (int i = 0; i < totuv; i++) {
834 if (element_map->storage[i].island == INVALID_ISLAND) {
835 int stacksize = 0;
836 element_map->storage[i].island = nislands;
837 stack[0] = element_map->storage[i].l->f;
838 island_number[BM_elem_index_get(stack[0])] = nislands;
839 stacksize = 1;
840
841 while (stacksize > 0) {
842 BMFace *efa = stack[--stacksize];
843
844 BMLoop *l;
845 BMIter liter;
846 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
847 if (uv_selected && !uvedit_uv_select_test(scene, bm, l, uv_offsets)) {
848 continue;
849 }
850
851 UvElement *initelement = element_map->vertex[BM_elem_index_get(l->v)];
852
853 for (UvElement *element = initelement; element; element = element->next) {
854 if (element->separate) {
855 initelement = element;
856 }
857
858 if (element->l->f == efa) {
859 /* found the uv corresponding to our face and vertex.
860 * Now fill it to the buffer */
861 bm_uv_assign_island(element_map, element, nislands, map, islandbuf, islandbufsize++);
862
863 for (element = initelement; element; element = element->next) {
864 if (element->separate && element != initelement) {
865 break;
866 }
867
868 if (island_number[BM_elem_index_get(element->l->f)] == INVALID_ISLAND) {
869 stack[stacksize++] = element->l->f;
870 island_number[BM_elem_index_get(element->l->f)] = nislands;
871 }
872 }
873 break;
874 }
875 }
876 }
877 }
878
879 nislands++;
880 }
881 }
882
883 MEM_SAFE_DELETE(island_number);
884
885 /* remap */
886 for (int i = 0; i < bm->totvert; i++) {
887 /* important since we may do selection only. Some of these may be nullptr */
888 if (element_map->vertex[i]) {
889 element_map->vertex[i] = &islandbuf[map[element_map->vertex[i] - element_map->storage]];
890 }
891 }
892
893 element_map->island_indices = MEM_new_array_zeroed<int>(nislands, __func__);
894 element_map->island_total_uvs = MEM_new_array_zeroed<int>(nislands, __func__);
895 element_map->island_total_unique_uvs = MEM_new_array_zeroed<int>(nislands, __func__);
896 int j = 0;
897 for (int i = 0; i < totuv; i++) {
898 UvElement *next = element_map->storage[i].next;
899 islandbuf[map[i]].next = next ? &islandbuf[map[next - element_map->storage]] : nullptr;
900
901 if (islandbuf[i].island != j) {
902 j++;
903 element_map->island_indices[j] = i;
904 }
905 BLI_assert(islandbuf[i].island == j);
906 element_map->island_total_uvs[j]++;
907 if (islandbuf[i].separate) {
908 element_map->island_total_unique_uvs[j]++;
909 }
910 }
911
912 MEM_SAFE_DELETE(element_map->storage);
913 element_map->storage = islandbuf;
914 islandbuf = nullptr;
915 element_map->total_islands = nislands;
916 MEM_SAFE_DELETE(stack);
917 MEM_SAFE_DELETE(map);
918}
919
921static bool loop_uv_match(BMLoop *loop,
922 const float luv_a[2],
923 const float luv_b[2],
924 int cd_loop_uv_offset)
925{
926 const float *luv_c = BM_ELEM_CD_GET_FLOAT_P(loop, cd_loop_uv_offset);
927 const float *luv_d = BM_ELEM_CD_GET_FLOAT_P(loop->next, cd_loop_uv_offset);
928 return compare_v2v2(luv_a, luv_c, STD_UV_CONNECT_LIMIT) &&
929 compare_v2v2(luv_b, luv_d, STD_UV_CONNECT_LIMIT);
930}
931
951 const float luv_anchor[2],
952 const float luv_fan[2],
953 const BMLoop *needle,
954 Set<const BMEdge *> &visited,
955 const int cd_loop_uv_offset)
956{
957 BMVert *anchor = needle->v;
958 BLI_assert(edge->v1 == anchor || edge->v2 == anchor);
959
960 if (BM_elem_flag_test(edge, BM_ELEM_SEAM)) {
961 return false; /* Edge is a seam, don't traverse. */
962 }
963
964 if (!visited.add(edge)) {
965 return false; /* Already visited. */
966 }
967
968 BMLoop *loop;
969 BMIter liter;
970 BM_ITER_ELEM (loop, &liter, edge, BM_LOOPS_OF_EDGE) {
971 if (loop->v == anchor) {
972 if (!loop_uv_match(loop, luv_anchor, luv_fan, cd_loop_uv_offset)) {
973 continue; /* `loop` is disjoint in UV space. */
974 }
975
976 if (loop == needle) {
977 return true; /* Success. */
978 }
979
980 const float *luv_far = BM_ELEM_CD_GET_FLOAT_P(loop->prev, cd_loop_uv_offset);
982 loop->prev->e, luv_anchor, luv_far, needle, visited, cd_loop_uv_offset))
983 {
984 return true;
985 }
986 }
987 else {
988 BLI_assert(loop->next->v == anchor);
989 if (!loop_uv_match(loop, luv_fan, luv_anchor, cd_loop_uv_offset)) {
990 continue; /* `loop` is disjoint in UV space. */
991 }
992
993 if (loop->next == needle) {
994 return true; /* Success. */
995 }
996
997 const float *luv_far = BM_ELEM_CD_GET_FLOAT_P(loop->next->next, cd_loop_uv_offset);
999 loop->next->e, luv_anchor, luv_far, needle, visited, cd_loop_uv_offset))
1000 {
1001 return true;
1002 }
1003 }
1004 }
1005
1006 return false;
1007}
1008
1015static bool seam_connected(BMLoop *loop_a,
1016 BMLoop *loop_b,
1017 Set<const BMEdge *> &visited,
1018 int cd_loop_uv_offset)
1019{
1020 BLI_assert(loop_a && loop_b);
1021 BLI_assert(loop_a != loop_b);
1022 BLI_assert(loop_a->v == loop_b->v);
1023
1024 visited.clear();
1025
1026 const float *luv_anchor = BM_ELEM_CD_GET_FLOAT_P(loop_a, cd_loop_uv_offset);
1027 const float *luv_next_fan = BM_ELEM_CD_GET_FLOAT_P(loop_a->next, cd_loop_uv_offset);
1029 loop_a->e, luv_anchor, luv_next_fan, loop_b, visited, cd_loop_uv_offset);
1030 if (!result) {
1031 /* Search around `loop_a` in the opposite direction, as one of the edges may be delimited by
1032 * a boundary, seam or disjoint UV, or itself be one of these. See: #103670, #103787. */
1033 const float *luv_prev_fan = BM_ELEM_CD_GET_FLOAT_P(loop_a->prev, cd_loop_uv_offset);
1035 loop_a->prev->e, luv_anchor, luv_prev_fan, loop_b, visited, cd_loop_uv_offset);
1036 }
1037
1038 return result;
1039}
1040
1042 const Scene *scene,
1043 const bool uv_selected,
1044 const bool use_winding,
1045 const bool use_seams,
1046 const bool do_islands)
1047{
1048 /* In uv sync selection, all UVs (from unhidden geometry) are visible. */
1049 const bool face_selected = !(scene->toolsettings->uv_flag & UV_FLAG_SELECT_SYNC);
1050
1051 BMVert *ev;
1052 BMFace *efa;
1053 BMIter iter, liter;
1054
1055 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
1056 if (offsets.uv < 0) {
1057 return nullptr;
1058 }
1059
1061
1062 /* Count total uvs. */
1063 int totuv = 0;
1064 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
1066 continue;
1067 }
1068
1069 if (face_selected && !BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
1070 continue;
1071 }
1072
1073 if (!uv_selected) {
1074 totuv += efa->len;
1075 }
1076 else {
1077 BMLoop *l;
1078 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
1079 if (uvedit_uv_select_test(scene, bm, l, offsets)) {
1080 totuv++;
1081 }
1082 }
1083 }
1084 }
1085
1086 if (totuv == 0) {
1087 return nullptr;
1088 }
1089
1090 UvElementMap *element_map = MEM_new_zeroed<UvElementMap>("UvElementMap");
1091 element_map->total_uvs = totuv;
1092 element_map->vertex = MEM_new_array_zeroed<UvElement *>(bm->totvert, "UvElementVerts");
1093 element_map->storage = MEM_new_array_zeroed<UvElement>(totuv, "UvElement");
1094
1095 bool *winding = use_winding ? MEM_new_array_zeroed<bool>(bm->totface, "winding") : nullptr;
1096
1097 UvElement *buf = element_map->storage;
1098 int j;
1099 BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, j) {
1100
1102 continue;
1103 }
1104
1105 if (face_selected && !BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
1106 continue;
1107 }
1108
1109 int i;
1110 BMLoop *l;
1111 BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
1112 if (uv_selected && !uvedit_uv_select_test(scene, bm, l, offsets)) {
1113 continue;
1114 }
1115
1116 buf->l = l;
1117 buf->island = INVALID_ISLAND;
1118 buf->loop_of_face_index = i;
1119
1120 /* Insert to head of linked list associated with BMVert. */
1121 buf->next = element_map->vertex[BM_elem_index_get(l->v)];
1122 element_map->vertex[BM_elem_index_get(l->v)] = buf;
1123
1124 buf++;
1125 }
1126
1127 if (winding) {
1128 winding[j] = BM_face_calc_area_uv_signed(efa, offsets.uv) > 0;
1129 }
1130 }
1131
1132 Set<const BMEdge *> seam_visited_set;
1133
1134 /* For each BMVert, sort associated linked list into unique uvs. */
1135 int ev_index;
1136 BM_ITER_MESH_INDEX (ev, &iter, bm, BM_VERTS_OF_MESH, ev_index) {
1137 UvElement *newvlist = nullptr;
1138 UvElement *vlist = element_map->vertex[ev_index];
1139 while (vlist) {
1140
1141 /* Detach head from unsorted list. */
1142 UvElement *v = vlist;
1143 vlist = vlist->next;
1144 v->next = newvlist;
1145 newvlist = v;
1146
1147 const float *uv = static_cast<const float *>(BM_ELEM_CD_GET_VOID_P(v->l, offsets.uv));
1148 bool uv_vert_sel = uvedit_uv_select_test(scene, bm, v->l, offsets);
1149
1150 UvElement *lastv = nullptr;
1151 UvElement *iterv = vlist;
1152
1153 /* Scan through unsorted list, finding UvElements which are connected to `v`. */
1154 while (iterv) {
1155 UvElement *next = iterv->next;
1156
1157 bool connected = true; /* Assume connected unless we can prove otherwise. */
1158
1159 if (connected) {
1160 /* Are the two UVs close together? */
1161 const float *uv2 = BM_ELEM_CD_GET_FLOAT_P(iterv->l, offsets.uv);
1162 connected = compare_v2v2(uv2, uv, STD_UV_CONNECT_LIMIT);
1163 }
1164
1165 if (connected) {
1166 /* Check if the uv loops share the same selection state (if not, they are not connected
1167 * as they have been ripped or other edit commands have separated them). */
1168 const bool uv2_vert_sel = uvedit_uv_select_test(scene, bm, iterv->l, offsets);
1169 connected = (uv_vert_sel == uv2_vert_sel);
1170 }
1171
1172 if (connected && use_winding) {
1173 connected = winding[BM_elem_index_get(iterv->l->f)] ==
1174 winding[BM_elem_index_get(v->l->f)];
1175 }
1176
1177 if (connected && use_seams) {
1178 connected = seam_connected(iterv->l, v->l, seam_visited_set, offsets.uv);
1179 }
1180
1181 if (connected) {
1182 if (lastv) {
1183 lastv->next = next;
1184 }
1185 else {
1186 vlist = next;
1187 }
1188 iterv->next = newvlist;
1189 newvlist = iterv;
1190 }
1191 else {
1192 lastv = iterv;
1193 }
1194
1195 iterv = next;
1196 }
1197
1198 element_map->total_unique_uvs++;
1199 newvlist->separate = true;
1200 }
1201
1202 /* Write back sorted list. */
1203 element_map->vertex[ev_index] = newvlist;
1204 }
1205
1206 if (!use_seams) {
1207 BLI_assert(seam_visited_set.is_empty());
1208 }
1209 MEM_SAFE_DELETE(winding);
1210
1211 /* at this point, every UvElement in vert points to a UvElement sharing the same vertex.
1212 * Now we should sort uv's in islands. */
1213 if (do_islands) {
1214 bm_uv_build_islands(element_map, bm, scene, uv_selected);
1215 }
1216
1217 /* TODO: Confirm element_map->total_unique_uvs doesn't require recalculating. */
1218 element_map->total_unique_uvs = 0;
1219 for (int i = 0; i < element_map->total_uvs; i++) {
1220 if (element_map->storage[i].separate) {
1221 element_map->total_unique_uvs++;
1222 }
1223 }
1224
1225 return element_map;
1226}
1227
1229{
1230 if (vmap) {
1231 if (vmap->vert) {
1232 MEM_delete(vmap->vert);
1233 }
1234 if (vmap->buf) {
1235 MEM_delete(vmap->buf);
1236 }
1237 MEM_delete(vmap);
1238 }
1239}
1240
1242{
1243 if (element_map) {
1244 MEM_SAFE_DELETE(element_map->storage);
1245 MEM_SAFE_DELETE(element_map->vertex);
1246 MEM_SAFE_DELETE(element_map->head_table);
1247 MEM_SAFE_DELETE(element_map->unique_index_table);
1248 MEM_SAFE_DELETE(element_map->island_indices);
1249 MEM_SAFE_DELETE(element_map->island_total_uvs);
1250 MEM_SAFE_DELETE(element_map->island_total_unique_uvs);
1251 MEM_SAFE_DELETE(element_map);
1252 }
1253}
1254
1256{
1257 UvElement *element = element_map->vertex[BM_elem_index_get(l->v)];
1258 while (element) {
1259 if (element->l == l) {
1260 return element;
1261 }
1262 element = element->next;
1263 }
1264
1265 return nullptr;
1266}
1267
1269{
1270 if (!child) {
1271 return nullptr;
1272 }
1273
1274 return element_map->vertex[BM_elem_index_get(child->l->v)];
1275}
1276
1278
1279/* -------------------------------------------------------------------- */
1282
1283BMFace *EDBM_uv_active_face_get(Mesh *mesh, const bool sloppy, const bool selected)
1284{
1285 if (!EDBM_uv_check(mesh)) {
1286 return nullptr;
1287 }
1289 BMFace *efa = BM_mesh_active_face_get(bm, sloppy, selected);
1290 if (efa) {
1291 return efa;
1292 }
1293
1294 return nullptr;
1295}
1296
1298{
1299 if (!mesh->runtime->edit_mesh) {
1300 return false;
1301 }
1303 if (!bm->totface) {
1304 return false;
1305 }
1307 return false;
1308 }
1309 return true;
1310}
1311
1313
1314/* -------------------------------------------------------------------- */
1317
1318static BMVert *cache_mirr_intptr_as_bmvert(const intptr_t *index_lookup, int index)
1319{
1320 intptr_t eve_i = index_lookup[index];
1321 return (eve_i == -1) ? nullptr : reinterpret_cast<BMVert *>(eve_i);
1322}
1323
1339
1340/* BM_SEARCH_MAXDIST is too big, copied from 2.6x MOC_THRESH, should become a preference. */
1341#define BM_SEARCH_MAXDIST_MIRR 0.00002f
1342#define BM_CD_LAYER_ID "__mirror_index"
1343
1345 BMesh *bm,
1346 const int axis,
1347 const bool use_self,
1348 const bool use_select,
1349 const bool respecthide,
1350 /* extra args */
1351 const bool use_topology,
1352 float maxdist,
1353 int *r_index)
1354{
1355 BMIter iter;
1356 BMVert *v;
1357 int cd_vmirr_offset = 0;
1358 int i;
1359 const float maxdist_sq = square_f(maxdist);
1360
1361 /* one or the other is used depending if topo is enabled */
1362 KDTree<float3> *tree = nullptr;
1363 MirrTopoStore_t mesh_topo_store = {nullptr, -1, -1, false};
1364
1366
1367 if (r_index == nullptr) {
1368 const char *layer_id = BM_CD_LAYER_ID;
1370 if (em->mirror_cdlayer == -1) {
1373 }
1374
1375 cd_vmirr_offset = CustomData_get_n_offset(
1376 &bm->vdata,
1379
1381 }
1382
1384
1385 if (use_topology) {
1386 ED_mesh_mirrtopo_init(bm, nullptr, &mesh_topo_store, true);
1387 }
1388 else {
1389 tree = kdtree_new<float3>(bm->totvert);
1390 BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) {
1391 if (respecthide && BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
1392 continue;
1393 }
1394
1395 kdtree_insert<float3>(tree, i, v->co);
1396 }
1398 }
1399
1400#define VERT_INTPTR(_v, _i) \
1401 (r_index ? &r_index[_i] : static_cast<int *>(BM_ELEM_CD_GET_VOID_P(_v, cd_vmirr_offset)))
1402
1403 BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) {
1404 if (respecthide && BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
1405 continue;
1406 }
1407
1408 if (use_select && !BM_elem_flag_test(v, BM_ELEM_SELECT)) {
1409 continue;
1410 }
1411
1413 BMVert *v_mirr;
1414 int *idx = VERT_INTPTR(v, i);
1415
1416 if (use_topology) {
1417 v_mirr = cache_mirr_intptr_as_bmvert(mesh_topo_store.index_lookup, i);
1418 if (v_mirr != nullptr) {
1419 if (respecthide && BM_elem_flag_test(v_mirr, BM_ELEM_HIDDEN)) {
1420 v_mirr = nullptr;
1421 }
1422 }
1423 }
1424 else {
1425 int i_mirr;
1426 float co[3];
1427 copy_v3_v3(co, v->co);
1428 co[axis] *= -1.0f;
1429
1430 v_mirr = nullptr;
1431 i_mirr = kdtree_find_nearest<float3>(tree, co, nullptr);
1432 if (i_mirr != -1) {
1433 BMVert *v_test = BM_vert_at_index(bm, i_mirr);
1434 if (len_squared_v3v3(co, v_test->co) < maxdist_sq) {
1435 v_mirr = v_test;
1436 }
1437 }
1438 }
1439
1440 if (v_mirr && (use_self || (v_mirr != v))) {
1441 const int i_mirr = BM_elem_index_get(v_mirr);
1442 *idx = i_mirr;
1443 idx = VERT_INTPTR(v_mirr, i_mirr);
1444 *idx = i;
1445 }
1446 else {
1447 *idx = -1;
1448 }
1449 }
1450
1451#undef VERT_INTPTR
1452
1453 if (use_topology) {
1454 ED_mesh_mirrtopo_free(&mesh_topo_store);
1455 }
1456 else {
1457 kdtree_free<float3>(tree);
1458 }
1459}
1460
1462 BMesh *bm,
1463 const int axis,
1464 const bool use_self,
1465 const bool use_select,
1466 const bool respecthide,
1467 const bool use_topology)
1468{
1470 bm,
1471 axis,
1472 use_self,
1473 use_select,
1474 respecthide,
1475 /* extra args */
1476 use_topology,
1478 nullptr);
1479}
1480
1482{
1483 const int *mirr = static_cast<const int *>(
1485
1486 BLI_assert(em->mirror_cdlayer != -1); /* invalid use */
1487
1488 if (mirr && *mirr >= 0 && *mirr < bm->totvert) {
1489 if (!bm->vtable) {
1490 printf(
1491 "err: should only be called between "
1492 "EDBM_verts_mirror_cache_begin and EDBM_verts_mirror_cache_end");
1493 return nullptr;
1494 }
1495
1496 return bm->vtable[*mirr];
1497 }
1498
1499 return nullptr;
1500}
1501
1503{
1504 BMVert *v1_mirr, *v2_mirr;
1505 if ((v1_mirr = EDBM_verts_mirror_get(em, bm, e->v1)) &&
1506 (v2_mirr = EDBM_verts_mirror_get(em, bm, e->v2)) &&
1507 /* While highly unlikely, a zero length central edges vertices can match, see #89342. */
1508 LIKELY(v1_mirr != v2_mirr))
1509 {
1510 return BM_edge_exists(v1_mirr, v2_mirr);
1511 }
1512
1513 return nullptr;
1514}
1515
1517{
1519
1520 BMLoop *l_iter, *l_first;
1521 uint i = 0;
1522
1523 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1524 do {
1525 if ((v_mirr_arr[i++] = EDBM_verts_mirror_get(em, bm, l_iter->v)) == nullptr) {
1526 return nullptr;
1527 }
1528 } while ((l_iter = l_iter->next) != l_first);
1529
1530 return BM_face_exists(v_mirr_arr.data(), v_mirr_arr.size());
1531}
1532
1534{
1535 int *mirr = static_cast<int *>(
1537
1538 BLI_assert(em->mirror_cdlayer != -1); /* invalid use */
1539
1540 if (mirr) {
1541 *mirr = -1;
1542 }
1543}
1544
1546{
1547 em->mirror_cdlayer = -1;
1548}
1549
1550void EDBM_verts_mirror_apply(BMEditMesh *em, BMesh *bm, const int sel_from, const int sel_to)
1551{
1552 BMIter iter;
1553 BMVert *v;
1554
1555 BLI_assert((bm->vtable != nullptr) && ((bm->elem_table_dirty & BM_VERT) == 0));
1556
1557 BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
1558 if (BM_elem_flag_test(v, BM_ELEM_SELECT) == sel_from) {
1559 BMVert *mirr = EDBM_verts_mirror_get(em, bm, v);
1560 if (mirr) {
1561 if (BM_elem_flag_test(mirr, BM_ELEM_SELECT) == sel_to) {
1562 copy_v3_v3(mirr->co, v->co);
1563 mirr->co[0] *= -1.0f;
1564 }
1565 }
1566 }
1567 }
1568}
1569
1571
1572/* -------------------------------------------------------------------- */
1575
1576bool EDBM_mesh_hide(BMesh *bm, const short selectmode, bool swap)
1577{
1578 BMIter iter;
1579 BMElem *ele;
1580 int itermode;
1581 char hflag_swap = swap ? BM_ELEM_SELECT : 0;
1582 bool changed = false;
1583
1584 if (selectmode & SCE_SELECT_VERTEX) {
1585 itermode = BM_VERTS_OF_MESH;
1586 }
1587 else if (selectmode & SCE_SELECT_EDGE) {
1588 itermode = BM_EDGES_OF_MESH;
1589 }
1590 else {
1591 itermode = BM_FACES_OF_MESH;
1592 }
1593
1594 BM_ITER_MESH (ele, &iter, bm, itermode) {
1595 if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN)) {
1596 if (BM_elem_flag_test(ele, BM_ELEM_SELECT) ^ hflag_swap) {
1597 BM_elem_hide_set(bm, ele, true);
1598 changed = true;
1599 }
1600 }
1601 }
1602
1603 /* Hiding unselected. */
1604 if (swap) {
1605 /* In face select mode, also hide loose edges that aren't part of any visible face. */
1606 if (itermode == BM_FACES_OF_MESH) {
1607 BMEdge *e;
1608 BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
1609 if (!BM_edge_is_wire(e)) {
1610 continue;
1611 }
1613 BM_elem_hide_set(bm, (BMElem *)e, true);
1614 changed = true;
1615 }
1616 }
1617 }
1618 /* In edge or face select mode, also hide isolated verts that aren't connected to an edge. */
1619 if (ELEM(itermode, BM_EDGES_OF_MESH, BM_FACES_OF_MESH)) {
1620 BMVert *v;
1621 BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
1622 if (v->e) {
1623 continue;
1624 }
1626 BM_elem_hide_set(bm, (BMElem *)v, true);
1627 changed = true;
1628 }
1629 }
1630 }
1631 }
1632
1633 if (changed) {
1634 EDBM_selectmode_flush(bm, selectmode);
1636 }
1637 return changed;
1638
1639 /* original hide flushing comment (OUTDATED):
1640 * hide happens on least dominant select mode, and flushes up, not down!
1641 * (helps preventing errors in subsurf) */
1642 /* - vertex hidden, always means edge is hidden too
1643 * - edge hidden, always means face is hidden too
1644 * - face hidden, only set face hide
1645 * - then only flush back down what's absolute hidden
1646 */
1647}
1648
1649bool EDBM_mesh_reveal(BMesh *bm, const short selectmode, bool select)
1650{
1651 const char iter_types[3] = {
1655 };
1656
1657 const bool sels[3] = {
1658 (selectmode & SCE_SELECT_VERTEX) != 0,
1659 (selectmode & SCE_SELECT_EDGE) != 0,
1660 (selectmode & SCE_SELECT_FACE) != 0,
1661 };
1662 int i;
1663 bool changed = false;
1664
1665 /* Use tag flag to remember what was hidden before all is revealed.
1666 * BM_ELEM_HIDDEN --> BM_ELEM_TAG */
1667 for (i = 0; i < 3; i++) {
1668 BMIter iter;
1669 BMElem *ele;
1670
1671 BM_ITER_MESH (ele, &iter, bm, iter_types[i]) {
1674 changed = true;
1675 }
1676 else {
1678 }
1679 }
1680 }
1681
1682 if (!changed) {
1683 return false;
1684 }
1685
1686 /* Reveal everything */
1688
1689 /* Select relevant just-revealed elements */
1690 for (i = 0; i < 3; i++) {
1691 BMIter iter;
1692 BMElem *ele;
1693
1694 if (!sels[i]) {
1695 continue;
1696 }
1697
1698 BM_ITER_MESH (ele, &iter, bm, iter_types[i]) {
1699 if (BM_elem_flag_test(ele, BM_ELEM_TAG)) {
1701 }
1702 }
1703 }
1704
1705 if (bm->uv_select_sync_valid) {
1706 /* NOTE(@ideasman42): this could/should use the "sticky" tool setting.
1707 * Although in practice it's OK to assume "connected" sticky in this case. */
1708 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
1709 if (cd_loop_uv_offset == -1) {
1710 /* Not expected but not an error either, clear if the UV's have been removed. */
1712 }
1713 else {
1714 BMIter iter;
1715 BMFace *f;
1716
1717 if (selectmode & SCE_SELECT_VERTEX) {
1718 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1719 BMLoop *l_iter, *l_first;
1720 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1721 do {
1722 if (BM_elem_flag_test(l_iter->v, BM_ELEM_TAG)) {
1723 BM_loop_vert_uvselect_set_shared(bm, l_iter, select, cd_loop_uv_offset);
1724 }
1725 } while ((l_iter = l_iter->next) != l_first);
1726 }
1727 }
1728 else if (selectmode & SCE_SELECT_EDGE) {
1729 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1730 BMLoop *l_iter, *l_first;
1731 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1732 do {
1733 if (BM_elem_flag_test(l_iter->e, BM_ELEM_TAG)) {
1734 BM_loop_edge_uvselect_set_shared(bm, l_iter, select, cd_loop_uv_offset);
1735 }
1736 } while ((l_iter = l_iter->next) != l_first);
1737 }
1738 }
1739 else {
1740 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1742 BM_face_uvselect_set_shared(bm, f, select, cd_loop_uv_offset);
1743 }
1744 }
1745 }
1746
1748 }
1749 }
1750
1751 EDBM_selectmode_flush(bm, selectmode);
1752
1753 /* hidden faces can have invalid normals */
1755
1756 return true;
1757}
1758
1760
1761/* -------------------------------------------------------------------- */
1764
1769
1771{
1773 params.face_normals = true;
1775}
1776
1778{
1779 const char iter_types[3] = {
1783 };
1784
1785 BMIter iter;
1786 BMElem *ele;
1787 int *tots[3];
1788 int i;
1789
1790 tots[0] = &bm->totvertsel;
1791 tots[1] = &bm->totedgesel;
1792 tots[2] = &bm->totfacesel;
1793
1795
1796 for (i = 0; i < 3; i++) {
1797 ele = static_cast<BMElem *>(BM_iter_new(&iter, bm, iter_types[i], nullptr));
1798 for (; ele; ele = static_cast<BMElem *>(BM_iter_step(&iter))) {
1800 (*tots[i])++;
1801 }
1802 }
1803 }
1804}
1805
1807{
1808 BMEditMesh *em = mesh->runtime->edit_mesh.get();
1810 /* Order of calling isn't important. */
1813
1814 if (params->calc_normals && params->calc_looptris) {
1815 /* Calculating both has some performance gains. */
1817 }
1818 else {
1819 if (params->calc_normals) {
1821 }
1822
1823 if (params->calc_looptris) {
1825 }
1826 }
1827
1828 if (params->is_destructive) {
1829 /* TODO(@ideasman42): we may be able to remove this now! */
1830 // BM_mesh_elem_table_free(bm, BM_ALL_NOLOOP);
1831 }
1832 else {
1833 /* in debug mode double check we didn't need to recalculate */
1835 }
1839 }
1840
1841#ifndef NDEBUG
1842 {
1843 for (BMEditSelection &ese : bm->selected) {
1845 }
1846 }
1847#endif
1848}
1849
1850void EDBM_update_extern(Mesh *mesh, const bool do_tessellation, const bool is_destructive)
1851{
1852 /* Python may assign `BMesh.select_mode`, apply it to the edit-mesh.
1853 * Since Python doesn't expose the edit-mesh, see: #166007. */
1854 BMEditMesh *em = mesh->runtime->edit_mesh.get();
1856 if (em->selectmode != bm->selectmode) {
1857 em->selectmode = bm->selectmode;
1860 }
1861
1862 EDBMUpdate_Params params{};
1863 params.calc_looptris = do_tessellation;
1864 params.calc_normals = false;
1865 params.is_destructive = is_destructive;
1866 EDBM_update(mesh, &params);
1867}
1868
1870
1871/* -------------------------------------------------------------------- */
1874
1876{
1878 return true;
1879 }
1880
1881 return false;
1882}
1883
1885
1886/* -------------------------------------------------------------------- */
1889
1891{
1892 if ((em->selectmode & SCE_SELECT_VERTEX) && eve) {
1893 return reinterpret_cast<BMElem *>(eve);
1894 }
1895 if ((em->selectmode & SCE_SELECT_EDGE) && eed) {
1896 return reinterpret_cast<BMElem *>(eed);
1897 }
1898 if ((em->selectmode & SCE_SELECT_FACE) && efa) {
1899 return reinterpret_cast<BMElem *>(efa);
1900 }
1901 return nullptr;
1902}
1903
1905{
1906 int index = BM_elem_index_get(ele);
1907
1908 if (ele->head.htype == BM_VERT) {
1910 }
1911 else if (ele->head.htype == BM_EDGE) {
1913 index += bm->totvert;
1914 }
1915 else if (ele->head.htype == BM_FACE) {
1917 index += bm->totvert + bm->totedge;
1918 }
1919 else {
1920 BLI_assert(0);
1921 }
1922
1923 return index;
1924}
1925
1927{
1928 if (index < bm->totvert) {
1929 return reinterpret_cast<BMElem *>(BM_vert_at_index_find_or_table(bm, index));
1930 }
1931 index -= bm->totvert;
1932 if (index < bm->totedge) {
1933 return reinterpret_cast<BMElem *>(BM_edge_at_index_find_or_table(bm, index));
1934 }
1935 index -= bm->totedge;
1936 if (index < bm->totface) {
1937 return reinterpret_cast<BMElem *>(BM_face_at_index_find_or_table(bm, index));
1938 }
1939
1940 return nullptr;
1941}
1942
1944 const Scene *scene,
1945 ViewLayer *view_layer,
1946 BMEditMesh *em,
1947 BMElem *ele,
1948 int *r_object_index)
1949{
1950 int elem_index = -1;
1951 *r_object_index = -1;
1953 bmain, scene, view_layer, nullptr);
1954 for (const int base_index : bases.index_range()) {
1955 Base *base_iter = bases[base_index];
1956 if (BKE_editmesh_from_object(base_iter->object) == em) {
1958 *r_object_index = base_index;
1959 elem_index = EDBM_elem_to_index_any(bm, ele);
1960 break;
1961 }
1962 }
1963 return elem_index;
1964}
1965
1967 const Scene *scene,
1968 ViewLayer *view_layer,
1969 uint object_index,
1970 uint elem_index,
1971 Object **r_obedit)
1972{
1974 bmain, scene, view_layer, nullptr);
1975 *r_obedit = nullptr;
1976 Object *obedit = (object_index < bases.size()) ? bases[object_index]->object : nullptr;
1977 if (obedit != nullptr) {
1979 BMElem *ele = EDBM_elem_from_index_any(bm, elem_index);
1980 if (ele != nullptr) {
1981 *r_obedit = obedit;
1982 return ele;
1983 }
1984 }
1985 return nullptr;
1986}
1987
1989
1990/* -------------------------------------------------------------------- */
1993
1994static BMFace *edge_ray_cast(const BMBVHTree *tree,
1995 const float co[3],
1996 const float dir[3],
1997 float *r_hitout,
1998 const BMEdge *e,
1999 float *r_dist)
2000{
2001 BMFace *f = BKE_bmbvh_ray_cast(tree, co, dir, 0.0f, r_dist, r_hitout, nullptr);
2002
2003 if (f && BM_edge_in_face(e, f)) {
2004 return nullptr;
2005 }
2006
2007 return f;
2008}
2009
2010static void scale_point(float c1[3], const float p[3], const float s)
2011{
2012 sub_v3_v3(c1, p);
2013 mul_v3_fl(c1, s);
2014 add_v3_v3(c1, p);
2015}
2016
2018 const BMEdge *e,
2019 const Depsgraph *depsgraph,
2020 const ARegion *region,
2021 const View3D *v3d,
2022 const Object *obedit)
2023{
2024 BMFace *f;
2025 float co1[3], co2[3], co3[3], dir1[3], dir2[3], dir3[3];
2026 float origin[3], invmat[4][4];
2027 float epsilon = 0.01f;
2028 float end[3];
2029 const float mval_f[2] = {
2030 region->winx / 2.0f,
2031 region->winy / 2.0f,
2032 };
2033
2034 ED_view3d_win_to_segment_clipped(depsgraph, region, v3d, mval_f, origin, end, false);
2035
2036 invert_m4_m4(invmat, obedit->object_to_world().ptr());
2037 mul_m4_v3(invmat, origin);
2038
2039 copy_v3_v3(co1, e->v1->co);
2040 mid_v3_v3v3(co2, e->v1->co, e->v2->co);
2041 copy_v3_v3(co3, e->v2->co);
2042
2043 scale_point(co1, co2, 0.99);
2044 scale_point(co3, co2, 0.99);
2045
2046 /* OK, idea is to generate rays going from the three points on the edge (v1, mid, v2) to the
2047 * camera origin. */
2048 sub_v3_v3v3(dir1, origin, co1);
2049 sub_v3_v3v3(dir2, origin, co2);
2050 sub_v3_v3v3(dir3, origin, co3);
2051
2052 /* This prevents the ray shooting behind the camera. */
2053 float dist1 = len_v3(dir1);
2054 float dist2 = len_v3(dir2);
2055 float dist3 = len_v3(dir3);
2056
2057 normalize_v3_length(dir1, epsilon);
2058 normalize_v3_length(dir2, epsilon);
2059 normalize_v3_length(dir3, epsilon);
2060
2061 /* Offset coordinates slightly along view vectors,
2062 * to avoid hitting the faces that own the edge. */
2063 add_v3_v3v3(co1, co1, dir1);
2064 add_v3_v3v3(co2, co2, dir2);
2065 add_v3_v3v3(co3, co3, dir3);
2066
2067 normalize_v3(dir1);
2068 normalize_v3(dir2);
2069 normalize_v3(dir3);
2070
2071 /* do three samplings: left, middle, right */
2072 f = edge_ray_cast(tree, co1, dir1, nullptr, e, &dist1);
2073 if (f && !edge_ray_cast(tree, co2, dir2, nullptr, e, &dist2)) {
2074 return true;
2075 }
2076 if (f && !edge_ray_cast(tree, co3, dir3, nullptr, e, &dist3)) {
2077 return true;
2078 }
2079 if (!f) {
2080 return true;
2081 }
2082
2083 return false;
2084}
2085
2087
2088/* -------------------------------------------------------------------- */
2091
2092void EDBM_project_snap_verts(bContext *C, Depsgraph *depsgraph, ARegion *region, Object *obedit)
2093{
2094 using namespace blender::ed;
2095 BMIter iter;
2096 BMVert *eve;
2097
2098 ED_view3d_init_mats_rv3d(obedit, static_cast<RegionView3D *>(region->regiondata));
2100
2101 const Scene *scene = CTX_data_scene(C);
2103
2105 const int snap_flag = scene->toolsettings->snap_flag;
2106
2108 target_op, !(snap_flag & SCE_SNAP_TO_INCLUDE_EDITED), SCE_SNAP_TARGET_NOT_EDITED);
2113
2114 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
2116 float mval[2], co_proj[3];
2117 if (ED_view3d_project_float_object(region, eve->co, mval, V3D_PROJ_TEST_NOP) ==
2119 {
2121 params.snap_target_select = target_op;
2122 params.edit_mode_type = transform ::SNAP_GEOM_FINAL;
2123 params.occlusion_test = transform ::SNAP_OCCLUSION_AS_SEEM;
2125 depsgraph,
2126 region,
2129 &params,
2130 nullptr,
2131 mval,
2132 nullptr,
2133 nullptr,
2134 co_proj,
2135 nullptr))
2136 {
2137 mul_v3_m4v3(eve->co, obedit->world_to_object().ptr(), co_proj);
2138 }
2139 }
2140 }
2141 }
2142
2144}
2145
2147
2149{
2150 return EDBM_op_callf(bm,
2151 op,
2152 "smooth_vert verts=%hv factor=%f mirror_clip_x=%b mirror_clip_y=%b "
2153 "mirror_clip_z=%b "
2154 "clip_dist=%f use_axis_x=%b use_axis_y=%b use_axis_z=%b",
2156 1.0,
2157 false,
2158 false,
2159 false,
2160 0.1,
2161 true,
2162 true,
2163 true);
2164}
2165
2166} // namespace blender
Generic geometry attributes built on CustomData.
CustomData interface, see also DNA_customdata_types.h.
#define STD_UV_CONNECT_LIMIT
A KD-tree for nearest neighbor search.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DATA
Definition WM_types.hh:552
#define NC_SCENE
Definition WM_types.hh:391
#define ND_TOOLSETTINGS
Definition WM_types.hh:468
#define ND_SELECT
Definition WM_types.hh:551
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define LIKELY(x)
#define BM_ALL_NOLOOP
#define BM_FACE_FIRST_LOOP(p)
#define BM_ELEM_CD_GET_FLOAT_P(ele, offset)
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
#define BM_elem_index_get(ele)
#define BM_elem_flag_disable(ele, hflag)
#define BM_elem_flag_test(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_iter_new(iter, bm, itype, data)
#define BM_elem_hide_set(bm, ele, hide)
#define BMSelectFlushFlag_All
#define BMO_FLAG_DEFAULTS
int64_t size() const
Definition BLI_array.hh:267
const T * data() const
Definition BLI_array.hh:323
static AttributeOwner from_id(ID *id)
bool add(const Key &key)
Definition BLI_set.hh:248
bool is_empty() const
Definition BLI_set.hh:614
void clear()
Definition BLI_set.hh:570
int64_t size() const
IndexRange index_range() const
#define INVALID_ISLAND
#define BM_CD_LAYER_ID
#define VERT_INTPTR(_v, _i)
#define BM_SEARCH_MAXDIST_MIRR
bool allow_procedural_attribute_access(StringRef attribute_name)
void snap_object_context_destroy(SnapObjectContext *sctx)
SnapObjectContext * snap_object_context_create()
eSnapMode snap_object_project_view3d(SnapObjectContext *sctx, Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const eSnapMode snap_to, const SnapObjectParams *params, const float init_co[3], const float mval[2], const float prev_co[3], float *dist_px, float r_loc[3], float r_no[3])
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
void EDBM_flag_disable_all(BMesh *bm, char hflag)
void EDBM_mesh_normals_update_ex(BMesh *bm, const BMeshNormalsUpdate_Params *params)
std::optional< StringRefNull > BKE_attributes_active_name_get(AttributeOwner &owner)
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
UvElement * BM_uv_element_get(const UvElementMap *element_map, const BMLoop *l)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
BMElem * EDBM_elem_from_selectmode(BMEditMesh *em, BMVert *eve, BMEdge *eed, BMFace *efa)
void BKE_mesh_uv_vert_map_free(UvVertMap *vmap)
void ED_mesh_mirror_topo_table_end(Object *ob)
Definition meshtools.cc:253
void EDBM_verts_mirror_cache_clear(BMEditMesh *em, BMesh *bm, BMVert *v)
@ V3D_PROJ_RET_OK
Definition ED_view3d.hh:273
void kdtree_balance(KDTree< CoordT > *tree)
void BM_loop_edge_uvselect_set_shared(BMesh *bm, BMLoop *l, bool select, const int cd_loop_uv_offset)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
void BM_mesh_elem_hflag_enable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
static int object_shapenr_basis_index_ensured(const Object *ob)
void EDBM_stats_update(BMesh *bm)
BLI_INLINE bool BM_edge_is_wire(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BM_edge_in_face(const BMEdge *e, const BMFace *f)
bool BMBVH_EdgeVisible(const BMBVHTree *tree, const BMEdge *e, const Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const Object *obedit)
@ BM_SPACEARR_BMO_SET
bool uvedit_edge_select_test(const Scene *scene, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
@ RPT_WARNING
Definition BKE_report.hh:40
bool BM_mesh_uvselect_clear(BMesh *bm)
void ED_mesh_mirrtopo_init(BMesh *bm, Mesh *mesh, MirrTopoStore_t *mesh_topo_store, bool skip_bm_vert_array_init)
void EDBM_selectmode_flush(BMesh *bm, short selectmode)
void EDBM_select_more(BMesh *bm, short selectmode, bool use_face_step)
void void void EDBM_redo_state_free(BMBackup *backup) ATTR_NONNULL(1)
void BKE_editmesh_looptris_calc(BMEditMesh *em, BMesh *bm)
Definition editmesh.cc:115
void BM_mesh_data_free(BMesh *bm)
BMesh Free Mesh Data.
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
void EDBM_selectmode_to_scene(bContext *C)
UvElement ** BM_uv_element_map_ensure_head_table(UvElementMap *element_map)
MINLINE void copy_v3_v3(float r[3], const float a[3])
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
void BMO_slot_buffer_hflag_enable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, char hflag, bool do_flush)
BMO_FLAG_BUFFER.
bool EDBM_op_init(BMesh *bm, BMOperator *bmop, wmOperator *op, const char *fmt,...)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
BMVert * EDBM_verts_mirror_get(BMEditMesh *em, BMesh *bm, BMVert *v)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
eV3DProjStatus ED_view3d_project_float_object(const ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
bool EDBM_view3d_poll(bContext *C)
struct BMFace * BKE_bmbvh_ray_cast(const BMBVHTree *tree, const float co[3], const float dir[3], float radius, float *r_dist, float r_hitout[3], float r_cagehit[3])
static BMFace * edge_ray_cast(const BMBVHTree *tree, const float co[3], const float dir[3], float *r_hitout, const BMEdge *e, float *r_dist)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
BMBackup EDBM_redo_state_store(BMesh *bm)
BMEdge * EDBM_verts_mirror_get_edge(BMEditMesh *em, BMesh *bm, BMEdge *e)
static bool seam_connected(BMLoop *loop_a, BMLoop *loop_b, Set< const BMEdge * > &visited, int cd_loop_uv_offset)
BMVert * BM_vert_at_index_find_or_table(BMesh *bm, const int index)
void EDBM_update(Mesh *mesh, const EDBMUpdate_Params *params)
int CustomData_get_n_offset(const CustomData *data, eCustomDataType type, int n)
void ED_mesh_mirror_spatial_table_end(Object *ob)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
bool EDBM_op_callf(BMesh *bm, wmOperator *op, const char *fmt,...)
bool BMO_op_initf(BMesh *bm, BMOperator *op, int flag, const char *fmt,...)
bool EDBM_op_vcall_and_selectf(BMesh *bm, wmOperator *op, const char *select_slot_out, const bool select_extend, const char *fmt, va_list list)
void BM_mesh_elem_hflag_disable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
void EDBM_mesh_load_ex(Main *bmain, Object *ob, bool free_data)
void BKE_attributes_active_set(AttributeOwner &owner, StringRef name)
UvElement * BM_uv_element_get_head(UvElementMap *element_map, UvElement *child)
int CustomData_get_layer_index(const CustomData *data, eCustomDataType type)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void EDBM_verts_mirror_cache_begin(BMEditMesh *em, BMesh *bm, int axis, bool use_self, bool use_select, bool respecthide, bool use_topology)
void BM_mesh_select_mode_clean(BMesh *bm)
static int bm_uv_edge_select_build_islands(UvElementMap *element_map, const Scene *scene, const BMesh *bm, UvElement *islandbuf, uint *map, bool uv_selected, const BMUVOffsets &offsets)
void BMO_op_exec(BMesh *bm, BMOperator *op)
BMESH OPSTACK EXEC OP.
void BM_uv_element_map_free(UvElementMap *element_map)
void BM_face_uvselect_set_shared(BMesh *bm, BMFace *f, bool select, const int cd_loop_uv_offset)
BMElem * EDBM_elem_from_index_any_multi(const Main &bmain, const Scene *scene, ViewLayer *view_layer, uint object_index, uint elem_index, Object **r_obedit)
void BM_mesh_normals_update_ex(BMesh *bm, const BMeshNormalsUpdate_Params *params)
BMesh Compute Normals.
bool EDBM_uv_check(const Mesh *mesh)
MINLINE void mul_v3_fl(float r[3], float f)
void * BM_iter_at_index(BMesh *bm, const char itype, void *data, int index)
MINLINE void sub_v3_v3(float r[3], const float a[3])
bool uvedit_uv_select_test(const Scene *scene, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
void EDBM_mesh_free_data(BMEditMesh *em)
KDTree< CoordT > * kdtree_new(uint nodes_len_capacity)
Definition BLI_kdtree.hh:65
void mul_m4_v3(const float M[4][4], float r[3])
void EDBM_verts_mirror_cache_begin_ex(BMEditMesh *em, BMesh *bm, int axis, bool use_self, bool use_select, bool respecthide, bool use_topology, float maxdist, int *r_index)
bool ED_operator_editmesh(bContext *C)
@ SCE_SNAP_TARGET_NOT_ACTIVE
@ SCE_SNAP_TARGET_NOT_NONEDITED
@ SCE_SNAP_TARGET_ONLY_SELECTABLE
@ SCE_SNAP_TARGET_NOT_EDITED
bool EDBM_op_finish(BMesh *bm, BMOperator *bmop, wmOperator *op, const bool do_report)
bool EDBM_op_call_and_selectf(BMesh *bm, wmOperator *op, const char *select_slot_out, const bool select_extend, const char *fmt,...)
bool EDBM_op_call_silentf(BMesh *bm, const char *fmt,...)
static void scale_point(float c1[3], const float p[3], const float s)
static void bm_uv_assign_island(UvElementMap *element_map, UvElement *element, int nisland, uint *map, UvElement *islandbuf, int islandbufsize)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
bool EDBM_mesh_hide(BMesh *bm, const short selectmode, bool swap)
BMesh * BM_mesh_copy(BMesh *bm_old)
void BM_uv_vert_map_free(UvVertMap *vmap)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
void BKE_editmesh_free_data(BMEditMesh *em)
Definition editmesh.cc:162
bool EDBM_mesh_reveal(BMesh *bm, const short selectmode, bool select)
BMFace * EDBM_verts_mirror_get_face(BMEditMesh *em, BMesh *bm, BMFace *f)
Object * CTX_data_edit_object(const bContext *C)
void BM_elem_select_set(BMesh *bm, BMElem *ele, const bool select)
void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store)
int EDBM_elem_to_index_any_multi(const Main &bmain, const Scene *scene, ViewLayer *view_layer, BMEditMesh *em, BMElem *ele, int *r_object_index)
void kdtree_insert(KDTree< CoordT > *tree, int index, const CoordT &co)
Definition BLI_kdtree.hh:96
BMFace * BM_face_at_index_find_or_table(BMesh *bm, const int index)
BMElem * EDBM_elem_from_index_any(BMesh *bm, uint index)
BMesh * BKE_mesh_to_bmesh(Mesh *mesh, int active_shapekey, bool add_key_index, const BMeshCreateParams *params)
int kdtree_find_nearest(const KDTree< CoordT > *tree, const CoordT &co, KDTreeNearest< CoordT > *r_nearest)
void BKE_editmesh_looptris_and_normals_calc(BMEditMesh *em, BMesh *bm)
Definition editmesh.cc:122
bool ED_operator_view3d_active(bContext *C)
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
void ED_view3d_init_mats_rv3d(const Object *ob, RegionView3D *rv3d)
BLI_INLINE BMVert * BM_vert_at_index(BMesh *bm, const int index)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void EDBM_mesh_load(Main *bmain, Object *ob)
float BM_face_calc_area_uv_signed(const BMFace *f, int cd_loop_uv_offset)
int CustomData_get_named_layer_index(const CustomData *data, eCustomDataType type, StringRef name)
int EDBM_elem_to_index_any(BMesh *bm, BMElem *ele)
void EDBM_flag_enable_all(BMesh *bm, char hflag)
BMFace * BM_face_exists(BMVert *const *varr, int len)
BMOpSlot * BMO_slot_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier)
BMESH OPSTACK GET SLOT.
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:59
static bool loop_uv_match(BMLoop *loop, const float luv_a[2], const float luv_b[2], int cd_loop_uv_offset)
void BM_loop_vert_uvselect_set_shared(BMesh *bm, BMLoop *l, bool select, const int cd_loop_uv_offset)
BMEdge * BM_edge_exists(BMVert *v_a, BMVert *v_b)
MINLINE float normalize_v3(float n[3])
static void bm_uv_build_islands(UvElementMap *element_map, BMesh *bm, const Scene *scene, bool uv_selected)
BMFace * EDBM_uv_active_face_get(Mesh *mesh, bool sloppy, bool selected)
MINLINE void add_v3_v3(float r[3], const float a[3])
void kdtree_free(KDTree< CoordT > *tree)
Definition BLI_kdtree.hh:84
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
void EDBM_verts_mirror_cache_end(BMEditMesh *em)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
void EDBM_selectmode_flush_ex(BMesh *bm, short selectmode)
void EDBM_mesh_make(Object *ob, int select_mode, bool add_key_index)
void EDBM_redo_state_restore(BMBackup *backup, BMEditMesh *em, BMesh *bm, bool recalc_looptris) ATTR_NONNULL(1
BMFace * BM_mesh_active_face_get(BMesh *bm, const bool is_sloppy, const bool is_selected)
void EDBM_mesh_make_from_mesh(Object *ob, Mesh *src_mesh, int select_mode, bool add_key_index)
bool BMO_op_vinitf(BMesh *bm, BMOperator *op, int flag, const char *fmt, va_list vlist)
void BM_mesh_uvselect_mode_flush(BMesh *bm)
bool ED_view3d_win_to_segment_clipped(const Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const float mval[2], float r_ray_start[3], float r_ray_end[3], bool do_clip_planes)
UvElementMap * BM_uv_element_map_create(BMesh *bm, const Scene *scene, bool uv_selected, bool use_winding, bool use_seams, bool do_islands)
UvMapVert * BM_uv_vert_map_at_index(UvVertMap *vmap, unsigned int v)
MINLINE float normalize_v3_length(float n[3], float unit_length)
void EDBM_mesh_normals_update(BMesh *bm)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
void EDBM_update_extern(Mesh *mesh, bool do_tessellation, bool is_destructive)
void * CustomData_bmesh_get_layer_n(const CustomData *data, void *block, int n)
@ V3D_PROJ_TEST_NOP
Definition ED_view3d.hh:295
void EDBM_verts_mirror_apply(BMEditMesh *em, BMesh *bm, int sel_from, int sel_to)
MINLINE float square_f(float a)
const BMesh * BKE_editmesh_bmesh_get(const Object *ob)
Definition editmesh.cc:65
bool EDBM_uvselect_clear(BMesh *bm)
void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const StringRef name)
Scene * CTX_data_scene(const bContext *C)
@ SCE_SNAP_TO_INCLUDE_EDITED
@ SCE_SNAP_TO_INCLUDE_NONEDITED
@ SCE_SNAP_TO_ONLY_SELECTABLE
void void EDBM_redo_state_restore_and_free(BMBackup *backup, BMEditMesh *em, BMesh *bm, bool recalc_looptris) ATTR_NONNULL(1
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *mesh, const BMeshToMeshParams *params)
UvVertMap * BM_uv_vert_map_create(BMesh *bm, bool use_select, bool respect_hide)
void BM_mesh_select_flush_from_verts(BMesh *bm, const bool select)
BLI_INLINE BMFace * BM_face_at_index(BMesh *bm, const int index)
BMUVOffsets BM_uv_map_offsets_get(const BMesh *bm)
void BMO_op_finish(BMesh *bm, BMOperator *op)
BMESH OPSTACK FINISH OP.
ATTR_WARN_UNUSED_RESULT const void * element
void BMO_slot_buffer_hflag_disable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, char hflag, bool do_flush)
BMO_FLAG_BUFFER.
Vector< Base * > BKE_view_layer_array_from_bases_in_edit_mode(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
bool BMO_error_pop(BMesh *bm, const char **r_msg, BMOperator **r_op, eBMOpErrorLevel *r_level)
void EDBM_select_flush_from_verts(BMesh *bm, short selectmode, bool select)
@ BMO_ERROR_WARN
@ BMO_ERROR_FATAL
@ BMO_ERROR_CANCEL
bool EDBM_smooth_vert(BMesh *bm, wmOperator *op)
int BM_uv_element_get_unique_index(UvElementMap *element_map, UvElement *child)
int * BM_uv_element_map_ensure_unique_index(UvElementMap *element_map)
View3D * CTX_wm_view3d(const bContext *C)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static bool seam_connected_recursive(BMEdge *edge, const float luv_anchor[2], const float luv_fan[2], const BMLoop *needle, Set< const BMEdge * > &visited, const int cd_loop_uv_offset)
static BMVert * cache_mirr_intptr_as_bmvert(const intptr_t *index_lookup, int index)
BMEdge * BM_edge_at_index_find_or_table(BMesh *bm, const int index)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void EDBM_select_less(BMesh *bm, short selectmode, bool use_face_step)
MINLINE bool compare_v2v2(const float v1[2], const float v2[2], float limit) ATTR_WARN_UNUSED_RESULT
_W64 int intptr_t
Definition BKE_text.h:119
void BM_mesh_select_mode_flush_ex(BMesh *bm, const short selectmode, BMSelectFlushFlag flag)
Select Mode Flush.
bool BM_mesh_elem_table_check(BMesh *bm)
void BM_lnorspace_invalidate(BMesh *bm, const bool do_invalidate_all)
void EDBM_project_snap_verts(bContext *C, Depsgraph *depsgraph, ARegion *region, Object *obedit)
#define swap(a, b)
Definition sort.cc:61
struct BMLoop * next
struct BMLoop * prev
struct BMEdge * e
struct BMVert * v
eBMOpSlotSubType_Union slot_subtype
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
struct Object * object
struct ToolSettings * toolsettings
eTool_UvSelectMode uv_selectmode
unsigned short loop_of_face_index
unsigned short loop_of_face_index
ListBaseT< BMEditSelection > selected
struct ReportList * reports