Blender V5.3
transform_convert_mesh.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10
11#include "DNA_mesh_types.h"
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_array.hh"
16#include "BLI_linklist_stack.hh"
17#include "BLI_math_geom_c.hh"
18#include "BLI_math_matrix_c.hh"
20#include "BLI_math_vector_c.hh"
22#include "BLI_memarena.hh"
23
24#include "BKE_context.hh"
25#include "BKE_crazyspace.hh"
26#include "BKE_editmesh.hh"
27#include "BKE_mesh.hh"
28#include "BKE_modifier.hh"
29#include "BKE_scene.hh"
30
31#include "ED_mesh.hh"
32#include "ED_object.hh"
33
35
36#include "transform.hh"
38#include "transform_snap.hh"
39
40#include "transform_convert.hh"
41
42namespace blender::ed::transform {
43
44/* -------------------------------------------------------------------- */
47
50 TransCustomData *custom_data);
51
54
63
85
86#define PARTIAL_TYPE_MAX 2
87
96
102
117
119{
120 if (tcmd->cd_layer_correct != nullptr) {
122 }
123
124 for (int i = 0; i < ARRAY_SIZE(tcmd->partial_update); i++) {
125 if (tcmd->partial_update[i].cache != nullptr) {
127 }
128 }
129
130 MEM_delete(tcmd);
131}
132
134 TransDataContainer * /*tc*/,
135 TransCustomData *custom_data)
136{
137 TransCustomDataMesh *tcmd = static_cast<TransCustomDataMesh *>(custom_data->data);
139 custom_data->data = nullptr;
140}
141
143
144/* -------------------------------------------------------------------- */
147
152
156
159
160 /* Special handle for multi-resolution. */
162
163 /* Optionally merge custom-data groups (this keeps UVs connected for example). */
174
176};
177
178#define USE_FACE_SUBSTITUTE
179#ifdef USE_FACE_SUBSTITUTE
180# define FACE_SUBSTITUTE_INDEX INT_MIN
181
187{
188 BMFace *best_face = nullptr;
189 BMLoop *l;
190 BMIter liter;
191 BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
192 BMLoop *l_radial_next = l->radial_next;
193 BMFace *f_test = l_radial_next->f;
194 if (f_test == f) {
195 continue;
196 }
197 if (is_zero_v3(f_test->no)) {
198 continue;
199 }
200
201 /* Check the loops edge isn't selected. */
202 if (!BM_elem_flag_test(l_radial_next->v, BM_ELEM_SELECT) &&
203 !BM_elem_flag_test(l_radial_next->next->v, BM_ELEM_SELECT))
204 {
205 /* Prefer edges with unselected vertices.
206 * Useful for extrude. */
207 best_face = f_test;
208 break;
209 }
210 if (best_face == nullptr) {
211 best_face = f_test;
212 }
213 }
214 return best_face;
215}
216
218 BMFace *f,
219 BMFace *f_copy)
220{
222 BMesh *bm = tcld->bm;
223
225 bm->pdata, tcld->bm_origfaces->pdata);
227 bm->ldata, tcld->bm_origfaces->ldata);
228
229 /* It is impossible to calculate the loops weights of a face without area.
230 * Find a substitute. */
232 if (f_substitute) {
233 /* Copy the custom-data from the substitute face. */
234 BMLoop *l_iter, *l_first;
235 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
236 do {
237 BM_loop_interp_from_face(bm, l_iter, f_substitute, false, false);
238 } while ((l_iter = l_iter->next) != l_first);
239
240 /* Use the substitute face as the reference during the transformation. */
241 BMFace *f_substitute_copy = BM_face_copy(
242 tcld->bm_origfaces, cd_face_map, cd_loop_map, f_substitute, true, true);
243
244 /* Hack: reference substitute face in `f_copy->no`.
245 * `tcld->origfaces` is already used to restore the initial value. */
247 *(reinterpret_cast<BMFace **>(&f_copy->no[0])) = f_substitute_copy;
248 }
249}
250
252{
254 return *(reinterpret_cast<BMFace **>(&f_copy->no[0]));
255}
256
257#endif /* USE_FACE_SUBSTITUTE */
258
260 TransDataBasic *td,
261 const int index)
262{
263 BMesh *bm = tcld->bm;
264 BMVert *v = static_cast<BMVert *>(td->extra);
265 BMIter liter;
266 int j, l_num;
267 float *loop_weights;
268
270 bm->pdata, tcld->bm_origfaces->pdata);
272 bm->ldata, tcld->bm_origfaces->ldata);
273
274 // BM_ITER_ELEM (l, &liter, sv->v, BM_LOOPS_OF_VERT) {
276 l_num = liter.count;
277 Array<float, BM_DEFAULT_TOPOLOGY_STACK_SIZE> loop_weights_buf(tcld->use_merge_group ? l_num : 0);
278 loop_weights = tcld->use_merge_group ? loop_weights_buf.data() : nullptr;
279 for (j = 0; j < l_num; j++) {
280 BMLoop *l = static_cast<BMLoop *>(BM_iter_step(&liter));
281 BMLoop *l_prev, *l_next;
282
283 /* Generic custom-data correction. Copy face data. */
284 tcld->origfaces->lookup_or_add_cb(l->f, [&]() {
285 BMFace *f_copy = BM_face_copy(
286 tcld->bm_origfaces, cd_face_map, cd_loop_map, l->f, true, true);
287#ifdef USE_FACE_SUBSTITUTE
288 if (is_zero_v3(l->f->no)) {
289 mesh_customdatacorrect_face_substitute_set(tcld, l->f, f_copy);
290 }
291#endif
292 return f_copy;
293 });
294
295 if (tcld->use_merge_group) {
296 if ((l_prev = BM_loop_find_prev_nodouble(l, l->next, FLT_EPSILON)) &&
297 (l_next = BM_loop_find_next_nodouble(l, l_prev, FLT_EPSILON)))
298 {
299 loop_weights[j] = angle_v3v3v3(l_prev->v->co, l->v->co, l_next->v->co);
300 }
301 else {
302 loop_weights[j] = 0.0f;
303 }
304 }
305 }
306
307 if (tcld->use_merge_group) {
308 /* Store cd_loop_groups. */
309 TransCustomDataMergeGroup *merge_data = &tcld->merge_group.data[index];
310 if (l_num != 0) {
311 merge_data->cd_loop_groups = static_cast<LinkNode **>(BLI_memarena_alloc(
312 tcld->arena, tcld->merge_group.customdatalayer_map_len * sizeof(void *)));
313 for (j = 0; j < tcld->merge_group.customdatalayer_map_len; j++) {
314 const int layer_nr = tcld->merge_group.customdatalayer_map[j];
315 merge_data->cd_loop_groups[j] = BM_vert_loop_groups_data_layer_create(
316 bm, v, layer_nr, loop_weights, tcld->arena);
317 }
318 }
319 else {
320 merge_data->cd_loop_groups = nullptr;
321 }
322
323 tcld->merge_group.origverts->add(v, td);
324 }
325}
326
329{
330 BMesh *bm = tcld->bm;
331
332 auto *origfaces = MEM_new<Map<BMFace *, BMFace *>>(__func__);
333 BMeshCreateParams params{};
334 params.use_toolflags = false;
335 BMesh *bm_origfaces = BM_mesh_create(&bm_mesh_allocsize_default, &params);
336
337 /* We need to have matching loop custom-data. */
338 BM_mesh_copy_init_customdata_all_layers(bm_origfaces, bm, BM_LOOP, nullptr);
339
340 tcld->origfaces = origfaces;
341 tcld->bm_origfaces = bm_origfaces;
342
345}
346
349{
350 BMesh *bm = tcld->bm;
352
353 /* TODO: We don't need `layer_math_map` when there are no loops linked
354 * to one of the sliding vertices. */
355
356 /* Over allocate, only 'math' layers are indexed. */
357 int *customdatalayer_map = MEM_new_array_uninitialized<int>(bm->ldata.totlayer, __func__);
358 int layer_math_map_len = 0;
359 for (int i = 0; i < bm->ldata.totlayer; i++) {
361 customdatalayer_map[layer_math_map_len++] = i;
362 }
363 }
364 BLI_assert(layer_math_map_len != 0);
365
366 tcld->merge_group.data_len = tc->data_len + tc->data_mirror_len;
367 tcld->merge_group.customdatalayer_map = customdatalayer_map;
368 tcld->merge_group.customdatalayer_map_len = layer_math_map_len;
369 tcld->merge_group.origverts = MEM_new<Map<BMVert *, TransDataBasic *>>(__func__);
370 tcld->merge_group.origverts->reserve(tcld->merge_group.data_len);
371 tcld->merge_group.data = static_cast<TransCustomDataMergeGroup *>(BLI_memarena_alloc(
372 tcld->arena, tcld->merge_group.data_len * sizeof(*tcld->merge_group.data)));
373}
374
376 const bool use_merge_group)
377{
379
380 if (bm->shapenr > 1) {
381 /* Don't do this at all for non-basis shape keys, too easy to
382 * accidentally break uv maps or vertex colors then. */
383 /* Create copies of faces for custom-data projection. */
384 return nullptr;
385 }
387 /* There is no custom-data to correct. */
388 return nullptr;
389 }
390
392 tcld->bm = bm;
394
395 /* Init `cd_loop_mdisp_offset` to -1 to avoid problems with a valid index. */
396 tcld->cd_loop_mdisp_offset = -1;
397 tcld->use_merge_group = use_merge_group;
398
400
401 if (tcld->use_merge_group) {
403 }
404
405 {
406 /* Setup Verts. */
407 int i = 0;
408
409 TransData *tob = tc->data;
410 for (int j = tc->data_len; j--; tob++, i++) {
411 mesh_customdatacorrect_init_vert(tcld, static_cast<TransDataBasic *>(tob), i);
412 }
413
414 TransDataMirror *td_mirror = tc->data_mirror;
415 for (int j = tc->data_mirror_len; j--; td_mirror++, i++) {
416 mesh_customdatacorrect_init_vert(tcld, static_cast<TransDataBasic *>(td_mirror), i);
417 }
418 }
419
420 return tcld;
421}
422
423static void mesh_customdatacorrect_create(TransDataContainer *tc, const bool use_merge_group)
424{
425 TransCustomDataLayer *customdatacorrect;
426 customdatacorrect = mesh_customdatacorrect_create_impl(tc, use_merge_group);
427
428 if (!customdatacorrect) {
429 return;
430 }
431
433 BLI_assert(tcmd->cd_layer_correct == nullptr);
434 tcmd->cd_layer_correct = customdatacorrect;
435}
436
438{
440
441 if (tcld->bm_origfaces) {
443 }
444 MEM_delete(tcld->origfaces);
445 if (tcld->merge_group.origverts) {
446 MEM_delete(tcld->merge_group.origverts);
447 }
448 if (tcld->arena) {
450 }
451 if (tcld->merge_group.customdatalayer_map) {
452 MEM_delete(tcld->merge_group.customdatalayer_map);
453 }
454
455 MEM_delete(tcld);
456}
457
459{
460 bool use_merge_group = false;
463 /* No custom-data correction. */
464 return;
465 }
466 use_merge_group = true;
467 }
468 else if (ELEM(t->mode,
473 TFM_SHEAR,
474 TFM_BEND,
478 TFM_ALIGN))
479 {
480 {
482 /* No custom-data correction. */
483 return;
484 }
485 use_merge_group = (t->settings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT_KEEP_CONNECTED) != 0;
486 }
487 }
488 else {
489 return;
490 }
491
493 if (tc->custom.type.data != nullptr) {
494 TransCustomDataMesh *tcmd = static_cast<TransCustomDataMesh *>(tc->custom.type.data);
495 if (tcmd && tcmd->cd_layer_correct) {
497 tcmd->cd_layer_correct = nullptr;
498 }
499 }
500
501 mesh_customdatacorrect_create(tc, use_merge_group);
502 }
503}
504
506
507/* -------------------------------------------------------------------- */
510
515{
516 TransDataBasic *td = tcld->merge_group.origverts->lookup_default(v, nullptr);
517 return td ? td->iloc : v->co;
518}
519
521 TransDataBasic *td,
522 TransCustomDataMergeGroup *merge_data,
523 bool do_loop_mdisps)
524{
525 BMesh *bm = tcld->bm;
526 BMVert *v = static_cast<BMVert *>(td->extra);
527 const float *co_orig_3d = td->iloc;
528
529 BMIter liter;
530 int j, l_num;
531 float *loop_weights;
532 const bool is_moved = (len_squared_v3v3(v->co, co_orig_3d) > FLT_EPSILON);
533 const bool do_loop_weight = is_moved && tcld->merge_group.customdatalayer_map_len;
534 const float *v_proj_axis = v->no;
535 /* Original (`l->prev`, `l`, `l->next`) projections for each loop ('l' remains unchanged). */
536 float v_proj[3][3];
537
538 if (do_loop_weight) {
539 project_plane_normalized_v3_v3v3(v_proj[1], co_orig_3d, v_proj_axis);
540 }
541
542 // BM_ITER_ELEM (l, &liter, sv->v, BM_LOOPS_OF_VERT)
544 l_num = liter.count;
545 Array<float, BM_DEFAULT_TOPOLOGY_STACK_SIZE> loop_weights_buf(do_loop_weight ? l_num : 0);
546 loop_weights = do_loop_weight ? loop_weights_buf.data() : nullptr;
547 for (j = 0; j < l_num; j++) {
548 BMFace *f_copy; /* The copy of 'f'. */
549 BMLoop *l = static_cast<BMLoop *>(BM_iter_step(&liter));
550
551 f_copy = tcld->origfaces->lookup(l->f);
552
553#ifdef USE_FACE_SUBSTITUTE
554 /* In some faces it is not possible to calculate interpolation,
555 * so we use a substitute. */
558 }
559#endif
560
561 /* Only loop data, no vertex data since that contains shape keys,
562 * and we do not want to mess up other shape keys. */
563 BM_loop_interp_from_face(bm, l, f_copy, false, false);
564
565 /* Weight the loop. */
566 if (do_loop_weight) {
567 const float eps = 1.0e-8f;
568 const BMLoop *l_prev = l->prev;
569 const BMLoop *l_next = l->next;
570 const float *co_prev = mesh_vert_orig_co_get(tcld, l_prev->v);
571 const float *co_next = mesh_vert_orig_co_get(tcld, l_next->v);
572 bool co_prev_ok;
573 bool co_next_ok;
574
575 /* In the unlikely case that we're next to a zero length edge - walk around to the next.
576 *
577 * Since we only need to check if the vertex is in this corner,
578 * its not important _which_ loop - as long as its not overlapping
579 * `sv->co_orig_3d`, see: #45096. */
580 project_plane_normalized_v3_v3v3(v_proj[0], co_prev, v_proj_axis);
581 while (((co_prev_ok = (len_squared_v3v3(v_proj[1], v_proj[0]) > eps)) == false) &&
582 ((l_prev = l_prev->prev) != l->next)) [[unlikely]]
583 {
584 co_prev = mesh_vert_orig_co_get(tcld, l_prev->v);
585 project_plane_normalized_v3_v3v3(v_proj[0], co_prev, v_proj_axis);
586 }
587 project_plane_normalized_v3_v3v3(v_proj[2], co_next, v_proj_axis);
588 while (((co_next_ok = (len_squared_v3v3(v_proj[1], v_proj[2]) > eps)) == false) &&
589 ((l_next = l_next->next) != l->prev)) [[unlikely]]
590 {
591 co_next = mesh_vert_orig_co_get(tcld, l_next->v);
592 project_plane_normalized_v3_v3v3(v_proj[2], co_next, v_proj_axis);
593 }
594
595 if (co_prev_ok && co_next_ok) {
596 const float dist = dist_signed_squared_to_corner_v3v3v3(
597 v->co, UNPACK3(v_proj), v_proj_axis);
598
599 loop_weights[j] = (dist >= 0.0f) ? 1.0f : ((dist <= -eps) ? 0.0f : (1.0f + (dist / eps)));
600 if (!isfinite(loop_weights[j])) [[unlikely]] {
601 loop_weights[j] = 0.0f;
602 }
603 }
604 else {
605 loop_weights[j] = 0.0f;
606 }
607 }
608 }
609
610 if (tcld->use_merge_group) {
611 LinkNode **cd_loop_groups = merge_data->cd_loop_groups;
612 if (tcld->merge_group.customdatalayer_map_len && cd_loop_groups) {
613 if (do_loop_weight) {
614 for (j = 0; j < tcld->merge_group.customdatalayer_map_len; j++) {
616 bm, cd_loop_groups[j], tcld->merge_group.customdatalayer_map[j], loop_weights);
617 }
618 }
619 else {
620 for (j = 0; j < tcld->merge_group.customdatalayer_map_len; j++) {
622 bm, cd_loop_groups[j], tcld->merge_group.customdatalayer_map[j]);
623 }
624 }
625 }
626 }
627
628 /* Special handling for multires
629 *
630 * Interpolate from every other loop (not ideal)
631 * However values will only be taken from loops which overlap other mdisps.
632 */
633 const bool update_loop_mdisps = is_moved && do_loop_mdisps && (tcld->cd_loop_mdisp_offset != -1);
634 if (update_loop_mdisps) {
636 BMLoop *l;
637
638 BM_ITER_ELEM_INDEX (l, &liter, v, BM_LOOPS_OF_VERT, j) {
639 BM_face_calc_center_median(l->f, faces_center[j]);
640 }
641
642 BM_ITER_ELEM_INDEX (l, &liter, v, BM_LOOPS_OF_VERT, j) {
643 BMFace *f_copy = tcld->origfaces->lookup(l->f);
644 float f_copy_center[3];
645 BMIter liter_other;
646 BMLoop *l_other;
647 int j_other;
648
649 BM_face_calc_center_median(f_copy, f_copy_center);
650
651 BM_ITER_ELEM_INDEX (l_other, &liter_other, v, BM_LOOPS_OF_VERT, j_other) {
653 l_other->f,
654 f_copy,
655 faces_center[j_other],
656 f_copy_center,
658 }
659 }
660 }
661}
662
664{
665 TransCustomDataMesh *tcmd = static_cast<TransCustomDataMesh *>(tc->custom.type.data);
666 TransCustomDataLayer *tcld = tcmd ? tcmd->cd_layer_correct : nullptr;
667 if (tcld == nullptr) {
668 return;
669 }
670 const bool use_merge_group = tcld->use_merge_group;
671
672 TransCustomDataMergeGroup *merge_data = tcld->merge_group.data;
673 TransData *tob = tc->data;
674 for (int i = tc->data_len; i--; tob++) {
676 tcld, static_cast<TransDataBasic *>(tob), merge_data, is_final);
677
678 if (use_merge_group) {
679 merge_data++;
680 }
681 }
682
683 TransDataMirror *td_mirror = tc->data_mirror;
684 for (int i = tc->data_mirror_len; i--; td_mirror++) {
686 tcld, static_cast<TransDataBasic *>(td_mirror), merge_data, is_final);
687
688 if (use_merge_group) {
689 merge_data++;
690 }
691 }
692}
693
695
696/* -------------------------------------------------------------------- */
699
701{
703 TransCustomDataMesh *tcmd = static_cast<TransCustomDataMesh *>(tc->custom.type.data);
704 TransCustomDataLayer *tcld = tcmd ? tcmd->cd_layer_correct : nullptr;
705 if (!tcld) {
706 continue;
707 }
708
709 BMesh *bm = tcld->bm;
710 BMesh *bm_copy = tcld->bm_origfaces;
711 const BMCustomDataCopyMap cd_loop_map = CustomData_bmesh_copy_map_calc(bm_copy->ldata,
712 bm->ldata);
713
714 for (const auto &item : tcld->origfaces->items()) {
715 BMFace *f = item.key;
716 BMFace *f_copy = item.value;
717 BLI_assert(f->len == f_copy->len);
718
719 BMLoop *l_iter, *l_first, *l_copy;
720 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
721 l_copy = BM_FACE_FIRST_LOOP(f_copy);
722 do {
723 /* TODO: Restore only the elements that transform. */
724 BM_elem_attrs_copy(bm, cd_loop_map, l_copy, l_iter);
725 l_copy = l_copy->next;
726 } while ((l_iter = l_iter->next) != l_first);
727 }
728 }
729}
730
732
733/* -------------------------------------------------------------------- */
736
738 BMesh *bm,
739 const bool calc_single_islands,
740 const bool calc_island_center,
741 const bool calc_island_axismtx,
742 TransIslandData *r_island_data)
743{
744 TransIslandData data = {nullptr};
745
746 char htype;
747 char itype;
748 int i;
749
750 /* Group variables. */
751 int *groups_array = nullptr;
752 int (*group_index)[2] = nullptr;
753
754 bool has_only_single_islands = bm->totedgesel == 0 && bm->totfacesel == 0;
755 if (has_only_single_islands && !calc_single_islands) {
756 return;
757 }
758
759 data.island_vert_map = MEM_new_array_uninitialized<int>(bm->totvert, __func__);
760 /* We shouldn't need this, but with incorrect selection flushing
761 * its possible we have a selected vertex that's not in a face,
762 * for now best not crash in that case. */
763 std::fill_n(data.island_vert_map, bm->totvert, -1);
764
765 if (!has_only_single_islands) {
767 groups_array = MEM_new_array_uninitialized<int>(bm->totedgesel, __func__);
768 data.island_tot = BM_mesh_calc_edge_groups(
769 bm, groups_array, &group_index, nullptr, nullptr, BM_ELEM_SELECT);
770
771 htype = BM_EDGE;
773 }
774 else { /* `bm->selectmode & SCE_SELECT_FACE`. */
775 groups_array = MEM_new_array_uninitialized<int>(bm->totfacesel, __func__);
776 data.island_tot = BM_mesh_calc_face_groups(
777 bm, groups_array, &group_index, nullptr, nullptr, nullptr, BM_ELEM_SELECT, BM_VERT);
778
779 htype = BM_FACE;
781 }
782
783 BLI_assert(data.island_tot);
784 if (calc_island_center) {
785 data.center = MEM_new_array_uninitialized<float[3]>(data.island_tot, __func__);
786 }
787
788 if (calc_island_axismtx) {
789 data.axismtx = MEM_new_array_uninitialized<float[3][3]>(data.island_tot, __func__);
790 }
791
793
794 void **ele_array;
795 ele_array = (htype == BM_FACE) ? reinterpret_cast<void **>(bm->ftable) :
796 reinterpret_cast<void **>(bm->etable);
797
799
800 /* May be an edge OR a face array. */
801 for (i = 0; i < data.island_tot; i++) {
802 BMEditSelection ese = {nullptr};
803
804 const int fg_sta = group_index[i][0];
805 const int fg_len = group_index[i][1];
806 float co[3], no[3], tangent[3];
807 int j;
808
809 zero_v3(co);
810 zero_v3(no);
811 zero_v3(tangent);
812
813 ese.htype = htype;
814
815 /* Loop on each face or edge in this group:
816 * - Assign `r_vert_map`.
817 * - Calculate (`co`, `no`).
818 */
819 for (j = 0; j < fg_len; j++) {
820 ese.ele = static_cast<BMElem *>(ele_array[groups_array[fg_sta + j]]);
821
822 if (data.center) {
823 float tmp_co[3];
824 BM_editselection_center(&ese, tmp_co);
825 add_v3_v3(co, tmp_co);
826 }
827
828 if (data.axismtx) {
829 float tmp_no[3], tmp_tangent[3];
830 BM_editselection_normal(&ese, tmp_no);
831 BM_editselection_plane(&ese, tmp_tangent);
832 add_v3_v3(no, tmp_no);
833 add_v3_v3(tangent, tmp_tangent);
834 }
835
836 {
837 /* Setup vertex map. */
838 BMIter iter;
839 BMVert *v;
840
841 /* Connected edge-verts. */
842 BM_ITER_ELEM (v, &iter, ese.ele, itype) {
843 data.island_vert_map[BM_elem_index_get(v)] = i;
844 }
845 }
846 }
847
848 if (data.center) {
849 mul_v3_v3fl(data.center[i], co, 1.0f / float(fg_len));
850 }
851
852 if (data.axismtx) {
853 normalize_v3(no);
854 normalize_v3(tangent);
855
856 createSpaceNormalTangent_or_fallback(data.axismtx[i], no, tangent);
857 }
858 }
859
860 MEM_delete(groups_array);
861 MEM_delete(group_index);
862 }
863
864 /* For proportional editing we need islands of 1 so connected vertices can use it with
865 * #V3D_AROUND_LOCAL_ORIGINS. */
866 if (calc_single_islands) {
867 BMIter viter;
868 BMVert *v;
869 int group_tot_single = 0;
870
871 BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, i) {
872 if (BM_elem_flag_test(v, BM_ELEM_SELECT) && (data.island_vert_map[i] == -1)) {
873 group_tot_single += 1;
874 }
875 }
876
877 if (group_tot_single != 0) {
878 if (calc_island_center) {
879 data.center = static_cast<float (*)[3]>(MEM_realloc_uninitialized(
880 data.center, sizeof(*data.center) * (data.island_tot + group_tot_single)));
881 }
882 if (calc_island_axismtx) {
883 data.axismtx = static_cast<float (*)[3][3]>(MEM_realloc_uninitialized(
884 data.axismtx, sizeof(*data.axismtx) * (data.island_tot + group_tot_single)));
885 }
886
887 BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, i) {
888 if (BM_elem_flag_test(v, BM_ELEM_SELECT) && (data.island_vert_map[i] == -1)) {
889 data.island_vert_map[i] = data.island_tot;
890 if (data.center) {
891 copy_v3_v3(data.center[data.island_tot], v->co);
892 }
893 if (data.axismtx) {
894 if (is_zero_v3(v->no) == false) {
895 axis_dominant_v3_to_m3(data.axismtx[data.island_tot], v->no);
896 invert_m3(data.axismtx[data.island_tot]);
897 }
898 else {
899 unit_m3(data.axismtx[data.island_tot]);
900 }
901 }
902
903 data.island_tot += 1;
904 }
905 }
906 }
907 }
908
909 *r_island_data = data;
910}
911
913{
914 if (island_data->center) {
915 MEM_delete(island_data->center);
916 }
917 if (island_data->axismtx) {
918 MEM_delete(island_data->axismtx);
919 }
920 if (island_data->island_vert_map) {
921 MEM_delete(island_data->island_vert_map);
922 }
923}
924
926
927/* -------------------------------------------------------------------- */
930
931/* Propagate distance from v1 and v2 to v0. */
933 BMVert *v1,
934 BMVert *v2,
935 float *dists, /* Optionally track original index. */
936 int *index,
937 const float mtx[3][3])
938{
940 {
941 const int i0 = BM_elem_index_get(v0);
942 const int i1 = BM_elem_index_get(v1);
943
944 BLI_assert(dists[i1] != FLT_MAX);
945 if (dists[i0] <= dists[i1]) {
946 return false;
947 }
948
949 float dist0;
950
951 if (v2) {
952 /* Distance across triangle. */
953 const int i2 = BM_elem_index_get(v2);
954 BLI_assert(dists[i2] != FLT_MAX);
955 if (dists[i0] <= dists[i2]) {
956 return false;
957 }
958
959 float vm0[3], vm1[3], vm2[3];
960 mul_v3_m3v3(vm0, mtx, v0->co);
961 mul_v3_m3v3(vm1, mtx, v1->co);
962 mul_v3_m3v3(vm2, mtx, v2->co);
963
964 dist0 = geodesic_distance_propagate_across_triangle(vm0, vm1, vm2, dists[i1], dists[i2]);
965 }
966 else {
967 /* Distance along edge. */
968 float vec[3];
969 sub_v3_v3v3(vec, v1->co, v0->co);
970 mul_m3_v3(mtx, vec);
971
972 dist0 = dists[i1] + len_v3(vec);
973 }
974
975 if (dist0 < dists[i0]) {
976 dists[i0] = dist0;
977 if (index != nullptr) {
978 index[i0] = index[i1];
979 }
980 return true;
981 }
982 }
983
984 return false;
985}
986
988{
989 /* Actual loose edge. */
990 if (edge->l == nullptr) {
991 return true;
992 }
993
994 /* Loose edge due to hidden adjacent faces. */
995 BMIter iter;
996 BMFace *face;
997 BM_ITER_ELEM (face, &iter, edge, BM_FACES_OF_EDGE) {
998 if (BM_elem_flag_test(face, BM_ELEM_HIDDEN) == 0) {
999 return false;
1000 }
1001 }
1002 return true;
1003}
1004
1006 const float mtx[3][3],
1007 float *dists,
1008 int *index)
1009{
1010 BLI_LINKSTACK_DECLARE(queue, BMEdge *);
1011
1012 /* Any BM_ELEM_TAG'd edge is in 'queue_next', so we don't add in twice. */
1013 const int tag_queued = BM_ELEM_TAG;
1014 const int tag_loose = BM_ELEM_TAG_ALT;
1015
1016 BLI_LINKSTACK_DECLARE(queue_next, BMEdge *);
1017
1018 BLI_LINKSTACK_INIT(queue);
1019 BLI_LINKSTACK_INIT(queue_next);
1020
1021 {
1022 /* Set indexes and initial distances for selected vertices. */
1023 BMIter viter;
1024 BMVert *v;
1025 int i;
1026
1027 BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, i) {
1028 float dist;
1029 BM_elem_index_set(v, i); /* set_inline */
1030
1032 dist = FLT_MAX;
1033 if (index != nullptr) {
1034 index[i] = i;
1035 }
1036 }
1037 else {
1038 dist = 0.0f;
1039 if (index != nullptr) {
1040 index[i] = i;
1041 }
1042 }
1043
1044 dists[i] = dist;
1045 }
1047 }
1048
1049 {
1050 /* Add edges with at least one selected vertex to the queue. */
1051 BMIter eiter;
1052 BMEdge *e;
1053
1054 BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) {
1055
1056 /* Always clear to satisfy the assert, also predictable to leave in cleared state. */
1057 BM_elem_flag_disable(e, tag_queued);
1058
1060 continue;
1061 }
1062
1063 BMVert *v1 = e->v1;
1064 BMVert *v2 = e->v2;
1065 int i1 = BM_elem_index_get(v1);
1066 int i2 = BM_elem_index_get(v2);
1067
1068 if (dists[i1] != FLT_MAX || dists[i2] != FLT_MAX) {
1069 BLI_LINKSTACK_PUSH(queue, e);
1070 }
1072 }
1073 }
1074
1075 do {
1076 BMEdge *e;
1077
1078 while ((e = BLI_LINKSTACK_POP(queue))) {
1079 BMVert *v1 = e->v1;
1080 BMVert *v2 = e->v2;
1081 int i1 = BM_elem_index_get(v1);
1082 int i2 = BM_elem_index_get(v2);
1083
1084 if (BM_elem_flag_test(e, tag_loose) || (dists[i1] == FLT_MAX || dists[i2] == FLT_MAX)) {
1085 /* Propagate along edge from vertex with smallest to largest distance. */
1086 if (dists[i1] > dists[i2]) {
1087 std::swap(i1, i2);
1088 std::swap(v1, v2);
1089 }
1090
1091 if (bmesh_test_dist_add(v2, v1, nullptr, dists, index, mtx)) {
1092 /* Add adjacent edges to the queue if:
1093 * - Adjacent edge is loose
1094 * - Edge itself is loose
1095 * - Edge has vertex that was originally selected
1096 * In all these cases a direct distance along the edge is accurate and
1097 * required to make sure we visit all edges.
1098 *
1099 * Additionally re-add edges whose other vertex already has a known
1100 * distance, so that propagation across their adjacent faces can happen
1101 * now that this vertex distance is known too. Other edges are handled
1102 * by propagation across edges below. */
1103 const bool need_direct_distance = BM_elem_flag_test(e, tag_loose) ||
1106 BMEdge *e_other;
1107 BMIter eiter;
1108 BM_ITER_ELEM (e_other, &eiter, v2, BM_EDGES_OF_VERT) {
1109 if (e_other != e && BM_elem_flag_test(e_other, tag_queued) == 0 &&
1110 !BM_elem_flag_test(e_other, BM_ELEM_HIDDEN) &&
1111 (need_direct_distance || BM_elem_flag_test(e_other, tag_loose) ||
1112 dists[BM_elem_index_get(BM_edge_other_vert(e_other, v2))] != FLT_MAX))
1113 {
1114 BM_elem_flag_enable(e_other, tag_queued);
1115 BLI_LINKSTACK_PUSH(queue_next, e_other);
1116 }
1117 }
1118 }
1119 }
1120
1121 if (!BM_elem_flag_test(e, tag_loose)) {
1122 /* Propagate across edge to vertices in adjacent faces. */
1123 BMLoop *l;
1124 BMIter liter;
1125 BM_ITER_ELEM (l, &liter, e, BM_LOOPS_OF_EDGE) {
1127 continue;
1128 }
1129 /* Don't check hidden edges or vertices in this loop
1130 * since any hidden edge causes the face to be hidden too. */
1131 for (BMLoop *l_other = l->next->next; l_other != l; l_other = l_other->next) {
1132 BMVert *v_other = l_other->v;
1133 BLI_assert(!ELEM(v_other, v1, v2));
1134
1135 if (bmesh_test_dist_add(v_other, v1, v2, dists, index, mtx)) {
1136 /* Add adjacent edges to the queue, if they are ready to propagate across/along.
1137 * Always propagate along loose edges, and for other edges only propagate across
1138 * if both vertices have a known distances. */
1139 BMEdge *e_other;
1140 BMIter eiter;
1141 BM_ITER_ELEM (e_other, &eiter, v_other, BM_EDGES_OF_VERT) {
1142 if (e_other != e && BM_elem_flag_test(e_other, tag_queued) == 0 &&
1143 !BM_elem_flag_test(e_other, BM_ELEM_HIDDEN) &&
1144 (BM_elem_flag_test(e_other, tag_loose) ||
1145 dists[BM_elem_index_get(BM_edge_other_vert(e_other, v_other))] != FLT_MAX))
1146 {
1147 BM_elem_flag_enable(e_other, tag_queued);
1148 BLI_LINKSTACK_PUSH(queue_next, e_other);
1149 }
1150 }
1151 }
1152 }
1153 }
1154 }
1155 }
1156
1157 /* Clear for the next loop. */
1158 for (LinkNode *lnk = queue_next; lnk; lnk = lnk->next) {
1159 BMEdge *e_link = static_cast<BMEdge *>(lnk->link);
1160
1161 BM_elem_flag_disable(e_link, tag_queued);
1162 }
1163
1164 BLI_LINKSTACK_SWAP(queue, queue_next);
1165
1166 /* None should be tagged now since 'queue_next' is empty. */
1167 BLI_assert(BM_iter_mesh_count_flag(BM_EDGES_OF_MESH, bm, tag_queued, true) == 0);
1168 } while (BLI_LINKSTACK_SIZE(queue));
1169
1170 BLI_LINKSTACK_FREE(queue);
1171 BLI_LINKSTACK_FREE(queue_next);
1172}
1173
1175
1176/* -------------------------------------------------------------------- */
1179
1180/* Used for both mirror epsilon and TD_MIRROR_EDGE_ */
1181#define TRANSFORM_MAXDIST_MIRROR 0.00002f
1182
1183static bool is_in_quadrant_v3(const float co[3], const int quadrant[3], const float epsilon)
1184{
1185 if (quadrant[0] && ((co[0] * quadrant[0]) < -epsilon)) {
1186 return false;
1187 }
1188 if (quadrant[1] && ((co[1] * quadrant[1]) < -epsilon)) {
1189 return false;
1190 }
1191 if (quadrant[2] && ((co[2] * quadrant[2]) < -epsilon)) {
1192 return false;
1193 }
1194 return true;
1195}
1196
1198 BMesh *bm,
1199 const bool use_select,
1200 const bool use_topology,
1201 const bool mirror_axis[3],
1202 TransMirrorData *r_mirror_data)
1203{
1204 MirrorDataVert *vert_map;
1205
1206 BMVert *eve;
1207 BMIter iter;
1208 int i, flag, totvert = bm->totvert;
1209
1210 vert_map = MEM_new_array_zeroed<MirrorDataVert>(totvert, __func__);
1211
1212 float select_sum[3] = {0};
1213 BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
1214 vert_map[i] = MirrorDataVert{-1, 0};
1216 continue;
1217 }
1219 add_v3_v3(select_sum, eve->co);
1220 }
1221 }
1222
1223 /* Tag only elements that will be transformed within the quadrant. */
1224 int quadrant[3];
1225 for (int a = 0; a < 3; a++) {
1226 if (mirror_axis[a]) {
1227 quadrant[a] = select_sum[a] >= 0.0f ? 1 : -1;
1228 }
1229 else {
1230 quadrant[a] = 0;
1231 }
1232 }
1233
1234 uint mirror_elem_len = 0;
1235 int *index[3] = {nullptr, nullptr, nullptr};
1236 bool is_single_mirror_axis = (mirror_axis[0] + mirror_axis[1] + mirror_axis[2]) == 1;
1237 bool test_selected_only = use_select && is_single_mirror_axis;
1238 for (int a = 0; a < 3; a++) {
1239 if (!mirror_axis[a]) {
1240 continue;
1241 }
1242
1243 index[a] = MEM_new_array_uninitialized<int>(totvert, __func__);
1245 bm,
1246 a,
1247 false,
1248 test_selected_only,
1249 true,
1250 use_topology,
1252 index[a]);
1253
1254 flag = TD_MIRROR_X << a;
1255 BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
1256 int i_mirr = index[a][i];
1257 if (i_mirr < 0) {
1258 continue;
1259 }
1261 continue;
1262 }
1263 if (use_select && !BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
1264 continue;
1265 }
1266 if (!is_in_quadrant_v3(eve->co, quadrant, TRANSFORM_MAXDIST_MIRROR)) {
1267 continue;
1268 }
1269 if (vert_map[i_mirr].flag != 0) {
1270 /* One mirror per element.
1271 * It can happen when vertices occupy the same position. */
1272 continue;
1273 }
1274 if (vert_map[i].flag & flag) {
1275 /* It's already a mirror.
1276 * Avoid a mirror vertex dependency cycle.
1277 * This can happen when the vertices are within the mirror threshold. */
1278 continue;
1279 }
1280
1281 vert_map[i_mirr] = MirrorDataVert{i, flag};
1282 mirror_elem_len++;
1283 }
1284 }
1285
1286 if (!mirror_elem_len) {
1287 MEM_delete(vert_map);
1288 vert_map = nullptr;
1289 }
1290 else if (!is_single_mirror_axis) {
1291 /* Adjustment for elements that are mirrors of mirrored elements. */
1292 for (int a = 0; a < 3; a++) {
1293 if (!mirror_axis[a]) {
1294 continue;
1295 }
1296
1297 flag = TD_MIRROR_X << a;
1298 for (i = 0; i < totvert; i++) {
1299 int i_mirr = index[a][i];
1300 if (i_mirr < 0) {
1301 continue;
1302 }
1303 if (vert_map[i].index != -1 && !(vert_map[i].flag & flag)) {
1304 if (vert_map[i_mirr].index == -1) {
1305 mirror_elem_len++;
1306 }
1307 vert_map[i_mirr].index = vert_map[i].index;
1308 vert_map[i_mirr].flag |= vert_map[i].flag | flag;
1309 }
1310 }
1311 }
1312 }
1313
1314 MEM_SAFE_DELETE(index[0]);
1315 MEM_SAFE_DELETE(index[1]);
1316 MEM_SAFE_DELETE(index[2]);
1317
1318 r_mirror_data->vert_map = vert_map;
1319 r_mirror_data->mirror_elem_len = mirror_elem_len;
1320}
1321
1323{
1324 if (mirror_data->vert_map) {
1325 MEM_delete(mirror_data->vert_map);
1326 }
1327}
1328
1330
1331/* -------------------------------------------------------------------- */
1334
1337 TransMeshDataCrazySpace *r_crazyspace_data)
1338{
1339 float (*quats)[4] = nullptr;
1340 const int prop_mode = (t->flag & T_PROP_EDIT) ? (t->flag & T_PROP_EDIT_ALL) : 0;
1341 if (BKE_modifiers_get_cage_index(t->scene, tc->obedit, nullptr, true) != -1) {
1342 Array<float3, 0> defcos;
1343 int totleft = -1;
1346
1347 /* Use evaluated state because we need b-bone cache. */
1348 Scene *scene_eval = DEG_get_evaluated(t->depsgraph, t->scene);
1349 Object *obedit_eval = DEG_get_evaluated(t->depsgraph, tc->obedit);
1350 /* We always want the edit-mesh (evaluation may clear it). */
1352 /* Check if we can use deform matrices for modifier from the
1353 * start up to stack, they are more accurate than quats. */
1355 t->depsgraph, scene_eval, obedit_eval, em, r_crazyspace_data->defmats, defcos);
1356 }
1357
1358 /* If we still have more modifiers, also do crazy-space
1359 * correction with \a quats, relative to the coordinates after
1360 * the modifiers that support deform matrices \a defcos. */
1361
1362#if 0 /* TODO(@ideasman42): fix crazy-space & extrude so it can be enabled for general use. */
1363 if ((totleft > 0) || (totleft == -1))
1364#else
1365 if (totleft > 0)
1366#endif
1367 {
1369 tc->obedit);
1371 quats = MEM_new_array_uninitialized<float[4]>(bm->totvert, "crazy quats");
1372 BKE_crazyspace_set_quats_editmesh(bm, defcos, mappedcos, quats, !prop_mode);
1373 }
1374 }
1375 r_crazyspace_data->quats = quats;
1376}
1377
1379 const float smtx[3][3],
1380 const float defmat[3][3],
1381 const float quat[4],
1382 TransData *r_td)
1383{
1384 /* CrazySpace. */
1385 if (quat || defmat) {
1386 float mat[3][3], qmat[3][3], imat[3][3];
1387
1388 /* Use both or either quat and defmat correction. */
1389 if (quat) {
1390 quat_to_mat3(qmat, quat);
1391
1392 if (defmat) {
1393 mul_m3_series(mat, defmat, qmat, mtx);
1394 }
1395 else {
1396 mul_m3_m3m3(mat, mtx, qmat);
1397 }
1398 }
1399 else {
1400 mul_m3_m3m3(mat, mtx, defmat);
1401 }
1402
1403 invert_m3_m3(imat, mat);
1404
1405 copy_m3_m3(r_td->smtx, imat);
1406 copy_m3_m3(r_td->mtx, mat);
1407 }
1408 else {
1409 copy_m3_m3(r_td->smtx, smtx);
1410 copy_m3_m3(r_td->mtx, mtx);
1411 }
1412}
1413
1415{
1416 if (r_crazyspace_data->quats) {
1417 MEM_delete(r_crazyspace_data->quats);
1418 }
1419}
1420
1422
1423/* -------------------------------------------------------------------- */
1426
1427static void mesh_transdata_center_copy(const TransIslandData *island_data,
1428 const int island_index,
1429 const float iloc[3],
1430 float r_center[3])
1431{
1432 if (island_data->center && island_index != -1) {
1433 copy_v3_v3(r_center, island_data->center[island_index]);
1434 }
1435 else {
1436 copy_v3_v3(r_center, iloc);
1437 }
1438}
1439
1440/* Way to overwrite what data is edited with transform. */
1442 TransData *td,
1444 BMEditMesh *em,
1445 BMVert *eve,
1446 const TransIslandData *island_data,
1447 const int island_index)
1448{
1449 float *no, _no[3];
1451
1452 td->flag = 0;
1453 // if (key)
1454 // td->loc = key->co;
1455 // else
1456 td->loc = eve->co;
1457 copy_v3_v3(td->iloc, td->loc);
1458
1459 if ((t->mode == TFM_SHRINKFATTEN) && (em->selectmode & SCE_SELECT_FACE) &&
1461 {
1462 no = _no;
1463 }
1464 else {
1465 no = eve->no;
1466 }
1467
1468 mesh_transdata_center_copy(island_data, island_index, td->iloc, td->center);
1469
1470 if ((island_index != -1) && island_data->axismtx) {
1471 copy_m3_m3(td->axismtx, island_data->axismtx[island_index]);
1472 }
1473 else if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
1474 createSpaceNormal(td->axismtx, no);
1475 }
1476 else {
1477 /* Setting normals. */
1478 copy_v3_v3(td->axismtx[2], no);
1479 td->axismtx[0][0] = td->axismtx[0][1] = td->axismtx[0][2] = td->axismtx[1][0] =
1480 td->axismtx[1][1] = td->axismtx[1][2] = 0.0f;
1481 }
1482
1483 td->val = nullptr;
1484 td->extra = eve;
1485 if (t->mode == TFM_SHRINKFATTEN) {
1487 }
1488}
1489
1491{
1493 TransDataExtension *tx = nullptr;
1494 BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
1495 Mesh *mesh = id_cast<Mesh *>(tc->obedit->data);
1497 BMVert *eve;
1498 BMIter iter;
1499 float mtx[3][3], smtx[3][3];
1500 int a;
1501 const int prop_mode = (t->flag & T_PROP_EDIT) ? (t->flag & T_PROP_EDIT_ALL) : 0;
1502
1503 TransIslandData island_data = {nullptr};
1504 TransMirrorData mirror_data = {nullptr};
1505 TransMeshDataCrazySpace crazyspace_data = {};
1506
1507 /* Avoid editing locked shapes. */
1508 if (t->mode != TFM_DUMMY && object::shape_key_report_if_locked(tc->obedit, t->reports)) {
1509 continue;
1510 }
1511
1518
1519 /* Support other objects using proportional editing to adjust these, unless connected is
1520 * enabled. */
1521 if ((!prop_mode || (prop_mode & T_PROP_CONNECTED)) && (bm->totvertsel == 0)) {
1522 continue;
1523 }
1524
1525 int data_len = 0;
1526 if (prop_mode) {
1527 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
1528 if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
1529 data_len++;
1530 }
1531 }
1532 }
1533 else {
1534 data_len = bm->totvertsel;
1535 }
1536
1537 if (data_len == 0) {
1538 continue;
1539 }
1540
1541 /* Snap rotation along normal needs a common axis for whole islands,
1542 * otherwise one get random crazy results, see #59104.
1543 * However, we do not want to use the island center for the pivot/translation reference. */
1544 const bool is_snap_rotate = ((t->mode == TFM_TRANSLATION) &&
1545 /* There is not guarantee that snapping
1546 * is initialized yet at this point... */
1547 (usingSnappingNormal(t) ||
1548 (t->settings->snap_flag & SCE_SNAP_ROTATE) != 0) &&
1550
1551 /* Even for translation this is needed because of island-orientation, see: #51651. */
1552 const bool is_island_center = (t->around == V3D_AROUND_LOCAL_ORIGINS) || is_snap_rotate;
1553 if (is_island_center) {
1554 /* In this specific case, near-by vertices will need to know
1555 * the island of the nearest connected vertex. */
1556 const bool calc_single_islands = ((prop_mode & T_PROP_CONNECTED) &&
1559
1560 const bool calc_island_center = !is_snap_rotate;
1561 /* The island axismtx is only necessary in some modes.
1562 * TODO(Germano): Extend the list to exclude other modes. */
1563 const bool calc_island_axismtx = !ELEM(t->mode, TFM_SHRINKFATTEN);
1564
1566 em, bm, calc_single_islands, calc_island_center, calc_island_axismtx, &island_data);
1567 }
1568
1569 copy_m3_m4(mtx, tc->obedit->object_to_world().ptr());
1570 /* We use a pseudo-inverse so that when one of the axes is scaled to 0,
1571 * matrix inversion still works and we can still moving along the other. */
1573
1574 /* Original index of our connected vertex when connected distances are calculated.
1575 * Optional, allocate if needed. */
1576 int *dists_index = nullptr;
1577 float *dists = nullptr;
1578 if (prop_mode & T_PROP_CONNECTED) {
1579 dists = MEM_new_array_uninitialized<float>(bm->totvert, __func__);
1580 if (is_island_center) {
1581 dists_index = MEM_new_array_uninitialized<int>(bm->totvert, __func__);
1582 }
1583 transform_convert_mesh_connectivity_distance(bm, mtx, dists, dists_index);
1584 }
1585
1586 /* Create TransDataMirror. */
1587 if (tc->use_mirror_axis_any) {
1588 bool use_topology = (mesh->editflag & ME_EDIT_MIRROR_TOPO) != 0;
1589 bool use_select = (t->flag & T_PROP_EDIT) == 0;
1590 const bool mirror_axis[3] = {
1591 bool(tc->use_mirror_axis_x), bool(tc->use_mirror_axis_y), bool(tc->use_mirror_axis_z)};
1593 em, bm, use_select, use_topology, mirror_axis, &mirror_data);
1594
1595 if (mirror_data.vert_map) {
1596 tc->data_mirror_len = mirror_data.mirror_elem_len;
1597 tc->data_mirror = MEM_new_array_zeroed<TransDataMirror>(mirror_data.mirror_elem_len,
1598 __func__);
1599
1600 BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, a) {
1601 if (prop_mode || BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
1602 if (mirror_data.vert_map[a].index != -1) {
1603 data_len--;
1604 }
1605 }
1606 }
1607 }
1608 }
1609
1610 /* Detect CrazySpace [tm]. */
1611 transform_convert_mesh_crazyspace_detect(t, tc, &crazyspace_data);
1612
1613 /* Create TransData. */
1614 BLI_assert(data_len >= 1);
1615 tc->data_len = data_len;
1616 tc->data = MEM_new_array_zeroed<TransData>(data_len, "TransObData(Mesh EditMode)");
1617 if (t->mode == TFM_SHRINKFATTEN) {
1618 /* Warning: this is overkill, we only need 2 extra floats,
1619 * but this stores loads of extra stuff, for TFM_SHRINKFATTEN its even more overkill
1620 * since we may not use the 'alt' transform mode to maintain shell thickness,
1621 * but with generic transform code its hard to lazy init variables. */
1622 tx = tc->data_ext = MEM_new_array_zeroed<TransDataExtension>(tc->data_len,
1623 "TransObData ext");
1624 }
1625
1626 TransData *tob = tc->data;
1627 TransDataMirror *td_mirror = tc->data_mirror;
1628 BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, a) {
1630 continue;
1631 }
1632
1633 int island_index = -1;
1634 if (island_data.island_vert_map) {
1635 const int connected_index = (dists_index && dists_index[a] != -1) ? dists_index[a] : a;
1636 island_index = island_data.island_vert_map[connected_index];
1637 }
1638
1639 if (mirror_data.vert_map && mirror_data.vert_map[a].index != -1) {
1640 int elem_index = mirror_data.vert_map[a].index;
1641 BMVert *v_src = BM_vert_at_index(bm, elem_index);
1642
1644 mirror_data.vert_map[a].flag |= TD_SELECTED;
1645 }
1646
1647 td_mirror->extra = eve;
1648 td_mirror->loc = eve->co;
1649 copy_v3_v3(td_mirror->iloc, eve->co);
1650 td_mirror->flag = mirror_data.vert_map[a].flag;
1651 td_mirror->loc_src = v_src->co;
1652 mesh_transdata_center_copy(&island_data, island_index, td_mirror->iloc, td_mirror->center);
1653
1654 td_mirror++;
1655 }
1656 else if (prop_mode || BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
1657 /* Do not use the island center in case we are using islands
1658 * only to get axis for snap/rotate to normal... */
1659 VertsToTransData(t, tob, tx, em, eve, &island_data, island_index);
1660 if (tx) {
1661 tx++;
1662 }
1663
1664 /* Selected. */
1666 tob->flag |= TD_SELECTED;
1667 }
1668
1669 if (prop_mode) {
1670 if (prop_mode & T_PROP_CONNECTED) {
1671 tob->dist = dists[a];
1672 }
1673 else {
1674 tob->dist = FLT_MAX;
1675 }
1676 }
1677
1678 /* CrazySpace. */
1680 mtx,
1681 smtx,
1682 !crazyspace_data.defmats.is_empty() ? crazyspace_data.defmats[a].ptr() : nullptr,
1683 crazyspace_data.quats && BM_elem_flag_test(eve, BM_ELEM_TAG) ?
1684 crazyspace_data.quats[a] :
1685 nullptr,
1686 tob);
1687
1688 if (tc->use_mirror_axis_any) {
1689 if (tc->use_mirror_axis_x && fabsf(tob->loc[0]) < TRANSFORM_MAXDIST_MIRROR) {
1690 tob->flag |= TD_MIRROR_EDGE_X;
1691 }
1692 if (tc->use_mirror_axis_y && fabsf(tob->loc[1]) < TRANSFORM_MAXDIST_MIRROR) {
1693 tob->flag |= TD_MIRROR_EDGE_Y;
1694 }
1695 if (tc->use_mirror_axis_z && fabsf(tob->loc[2]) < TRANSFORM_MAXDIST_MIRROR) {
1696 tob->flag |= TD_MIRROR_EDGE_Z;
1697 }
1698 }
1699
1700 tob++;
1701 }
1702 }
1703
1707 if (dists) {
1708 MEM_delete(dists);
1709 }
1710 if (dists_index) {
1711 MEM_delete(dists_index);
1712 }
1713
1714 /* WORKAROUND: The transform operators rely on looptris being up-to-date.
1715 * However, this is not always the case, especially when called from scripts.
1716 * If this happens, to prevent update issues, make sure the size of #BMEditMesh::looptris
1717 * arrays aligns with the number looptris to update. */
1718 const bool looptri_is_dirty = em->looptris.size() !=
1720 if (looptri_is_dirty) {
1722 }
1723 }
1724}
1725
1727
1728/* -------------------------------------------------------------------- */
1731
1734 enum ePartialType partial_type)
1735{
1737
1738 TransCustomData_PartialUpdate *pupdate = &tcmd->partial_update[partial_type];
1739
1740 if (pupdate->cache) {
1741
1742 /* Recalculate partial update data when the proportional editing size changes.
1743 *
1744 * Note that decreasing the proportional editing size requires the existing
1745 * partial data is used before recreating this partial data at the smaller size.
1746 * Since excluding geometry from being transformed requires an update.
1747 *
1748 * Extra logic is needed to account for this situation. */
1749
1750 bool recalc;
1751 if (pupdate->prop_size_prev < t->prop_size) {
1752 /* Size increase, simply recalculate. */
1753 recalc = true;
1754 }
1755 else if (pupdate->prop_size_prev > t->prop_size) {
1756 /* Size decreased, first use this partial data since reducing the size will transform
1757 * geometry which needs recalculating. */
1758 pupdate->prop_size_prev = t->prop_size;
1759 recalc = false;
1760 }
1761 else if (pupdate->prop_size != t->prop_size) {
1762 BLI_assert(pupdate->prop_size > pupdate->prop_size_prev);
1763 recalc = true;
1764 }
1765 else {
1766 BLI_assert(t->prop_size == pupdate->prop_size_prev);
1767 recalc = false;
1768 }
1769
1770 if (!recalc) {
1771 return pupdate->cache;
1772 }
1773
1775 pupdate->cache = nullptr;
1776 }
1777
1779
1781
1782 /* Only use `verts_group` or `verts_mask`. */
1783 Array<int> verts_group;
1784 int verts_group_count = 0; /* Number of non-zero elements in `verts_group`. */
1785
1786 BitVector<> verts_mask;
1787 int verts_mask_count = 0; /* Number of elements enabled in `verts_mask`. */
1788
1789 if ((partial_type == PARTIAL_TYPE_GROUP) && ((t->flag & T_PROP_EDIT) || tc->use_mirror_axis_any))
1790 {
1791 verts_group = Array<int>(bm->totvert, 0);
1792 int i;
1793 TransData *td;
1794 for (i = 0, td = tc->data; i < tc->data_len; i++, td++) {
1795 if (td->factor == 0.0f) {
1796 continue;
1797 }
1798 const BMVert *v = static_cast<BMVert *>(td->extra);
1799 const int v_index = BM_elem_index_get(v);
1800 BLI_assert(verts_group[v_index] == 0);
1801 if (td->factor < 1.0f) {
1802 /* Don't use grouping logic with the factor is under 1.0. */
1803 verts_group[v_index] = -1;
1804 }
1805 else {
1806 BLI_assert(td->factor == 1.0f);
1807 verts_group[v_index] = 1;
1808 if (tc->use_mirror_axis_any) {
1809 /* Use bits 2-4 for central alignment (don't overlap the first bit). */
1810 const int flag = td->flag & (TD_MIRROR_EDGE_X | TD_MIRROR_EDGE_Y | TD_MIRROR_EDGE_Z);
1811 verts_group[v_index] |= (flag >> TD_MIRROR_EDGE_AXIS_SHIFT) << 1;
1812 }
1813 }
1814 verts_mask_count += 1;
1815 }
1816
1817 TransDataMirror *td_mirror = tc->data_mirror;
1818 for (i = 0; i < tc->data_mirror_len; i++, td_mirror++) {
1819 BMVert *v_mirr = reinterpret_cast<BMVert *> POINTER_OFFSET(td_mirror->loc_src,
1820 -offsetof(BMVert, co));
1821 /* The equality check is to account for the case when topology mirror moves
1822 * the vertex from it's original location to match it's symmetrical position,
1823 * with proportional editing enabled. */
1824 const int v_mirr_index = BM_elem_index_get(v_mirr);
1825 if (verts_group[v_mirr_index] == 0 && equals_v3v3(td_mirror->loc, td_mirror->iloc)) {
1826 continue;
1827 }
1828
1829 BMVert *v_mirr_other = static_cast<BMVert *>(td_mirror->extra);
1830 /* This assert should never fail since there is no overlap
1831 * between mirrored vertices and non-mirrored. */
1832 BLI_assert(verts_group[BM_elem_index_get(v_mirr_other)] == 0);
1833 const int v_mirr_other_index = BM_elem_index_get(v_mirr_other);
1834
1835 if (verts_group[v_mirr_index] == -1) {
1836 verts_group[v_mirr_other_index] = -1;
1837 }
1838 else {
1839 /* Use bits 5-8 for mirror (don't overlap previous bits). */
1840 const int flag = td_mirror->flag & (TD_MIRROR_X | TD_MIRROR_Y | TD_MIRROR_Z);
1841 verts_group[v_mirr_other_index] |= (flag >> TD_MIRROR_EDGE_AXIS_SHIFT) << 4;
1842 }
1843 verts_mask_count += 1;
1844 }
1845 }
1846 else {
1847 /* See the body of the comments in the previous block for details. */
1848 verts_mask.resize(bm->totvert);
1849 int i;
1850 TransData *td;
1851 for (i = 0, td = tc->data; i < tc->data_len; i++, td++) {
1852 if (td->factor == 0.0f) {
1853 continue;
1854 }
1855 const BMVert *v = static_cast<BMVert *>(td->extra);
1856 const int v_index = BM_elem_index_get(v);
1857 BLI_assert(!verts_mask[v_index]);
1858 verts_mask[v_index].set();
1859 verts_mask_count += 1;
1860 }
1861
1862 TransDataMirror *td_mirror = tc->data_mirror;
1863 for (i = 0; i < tc->data_mirror_len; i++, td_mirror++) {
1864 BMVert *v_mirr = reinterpret_cast<BMVert *> POINTER_OFFSET(td_mirror->loc_src,
1865 -offsetof(BMVert, co));
1866 if (!verts_mask[BM_elem_index_get(v_mirr)] && equals_v3v3(td_mirror->loc, td_mirror->iloc)) {
1867 continue;
1868 }
1869
1870 BMVert *v_mirr_other = static_cast<BMVert *>(td_mirror->extra);
1871 BLI_assert(!verts_mask[BM_elem_index_get(v_mirr_other)]);
1872 const int v_mirr_other_index = BM_elem_index_get(v_mirr_other);
1873 verts_mask[v_mirr_other_index].set();
1874 verts_mask_count += 1;
1875 }
1876 }
1877
1878 switch (partial_type) {
1879 case PARTIAL_TYPE_ALL: {
1880 BMPartialUpdate_Params params{};
1881 params.do_tessellate = true;
1882 params.do_normals = true;
1884 *bm, params, verts_mask, verts_mask_count);
1885 break;
1886 }
1887 case PARTIAL_TYPE_GROUP: {
1888 BMPartialUpdate_Params params{};
1889 params.do_tessellate = true;
1890 params.do_normals = true;
1891 pupdate->cache = (!verts_group.is_empty() ?
1893 *bm, params, verts_group, verts_group_count) :
1895 *bm, params, verts_mask, verts_mask_count));
1896 break;
1897 }
1898 case PARTIAL_NONE: {
1900 }
1901 }
1902
1903 pupdate->prop_size_prev = t->prop_size;
1904 pupdate->prop_size = t->prop_size;
1905
1906 return pupdate->cache;
1907}
1908
1909static void mesh_partial_types_calc(TransInfo *t, PartialTypeState *r_partial_state)
1910{
1911 /* Calculate the kind of partial updates which can be performed. */
1912 enum ePartialType partial_for_normals = PARTIAL_NONE;
1913 enum ePartialType partial_for_looptris = PARTIAL_NONE;
1914
1915 /* Note that operations such as #TFM_CREASE are not handled here
1916 * (if they were, leaving as #PARTIAL_NONE would be appropriate). */
1917 switch (t->mode) {
1918 case TFM_TRANSLATION: {
1919 partial_for_looptris = PARTIAL_TYPE_GROUP;
1920 partial_for_normals = PARTIAL_TYPE_GROUP;
1921 /* Translation can rotate when snapping to normal. */
1923 partial_for_normals = PARTIAL_TYPE_ALL;
1924 }
1925 break;
1926 }
1927 case TFM_ROTATION: {
1928 partial_for_looptris = PARTIAL_TYPE_GROUP;
1929 partial_for_normals = PARTIAL_TYPE_ALL;
1930 break;
1931 }
1932 case TFM_RESIZE: {
1933 /* Ensure zero (or small) scale calculates normals, see: #159460. */
1934 const float zero_resize_threshold_all = 1e-6f;
1935
1936 partial_for_looptris = PARTIAL_TYPE_GROUP;
1937 partial_for_normals = PARTIAL_TYPE_GROUP;
1938 /* Non-uniform scale needs to recalculate all normals
1939 * since their relative locations change.
1940 * Uniform negative scale can keep normals as-is since the faces are flipped,
1941 * normals remain unchanged. */
1942 if ((t->con.mode & CON_APPLY) ||
1943 /* NOTE(@ideasman42): negative values always recalculate, this is intentional
1944 * although it switches between negative and positive uniform scales could be
1945 * detected (minor optimization, not so important). */
1946 ((t->values_final[0] <= zero_resize_threshold_all) ||
1947 (t->values_final[1] <= zero_resize_threshold_all) ||
1948 (t->values_final[2] <= zero_resize_threshold_all)) ||
1949 (t->values_final[0] != t->values_final[1] || t->values_final[0] != t->values_final[2]))
1950 {
1951 partial_for_normals = PARTIAL_TYPE_ALL;
1952 }
1953 break;
1954 }
1955 default: {
1956 partial_for_looptris = PARTIAL_TYPE_ALL;
1957 partial_for_normals = PARTIAL_TYPE_ALL;
1958 break;
1959 }
1960 }
1961
1962 /* With projection, transform isn't affine. */
1964 if (partial_for_looptris == PARTIAL_TYPE_GROUP) {
1965 partial_for_looptris = PARTIAL_TYPE_ALL;
1966 }
1967 if (partial_for_normals == PARTIAL_TYPE_GROUP) {
1968 partial_for_normals = PARTIAL_TYPE_ALL;
1969 }
1970 }
1971
1972 r_partial_state->for_looptris = partial_for_looptris;
1973 r_partial_state->for_normals = partial_for_normals;
1974}
1975
1978 const PartialTypeState *partial_state)
1979{
1982
1984
1985 const PartialTypeState *partial_state_prev = &tcmd->partial_update_state_prev;
1986
1987 /* Promote the partial update types based on the previous state
1988 * so the values that no longer modified are reset before being left as-is.
1989 * Needed for translation which can toggle snap-to-normal during transform. */
1990 const enum ePartialType partial_for_looptris = std::max(partial_state->for_looptris,
1991 partial_state_prev->for_looptris);
1992 const enum ePartialType partial_for_normals = std::max(partial_state->for_normals,
1993 partial_state_prev->for_normals);
1994
1995 if ((partial_for_looptris == PARTIAL_TYPE_ALL) && (partial_for_normals == PARTIAL_TYPE_ALL) &&
1996 (bm->totvert == bm->totvertsel))
1997 {
1998 /* The additional cost of generating the partial connectivity data isn't justified
1999 * when all data needs to be updated.
2000 *
2001 * While proportional editing can cause all geometry to need updating with a partial
2002 * selection. It's impractical to calculate this ahead of time. Further, the down side of
2003 * using partial updates when their not needed is negligible. */
2005 }
2006 else {
2007 if (partial_for_looptris != PARTIAL_NONE) {
2008 BMPartialUpdate *bmpinfo = mesh_partial_ensure(t, tc, partial_for_looptris);
2010 params.face_normals = true;
2011 BKE_editmesh_looptris_calc_with_partial_ex(em, bm, bmpinfo, &params);
2012 }
2013
2014 if (partial_for_normals != PARTIAL_NONE) {
2015 BMPartialUpdate *bmpinfo = mesh_partial_ensure(t, tc, partial_for_normals);
2016 /* While not a large difference, take advantage of existing normals where possible. */
2017 const bool face_normals = !((partial_for_looptris == PARTIAL_TYPE_ALL) ||
2018 ((partial_for_looptris == PARTIAL_TYPE_GROUP) &&
2019 (partial_for_normals == PARTIAL_TYPE_GROUP)));
2021 params.face_normals = face_normals;
2022 BM_mesh_normals_update_with_partial_ex(bm, bmpinfo, &params);
2023 }
2024 }
2025
2026 /* Store the previous requested (not the previous used),
2027 * since the values used may have been promoted based on the previous types. */
2028 tcmd->partial_update_state_prev = *partial_state;
2029}
2030
2032
2033/* -------------------------------------------------------------------- */
2036
2038{
2039 if (tc->use_mirror_axis_any) {
2040 int i;
2041 TransData *td;
2042 for (i = 0, td = tc->data; i < tc->data_len; i++, td++) {
2044 if (td->flag & TD_MIRROR_EDGE_X) {
2045 td->loc[0] = 0.0f;
2046 }
2047 if (td->flag & TD_MIRROR_EDGE_Y) {
2048 td->loc[1] = 0.0f;
2049 }
2050 if (td->flag & TD_MIRROR_EDGE_Z) {
2051 td->loc[2] = 0.0f;
2052 }
2053 }
2054 }
2055
2056 TransDataMirror *td_mirror = tc->data_mirror;
2057 for (i = 0; i < tc->data_mirror_len; i++, td_mirror++) {
2058 copy_v3_v3(td_mirror->loc, td_mirror->loc_src);
2059 if (td_mirror->flag & TD_MIRROR_X) {
2060 td_mirror->loc[0] *= -1;
2061 }
2062 if (td_mirror->flag & TD_MIRROR_Y) {
2063 td_mirror->loc[1] *= -1;
2064 }
2065 if (td_mirror->flag & TD_MIRROR_Z) {
2066 td_mirror->loc[2] *= -1;
2067 }
2068 }
2069 }
2070}
2071
2073{
2074 if (t->mode == TFM_NORMAL_ROTATION) {
2076 /* The Rotate Normal mode uses a custom array and ignores any elements created for the mesh
2077 * in transData and similar structures. */
2078 DEG_id_tag_update(tc->obedit->data, ID_RECALC_GEOMETRY);
2079 }
2080 return;
2081 }
2082
2083 bool is_canceling = t->state == TRANS_CANCEL;
2084 /* Apply corrections. */
2085 if (!is_canceling) {
2087
2088 bool do_mirror = !(t->flag & T_NO_MIRROR);
2090 /* Apply clipping after so we never project past the clip plane #25423. */
2092
2093 if (do_mirror) {
2095 }
2096
2098 }
2099 }
2100 else {
2102 }
2103
2104 PartialTypeState partial_state;
2105 mesh_partial_types_calc(t, &partial_state);
2106
2108 DEG_id_tag_update(tc->obedit->data, ID_RECALC_GEOMETRY);
2109
2110 /* Transformation is not affine when the mirror modifier's clipping boundary is hit so
2111 * normal calculation does not have to be skipped. */
2112 if (tc->has_mirror_clipping) {
2113 if (partial_state.for_looptris == PARTIAL_TYPE_GROUP) {
2114 partial_state.for_looptris = PARTIAL_TYPE_ALL;
2115 }
2116 if (partial_state.for_normals == PARTIAL_TYPE_GROUP) {
2117 partial_state.for_normals = PARTIAL_TYPE_ALL;
2118 }
2119 }
2120
2121 mesh_partial_update(t, tc, &partial_state);
2122 }
2123}
2124
2126
2127/* -------------------------------------------------------------------- */
2130
2132{
2133 const bool is_canceling = (t->state == TRANS_CANCEL);
2134 const bool use_automerge = !is_canceling && (t->flag & (T_AUTOMERGE | T_AUTOSPLIT)) != 0;
2135
2136 if (!is_canceling && ELEM(t->mode, TFM_EDGE_SLIDE, TFM_VERT_SLIDE)) {
2137 /* NOTE(joeedh): Handle multi-res re-projection,
2138 * done on transform completion since it's really slow. */
2141 }
2142 }
2143
2144 if (use_automerge) {
2146 BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
2148 char hflag;
2149 bool has_face_sel = (bm->totfacesel != 0);
2150
2151 if (tc->use_mirror_axis_any) {
2152 /* Rather than adjusting the selection (which the user would notice)
2153 * tag all mirrored verts, then auto-merge those. */
2155
2156 TransDataMirror *td_mirror = tc->data_mirror;
2157 for (int i = tc->data_mirror_len; i--; td_mirror++) {
2159 }
2160
2161 hflag = BM_ELEM_SELECT | BM_ELEM_TAG;
2162 }
2163 else {
2164 hflag = BM_ELEM_SELECT;
2165 }
2166
2167 if (t->flag & T_AUTOSPLIT) {
2169 tc->obedit, true, true, true, hflag, t->scene->toolsettings->doublimit);
2170 }
2171 else {
2172 EDBM_automerge(tc->obedit, true, hflag, t->scene->toolsettings->doublimit, false);
2173 }
2174
2175 /* Special case, this is needed or faces won't re-select.
2176 * Flush selected edges to faces. */
2177 if (has_face_sel && (em->selectmode == SCE_SELECT_FACE)) {
2179 }
2180 }
2181 }
2182
2184 /* Table needs to be created for each edit command, since vertices can move etc. */
2186 /* TODO(@ideasman42): xform: We need support for many mirror objects at once! */
2187 break;
2188 }
2189}
2190
2192
2193/* -------------------------------------------------------------------- */
2196
2198 const TransDataContainer *tc, Vector<float3> &r_loc_dst_buffer)
2199{
2200 int td_selected_len = 0;
2201 tc->foreach_index_selected([&](const int /*i*/) { td_selected_len++; });
2202
2203 Array<TransDataVertSlideVert> sv_array(td_selected_len);
2204
2205 r_loc_dst_buffer.reserve(sv_array.size() * 4);
2206 int sv_array_index = 0;
2207 tc->foreach_index_selected([&](const int i) {
2208 TransData *td = &tc->data[i];
2209 const int size_prev = r_loc_dst_buffer.size();
2210
2211 BMVert *v = static_cast<BMVert *>(td->extra);
2212 if (v->e) {
2213 BMIter eiter;
2214 BMEdge *e;
2215 BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) {
2217 continue;
2218 }
2219 BMVert *v_other = BM_edge_other_vert(e, v);
2220 r_loc_dst_buffer.append(v_other->co);
2221 }
2222 }
2223 if (r_loc_dst_buffer.size() == size_prev) {
2224 /* NOTE(@ideasman42): it may be better not to add these at all
2225 * since sliding into itself is a no-op. Needs to be investigated. */
2226 r_loc_dst_buffer.append(td->iloc);
2227 }
2228
2229 TransDataVertSlideVert &sv = sv_array[sv_array_index];
2230 sv.td = &tc->data[i];
2231 /* The buffer address may change as the vector is resized. Avoid setting #Span. */
2232 // sv.targets = r_loc_dst_buffer.as_span().drop_front(size_prev);
2233
2234 /* Store the buffer size temporarily in `target_curr`. */
2235 sv.co_link_curr = r_loc_dst_buffer.size() - size_prev;
2236
2237 sv_array_index++;
2238 });
2239
2240 int start = 0;
2241 for (TransDataVertSlideVert &sv : sv_array) {
2242 int size = sv.co_link_curr;
2243 sv.co_link_orig_3d = r_loc_dst_buffer.as_span().slice(start, size);
2244 sv.co_link_curr = 0;
2245 start += size;
2246 }
2247
2248 return sv_array;
2249}
2250
2252
2253/* -------------------------------------------------------------------- */
2256
2258{
2260}
2261
2266static bool bm_loop_calc_opposite_co(const BMLoop *l_tmp, const float plane_no[3], float r_co[3])
2267{
2268 /* Skip adjacent edges. */
2269 BMLoop *l_first = l_tmp->next;
2270 BMLoop *l_last = l_tmp->prev;
2271 BMLoop *l_iter;
2272 float dist_sq_best = FLT_MAX;
2273 bool found = false;
2274
2275 l_iter = l_first;
2276 do {
2277 float tvec[3];
2278 if (isect_line_plane_v3(tvec, l_iter->v->co, l_iter->next->v->co, l_tmp->v->co, plane_no)) {
2279 const float fac = line_point_factor_v3(tvec, l_iter->v->co, l_iter->next->v->co);
2280 /* Allow some overlap to avoid missing the intersection because of float precision. */
2281 if ((fac > -FLT_EPSILON) && (fac < 1.0f + FLT_EPSILON)) {
2282 /* Likelihood of multiple intersections per ngon is quite low,
2283 * it would have to loop back on itself, but better support it
2284 * so check for the closest opposite edge. */
2285 const float dist_sq_test = len_squared_v3v3(l_tmp->v->co, tvec);
2286 if (dist_sq_test < dist_sq_best) {
2287 copy_v3_v3(r_co, tvec);
2288 dist_sq_best = dist_sq_test;
2289 found = true;
2290 }
2291 }
2292 }
2293 } while ((l_iter = l_iter->next) != l_last);
2294
2295 return found;
2296}
2297
2299{
2300 BMFace *f = l->f;
2301 BMLoop *l_next = l->next;
2302 if (f->len == 4) {
2303 /* We could use code below, but in this case
2304 * sliding diagonally across the quad works well. */
2305 return l_next->next->v->co;
2306 }
2307
2308 float3 plane_no;
2309 BM_loop_calc_face_direction(l, plane_no);
2310
2311 float3 isect_co;
2312 if (!bm_loop_calc_opposite_co(l, plane_no, isect_co)) {
2313 /* Rare case. */
2314 mid_v3_v3v3(isect_co, l->prev->v->co, l_next->v->co);
2315 }
2316 return isect_co;
2317}
2318
2320 int *r_group_len)
2321{
2323 int td_selected_len = 0;
2324
2325 /* Ensure valid selection. */
2326 BMIter iter;
2327 BMVert *v;
2328 bool found_invalid_edge_selection = false;
2329 tc->foreach_index_selected([&](const int i) {
2330 TransData *td = &tc->data[i];
2331 v = static_cast<BMVert *>(td->extra);
2333 if (numsel == 0 || numsel > 2) {
2334 /* Invalid edge selection. */
2335 found_invalid_edge_selection = true;
2336 return;
2337 }
2338 td_selected_len++;
2339 });
2340
2341 if (found_invalid_edge_selection) {
2342 return {};
2343 }
2344
2345 BMEdge *e;
2346 BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
2348 continue;
2349 }
2351 /* Can edges with at least once face user. */
2352 return {};
2353 }
2354 }
2355
2356 BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
2357 BM_elem_index_set(v, -1);
2358 }
2360
2361 /* Alloc and initialize the #TransDataEdgeSlideVert. */
2362
2363 Array<TransDataEdgeSlideVert> sv_array(td_selected_len);
2364 TransDataEdgeSlideVert *sv = sv_array.data();
2365 int sv_index = 0;
2366 tc->foreach_index_selected([&](const int i) {
2367 TransData *td = &tc->data[i];
2368
2369 sv->td = td;
2370 sv->loop_nr = -1;
2371 sv->dir_side[0] = float3(0);
2372 sv->dir_side[1] = float3(0);
2373
2374 /* Identify the #TransDataEdgeSlideVert by the vertex index. */
2375 v = static_cast<BMVert *>(td->extra);
2376 BM_elem_index_set(v, sv_index);
2377 sv_index++;
2378 sv++;
2379 });
2380
2381 /* Map indicating the indexes of #TransData connected by edge. */
2382 Array<int2> td_connected(tc->data_len, int2(-1, -1));
2383 BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
2385 continue;
2386 }
2387 int td_index_1 = BM_elem_index_get(e->v1);
2388 int td_index_2 = BM_elem_index_get(e->v2);
2389
2390 /* This can occur when the mesh has symmetry enabled but is not symmetrical. See #120811. */
2391 if (ELEM(-1, td_index_1, td_index_2)) {
2392 continue;
2393 }
2394
2395 int slot_1 = int(td_connected[td_index_1][0] != -1);
2396 int slot_2 = int(td_connected[td_index_2][0] != -1);
2397
2398 td_connected[td_index_1][slot_1] = td_index_2;
2399 td_connected[td_index_2][slot_2] = td_index_1;
2400 }
2401
2402 /* Compute the sliding groups. */
2403 int loop_nr = 0;
2404 for (int i : sv_array.index_range()) {
2405 TransDataEdgeSlideVert *sv = &sv_array[i];
2406 if (sv->loop_nr != -1) {
2407 /* This vertex has already been computed. */
2408 continue;
2409 }
2410
2411 /* Start from a vertex connected to just a single edge or any if it doesn't exist. */
2412 int i_curr = i;
2413 int i_prev = td_connected[i][1];
2414 while (!ELEM(i_prev, -1, i)) {
2415 int tmp = td_connected[i_prev][0] != i_curr ? td_connected[i_prev][0] :
2416 td_connected[i_prev][1];
2417 i_curr = i_prev;
2418 i_prev = tmp;
2419 }
2420
2430 struct SlideTempDataMesh {
2431 int i; /* The #TransDataEdgeSlideVert index. */
2433 BMVert *v;
2434 BMEdge *e;
2435 struct {
2436 BMFace *f;
2437 BMVert *v_dst;
2438 float3 dst;
2439 } fdata[2];
2440 bool vert_is_edge_pair;
2449 int find_best_dir(const SlideTempDataMesh *curr_side_other,
2450 const BMFace *f_curr,
2451 const BMLoop *l_src,
2452 const BMVert *v_dst,
2453 bool *r_do_isect_curr_dirs) const
2454 {
2455 *r_do_isect_curr_dirs = false;
2456
2457 if (f_curr == curr_side_other->fdata[0].f || v_dst == curr_side_other->fdata[0].v_dst) {
2458 return 0;
2459 }
2460
2461 if (f_curr == curr_side_other->fdata[1].f || v_dst == curr_side_other->fdata[1].v_dst) {
2462 return 1;
2463 }
2464
2465 if (curr_side_other->fdata[0].f || curr_side_other->fdata[1].f) {
2466 /* Find the best direction checking the edges that share faces between them. */
2467 int best_dir = -1;
2468 const BMLoop *l_edge = l_src->next->v == v_dst ? l_src : l_src->prev;
2469 const BMLoop *l_other = l_edge->radial_next;
2470 while (l_other->f != l_edge->f) {
2471 if (l_other->f == curr_side_other->fdata[0].f) {
2472 best_dir = 0;
2473 break;
2474 }
2475 if (l_other->f == curr_side_other->fdata[1].f) {
2476 best_dir = 1;
2477 break;
2478 }
2479 l_other = (l_other->v == this->v ? l_other->prev : l_other->next)->radial_next;
2480 }
2481
2482 if (best_dir != -1) {
2483 *r_do_isect_curr_dirs = true;
2484 return best_dir;
2485 }
2486 }
2487
2488 if (ELEM(nullptr, this->fdata[0].f, this->fdata[1].f)) {
2489 return int(this->fdata[0].f != nullptr);
2490 }
2491
2492 /* Find the best direction among those already computed.
2493 * Prioritizing in order:
2494 * - Boundary edge that points to the closest direction.
2495 * - Any edge that points to the closest direction. */
2496
2497 *r_do_isect_curr_dirs = true;
2498 BMEdge *e0 = this->fdata[0].v_dst ? BM_edge_exists(this->v, this->fdata[0].v_dst) :
2499 nullptr;
2500 BMEdge *e1 = this->fdata[1].v_dst ? BM_edge_exists(this->v, this->fdata[1].v_dst) :
2501 nullptr;
2502 const bool is_boundary_0 = e0 && BM_edge_is_boundary(e0);
2503 const bool is_boundary_1 = e1 && BM_edge_is_boundary(e1);
2504 if (is_boundary_0 && !is_boundary_1) {
2505 return 0;
2506 }
2507
2508 if (is_boundary_1 && !is_boundary_0) {
2509 return 1;
2510 }
2511
2512 /* Find the closest direction. */
2513 float3 src = this->v->co;
2514 float3 dst = v_dst->co;
2515 float3 dir_curr = dst - src;
2516 float3 dir0 = math::normalize(this->fdata[0].dst - src);
2517 float3 dir1 = math::normalize(this->fdata[1].dst - src);
2518 float dot0 = math::dot(dir_curr, dir0);
2519 float dot1 = math::dot(dir_curr, dir1);
2520 return int(dot0 < dot1);
2521 }
2522 } prev = {}, curr = {}, next = {}, next_next = {}, tmp = {};
2523
2524 next.i = td_connected[i_curr][0] != i_prev ? td_connected[i_curr][0] : td_connected[i_curr][1];
2525 if (next.i != -1) {
2526 next.sv = &sv_array[next.i];
2527 next.v = static_cast<BMVert *>(next.sv->td->extra);
2528 next.vert_is_edge_pair = mesh_vert_is_inner(next.v);
2529 }
2530
2531 curr.i = i_curr;
2532 if (curr.i != -1) {
2533 curr.sv = &sv_array[curr.i];
2534 curr.v = static_cast<BMVert *>(curr.sv->td->extra);
2535 curr.vert_is_edge_pair = mesh_vert_is_inner(curr.v);
2536 if (next.i != -1) {
2537 curr.e = BM_edge_exists(curr.v, next.v);
2538 }
2539 }
2540
2541 /* Do not compute `prev` for now. Let the loop calculate `curr` twice. */
2542 prev.i = -1;
2543
2544 while (curr.i != -1) {
2545 if (next.i != -1) {
2546 next_next.i = td_connected[next.i][0] != curr.i ? td_connected[next.i][0] :
2547 td_connected[next.i][1];
2548 if (next_next.i != -1) {
2549 next_next.sv = &sv_array[next_next.i];
2550 next_next.v = static_cast<BMVert *>(next_next.sv->td->extra);
2551 next_next.vert_is_edge_pair = mesh_vert_is_inner(next_next.v);
2552 next.e = BM_edge_exists(next.v, next_next.v);
2553 }
2554
2555 tmp = curr;
2556
2557 BMLoop *l;
2558 BM_ITER_ELEM (l, &iter, curr.e, BM_LOOPS_OF_EDGE) {
2559 BMFace *f_curr = l->f;
2560
2561 BMVert *v1_dst, *v2_dst;
2562 BMEdge *l_edge_next;
2563 BMLoop *l1, *l2;
2564 if (l->v == curr.v) {
2565 l1 = l;
2566 l2 = l->next;
2567 l_edge_next = l2->e;
2568 v1_dst = l1->prev->v;
2569 v2_dst = l2->next->v;
2570 }
2571 else {
2572 l1 = l->next;
2573 l2 = l;
2574 l_edge_next = l2->prev->e;
2575 v1_dst = l1->next->v;
2576 v2_dst = l2->prev->v;
2577 }
2578
2579 float3 dst = v1_dst->co;
2580
2581 /* Sometimes the sliding direction may fork (`isect_curr_dirs` is `true`).
2582 * In this case, the resulting direction is the intersection of the destinations. */
2583 bool isect_curr_dirs = false;
2584
2585 /* Identify the slot to slide according to the directions already computed in `curr`. */
2586 int best_dir = curr.find_best_dir(&tmp, f_curr, l1, v1_dst, &isect_curr_dirs);
2587
2588 if (curr.fdata[best_dir].f == nullptr) {
2589 curr.fdata[best_dir].f = f_curr;
2590 if (curr.vert_is_edge_pair) {
2591 curr.fdata[best_dir].dst = isect_face_dst(l1);
2592 }
2593 else {
2594 curr.fdata[best_dir].v_dst = v1_dst;
2595 curr.fdata[best_dir].dst = v1_dst->co;
2596 }
2597 }
2598
2599 /* Compute `next`. */
2600 next.fdata[best_dir].f = f_curr;
2601 if (l_edge_next == next.e || next.vert_is_edge_pair) {
2602 /* Case where the vertex slides over the face. */
2603 next.fdata[best_dir].v_dst = nullptr;
2604 next.fdata[best_dir].dst = isect_face_dst(l2);
2605 }
2606 else {
2607 /* Case where the vertex slides over an edge. */
2608 next.fdata[best_dir].v_dst = v2_dst;
2609 next.fdata[best_dir].dst = v2_dst->co;
2610 }
2611
2612 if (isect_curr_dirs) {
2613 /* The `best_dir` can only have one direction. */
2614 const float *curr_orig = curr.sv->v_co_orig();
2615 const float3 &dst0 = prev.fdata[best_dir].dst;
2616 const float3 &dst1 = curr.fdata[best_dir].dst;
2617 const float3 &dst2 = dst;
2618 const float3 &dst3 = next.fdata[best_dir].dst;
2619 float3 isect_pair[2];
2620
2686
2687 const float isect_eps = FLT_EPSILON;
2688 int isect_line_line = isect_line_line_epsilon_v3(
2689 dst0, dst1, dst2, dst3, isect_pair[0], isect_pair[1], isect_eps);
2690
2691 if (isect_line_line != 0) {
2692 /* Check if the intersections are outside the "valid conical region". */
2693 BLI_assert(isect_line_line <= 2);
2694 const float3 dir1 = math::normalize(dst1 - float3(curr_orig));
2695 const float3 dir2 = math::normalize(dst2 - float3(curr_orig));
2696 float len_n;
2697 const float3 n = math::normalize_and_get_length(math::cross(dir1, dir2), len_n);
2698 if (len_n < isect_eps) [[unlikely]] {
2699 isect_line_line = 0;
2700 }
2701 else {
2702 float len1, len2;
2703 const float3 plane_no_1 = math::normalize_and_get_length(math::cross(n, dir1),
2704 len1);
2705 const float3 plane_no_2 = math::normalize_and_get_length(math::cross(dir2, n),
2706 len2);
2707
2708 if ((len1 < isect_eps) || (len2 < isect_eps)) [[unlikely]] {
2709 isect_line_line = 0;
2710 }
2711 else {
2712 for (int isect_pass = 0; isect_pass < isect_line_line; isect_pass++) {
2713 const float3 isect_co = isect_pair[isect_pass] - float3(curr_orig);
2714 if ((math::dot(isect_co, plane_no_1) <= 0.0f) ||
2715 (math::dot(isect_co, plane_no_2) <= 0.0f))
2716 {
2717 /* Outside the plane, ignore. */
2718 isect_line_line = 0;
2719 break;
2720 }
2721 }
2722 }
2723 }
2724 }
2725
2726 if (isect_line_line != 0) {
2727 curr.fdata[best_dir].dst = math::midpoint(isect_pair[0], isect_pair[1]);
2728 }
2729 else {
2730 curr.fdata[best_dir].dst = math::midpoint(dst1, dst2);
2731 }
2732 }
2733 }
2734 }
2735
2736 /* The data in `curr` is computed. Use to compute the #TransDataEdgeSlideVert. */
2737 float3 iloc = curr.sv->td->iloc;
2738 if (curr.fdata[0].f) {
2739 curr.sv->dir_side[0] = curr.fdata[0].dst - iloc;
2740 }
2741 if (curr.fdata[1].f) {
2742 curr.sv->dir_side[1] = curr.fdata[1].dst - iloc;
2743 }
2744 curr.sv->edge_len = math::distance(curr.sv->dir_side[0], curr.sv->dir_side[1]);
2745 curr.sv->loop_nr = loop_nr;
2746
2747 if (i_prev != -1 && prev.i == i_prev) {
2748 /* Cycle returned to the beginning.
2749 * The data with index `i_curr` was computed twice to make sure the directions are correct
2750 * the second time. */
2751 break;
2752 }
2753
2754 /* Move forward. */
2755 prev = curr;
2756 curr = next;
2757 next = next_next;
2758 }
2759 loop_nr++;
2760 }
2761 *r_group_len = loop_nr;
2762 return sv_array;
2763}
2764
2766
2768 /*flags*/ (T_EDIT | T_POINTS),
2769 /*create_trans_data*/ createTransEditVerts,
2770 /*recalc_data*/ recalcData_mesh,
2771 /*special_aftertrans_update*/ special_aftertrans_update__mesh,
2772};
2773
2774} // namespace blender::ed::transform
#define PSEUDOINVERSE_EPSILON
#define mul_m3_series(...)
#define BLI_MEMARENA_STD_BUFSIZE
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define UNPACK3(a)
#define ELEM(...)
#define POINTER_OFFSET(v, ofs)
#define BM_FACE_FIRST_LOOP(p)
#define BM_elem_index_get(ele)
#define BM_elem_flag_disable(ele, hflag)
#define BM_elem_flag_set(ele, hflag, val)
#define BM_elem_index_set(ele, index)
#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_init(iter, bm, itype, data)
#define BM_ITER_ELEM_INDEX(ele, iter, data, itype, indexvar)
#define MEM_realloc_uninitialized(vmemh, len)
int64_t size() const
Definition BLI_array.hh:267
const T * data() const
Definition BLI_array.hh:323
IndexRange index_range() const
Definition BLI_array.hh:371
bool is_empty() const
Definition BLI_array.hh:275
int64_t size() const
void append(const T &value)
void reserve(const int64_t min_capacity)
Span< T > as_span() const
void resize(const int64_t new_size_in_bits, const bool value=false)
#define offsetof(t, d)
#define FLT_MAX
#define FLT_EPSILON
bool shape_key_report_if_locked(const Object *obedit, ReportList *reports)
Array< TransDataVertSlideVert > transform_mesh_vert_slide_data_create(const TransDataContainer *tc, Vector< float3 > &r_loc_dst_buffer)
void createSpaceNormalTangent_or_fallback(float mat[3][3], const float normal[3], const float tangent[3])
static void mesh_customdatacorrect_init_container_merge_group(TransDataContainer *tc, TransCustomDataLayer *tcld)
static void mesh_customdata_free_fn(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data)
TransConvertTypeInfo TransConvertType_Mesh
static void mesh_customdatacorrect_face_substitute_set(TransCustomDataLayer *tcld, BMFace *f, BMFace *f_copy)
static void mesh_customdatacorrect_free(TransCustomDataLayer *tcld)
static TransCustomDataLayer * mesh_customdatacorrect_create_impl(TransDataContainer *tc, const bool use_merge_group)
void transform_convert_mesh_crazyspace_detect(TransInfo *t, TransDataContainer *tc, TransMeshDataCrazySpace *r_crazyspace_data)
static void mesh_customdatacorrect_init_container_generic(TransDataContainer *, TransCustomDataLayer *tcld)
void transform_convert_mesh_mirrordata_calc(BMEditMesh *em, BMesh *bm, bool use_select, bool use_topology, const bool mirror_axis[3], TransMirrorData *r_mirror_data)
void transform_convert_mesh_mirrordata_free(TransMirrorData *mirror_data)
Array< TransDataEdgeSlideVert > transform_mesh_edge_slide_data_create(const TransDataContainer *tc, int *r_group_len)
void transform_convert_mesh_islanddata_free(TransIslandData *island_data)
static void mesh_transdata_center_copy(const TransIslandData *island_data, const int island_index, const float iloc[3], float r_center[3])
bool validSnappingNormal(const TransInfo *t)
static void mesh_customdatacorrect_create(TransDataContainer *tc, const bool use_merge_group)
void transform_convert_mesh_crazyspace_free(TransMeshDataCrazySpace *r_crazyspace_data)
bool usingSnappingNormal(const TransInfo *t)
static const float * mesh_vert_orig_co_get(TransCustomDataLayer *tcld, BMVert *v)
static bool bm_loop_calc_opposite_co(const BMLoop *l_tmp, const float plane_no[3], float r_co[3])
void transform_snap_project_individual_apply(TransInfo *t)
void transform_convert_mesh_islands_calc(BMEditMesh *em, BMesh *bm, bool calc_single_islands, bool calc_island_center, bool calc_island_axismtx, TransIslandData *r_island_data)
void transform_convert_mesh_customdatacorrect_init(TransInfo *t)
static void recalcData_mesh(TransInfo *t)
static bool bmesh_test_loose_edge(BMEdge *edge)
static bool bmesh_test_dist_add(BMVert *v0, BMVert *v1, BMVert *v2, float *dists, int *index, const float mtx[3][3])
void transform_convert_mesh_crazyspace_transdata_set(const float mtx[3][3], const float smtx[3][3], const float defmat[3][3], const float quat[4], TransData *r_td)
bool transform_snap_project_individual_is_active(const TransInfo *t)
bool createSpaceNormal(float mat[3][3], const float normal[3])
void transform_convert_clip_mirror_modifier_apply(TransDataContainer *tc)
static TransCustomDataMesh * mesh_customdata_ensure(TransDataContainer *tc)
static BMPartialUpdate * mesh_partial_ensure(TransInfo *t, TransDataContainer *tc, enum ePartialType partial_type)
static void createTransEditVerts(bContext *, TransInfo *t)
static void mesh_customdatacorrect_apply_vert(TransCustomDataLayer *tcld, TransDataBasic *td, TransCustomDataMergeGroup *merge_data, bool do_loop_mdisps)
static void special_aftertrans_update__mesh(bContext *, TransInfo *t)
static void mesh_customdata_free(TransCustomDataMesh *tcmd)
static void mesh_partial_types_calc(TransInfo *t, PartialTypeState *r_partial_state)
static void mesh_partial_update(TransInfo *t, TransDataContainer *tc, const PartialTypeState *partial_state)
static void mesh_customdatacorrect_apply(TransDataContainer *tc, bool is_final)
bool transform_snap_is_active(const TransInfo *t)
static bool is_in_quadrant_v3(const float co[3], const int quadrant[3], const float epsilon)
static void mesh_customdatacorrect_restore(TransInfo *t)
void transform_convert_mesh_connectivity_distance(BMesh *bm, const float mtx[3][3], float *dists, int *index)
static bool mesh_vert_is_inner(BMVert *v)
static BMFace * mesh_customdatacorrect_face_substitute_get(BMFace *f_copy)
static float3 isect_face_dst(const BMLoop *l)
static BMFace * mesh_customdatacorrect_find_best_face_substitute(BMFace *f)
static void mesh_customdatacorrect_init_vert(TransCustomDataLayer *tcld, TransDataBasic *td, const int index)
static void mesh_transdata_mirror_apply(TransDataContainer *tc)
static void VertsToTransData(TransInfo *t, TransData *td, TransDataExtension *tx, BMEditMesh *em, BMVert *eve, const TransIslandData *island_data, const int island_index)
T distance(const T &a, const T &b)
QuaternionBase< T > normalize_and_get_length(const QuaternionBase< T > &q, T &out_length)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T midpoint(const T &a, const T &b)
AxisSigned cross(const AxisSigned a, const AxisSigned b)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
void BM_face_calc_center_median(const BMFace *f, float r_cent[3])
void BM_loop_calc_face_direction(const BMLoop *l, float r_dir[3])
BM_loop_calc_face_direction.
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
BMFace * BM_face_copy(BMesh *bm_dst, const BMCustomDataCopyMap &cd_face_map, const BMCustomDataCopyMap &cd_loop_map, BMFace *f, const bool copy_verts, const bool copy_edges)
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
void mul_m3_v3(const float M[3][3], float r[3])
@ UVCALC_TRANSFORM_CORRECT_KEEP_CONNECTED
@ UVCALC_TRANSFORM_CORRECT_SLIDE
@ UVCALC_TRANSFORM_CORRECT
bool EDBM_automerge(Object *obedit, bool update, char hflag, float dist, bool use_centroid)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3])
int isect_line_line_epsilon_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float r_i1[3], float r_i2[3], float epsilon)
int BKE_crazyspace_get_first_deform_matrices_editbmesh(Depsgraph *depsgraph, Scene *, Object *, BMEditMesh *em, Array< float3x3, 0 > &deformmats, Array< float3, 0 > &deformcos)
void BM_vert_loop_groups_data_layer_merge(BMesh *bm, LinkNode *groups, const int layer_n)
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
void BKE_editmesh_looptris_calc(BMEditMesh *em, BMesh *bm)
Definition editmesh.cc:115
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
void BKE_editmesh_looptris_calc_with_partial_ex(BMEditMesh *em, BMesh *bm, BMPartialUpdate *bmpinfo, const BMeshCalcTessellation_Params *params)
Definition editmesh.cc:132
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
int BM_iter_elem_count_flag(const char itype, void *data, const char hflag, const bool value)
Elem Iter Flag Count.
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BM_editselection_center(BMEditSelection *ese, float r_center[3])
void copy_m3_m4(float m1[3][3], const float m2[4][4])
bool BKE_modifiers_is_correctable_deformed(const Scene *scene, Object *ob)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void BM_vert_loop_groups_data_layer_merge_weights(BMesh *bm, LinkNode *groups, const int layer_n, const float *loop_weights)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
BMCustomDataCopyMap CustomData_bmesh_copy_map_calc(const CustomData &src, const CustomData &dst, eCustomDataMask mask_exclude=0)
float angle_v3v3v3(const float a[3], const float b[3], const float c[3]) ATTR_WARN_UNUSED_RESULT
void BKE_crazyspace_set_quats_editmesh(BMesh *bm, Span< float3 > origcos, Span< float3 > mappedcos, float(*quats)[4], bool use_select)
void ED_mesh_mirror_spatial_table_end(Object *ob)
@ V3D_AROUND_LOCAL_ORIGINS
BMPartialUpdate * BM_mesh_partial_create_from_verts_group_multi(BMesh &bm, const BMPartialUpdate_Params &params, const Span< int > verts_group, const int verts_group_count)
void BM_mesh_elem_hflag_disable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
void project_plane_normalized_v3_v3v3(float out[3], const float p[3], const float v_plane[3])
ATTR_WARN_UNUSED_RESULT const BMVert * v
BLI_INLINE bool BM_edge_is_manifold(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BM_mesh_calc_edge_groups(BMesh *bm, int *r_groups_array, int(**r_group_index)[2], BMVertFilterFunc filter_fn, void *user_data, const char hflag_test)
bool BM_vert_is_boundary(const BMVert *v)
BLI_INLINE BMVert * BM_edge_other_vert(BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2872
void quat_to_mat3(float m[3][3], const float q[4])
MINLINE bool equals_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
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)
BMesh const char itype
VecBase< int32_t, 2 > int2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
bool BM_vert_calc_normal_ex(const BMVert *v, const char hflag, float r_no[3])
@ ME_EDIT_MIRROR_TOPO
float BM_vert_calc_shell_factor_ex(const BMVert *v, const float no[3], const char hflag)
void DEG_id_tag_update(ID *id, unsigned int flags)
BMesh const char void * data
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void BKE_editmesh_looptris_and_normals_calc(BMEditMesh *em, BMesh *bm)
Definition editmesh.cc:122
const BMAllocTemplate bm_mesh_allocsize_default
Definition bmesh_mesh.cc:26
BLI_INLINE bool BM_edge_is_boundary(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BKE_modifiers_get_cage_index(const Scene *scene, Object *ob, int *r_lastPossibleCageIndex, bool is_virtual)
void BM_editselection_plane(BMEditSelection *ese, float r_plane[3])
BMLoop * BM_loop_find_next_nodouble(BMLoop *l, BMLoop *l_stop, const float eps_sq)
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE int poly_to_tri_count(int poly_count, int corner_count)
MINLINE void zero_v3(float r[3])
BLI_INLINE BMVert * BM_vert_at_index(BMesh *bm, const int index)
bool isect_line_plane_v3(float r_isect_co[3], const float l1[3], const float l2[3], const float plane_co[3], const float plane_no[3]) ATTR_WARN_UNUSED_RESULT
bool EDBM_automerge_and_split(Object *obedit, bool split_edges, bool split_faces, bool update, char hflag, float dist)
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:59
bool invert_m3(float mat[3][3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
void * BLI_memarena_alloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
BMEdge * BM_edge_exists(BMVert *v_a, BMVert *v_b)
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
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_selectmode_flush_ex(BMesh *bm, short selectmode)
Main * CTX_data_main(const bContext *C)
void unit_m3(float m[3][3])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void BM_mesh_copy_init_customdata_all_layers(BMesh *bm_dst, BMesh *bm_src, const char htype, const BMAllocTemplate *allocsize)
int BM_mesh_calc_face_groups(BMesh *bm, int *r_groups_array, int(**r_group_index)[2], BMLoopFilterFunc filter_fn, BMLoopPairFilterFunc filter_pair_fn, void *user_data, const char hflag_test, const char htype_step)
@ BMO_OPTYPE_FLAG_UNTAN_MULTIRES
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
void bmesh_edit_begin(BMesh *, BMOpTypeFlag)
BMesh Begin Edit.
float geodesic_distance_propagate_across_triangle(const float v0[3], const float v1[3], const float v2[3], float dist1, float dist2)
bool BM_vert_is_edge_pair(const BMVert *v)
BMLoop * BM_loop_find_prev_nodouble(BMLoop *l, BMLoop *l_stop, const float eps_sq)
void pseudoinverse_m3_m3(float inverse[3][3], const float mat[3][3], float epsilon)
void BM_mesh_partial_destroy(BMPartialUpdate *bmpinfo)
Array< float3 > BKE_crazyspace_get_mapped_editverts(Depsgraph *depsgraph, Object *obedit)
Definition crazyspace.cc:93
int BM_iter_mesh_count_flag(const char itype, BMesh *bm, const char hflag, const bool value)
Mesh Iter Flag Count.
void BM_face_interp_multires_ex(BMesh *bm, BMFace *f_dst, const BMFace *f_src, const float f_dst_center[3], const float f_src_center[3], const int cd_loop_mdisp_offset)
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
bool CustomData_has_math(const CustomData *data)
VecBase< float, 3 > float3
BMPartialUpdate * BM_mesh_partial_create_from_verts(BMesh &bm, const BMPartialUpdate_Params &params, const BitSpan verts_mask, const int verts_mask_count)
void bmesh_edit_end(BMesh *bm, BMOpTypeFlag type_flag)
BMesh End Edit.
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
BMPartialUpdate * BM_mesh_partial_create_from_verts_group_single(BMesh &bm, const BMPartialUpdate_Params &params, const BitSpan verts_mask, const int verts_mask_count)
BMesh * BM_mesh_create(const BMAllocTemplate *allocsize, const BMeshCreateParams *params)
BMesh Make Mesh.
@ BM_ELEM_TAG_ALT
void BM_editselection_normal(BMEditSelection *ese, float r_normal[3])
float dist_signed_squared_to_corner_v3v3v3(const float p[3], const float v1[3], const float v2[3], const float v3[3], const float axis_ref[3])
Definition math_geom.cc:562
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
void BM_mesh_normals_update_with_partial_ex(BMesh *, const BMPartialUpdate *bmpinfo, const BMeshNormalsUpdate_Params *params)
bool CustomData_layer_has_math(const CustomData *data, int layer_n)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void BM_loop_interp_from_face(BMesh *bm, BMLoop *l_dst, const BMFace *f_src, const bool do_vertex, const bool do_multires)
void axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3])
Normal to x,y matrix.
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
LinkNode * BM_vert_loop_groups_data_layer_create(BMesh *bm, BMVert *v, const int layer_n, const float *loop_weights, MemArena *arena)
const btScalar eps
Definition poly34.cpp:11
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct BMLoop * l
Array< std::array< BMLoop *, 3 > > looptris
struct BMLoop * next
struct BMLoop * prev
struct BMEdge * e
struct BMVert * v
struct BMLoop * radial_next
struct BMFace * f
struct BMEdge * e
BMEdge ** etable
CustomData pdata
CustomData ldata
BMFace ** ftable
struct LinkNode * next
struct ToolSettings * toolsettings
eTool_UvCalcFlag uvcalc_flag
struct blender::ed::transform::TransCustomDataLayer::@214336046004207112234340360334155201264076243352 merge_group
TransCustomData_PartialUpdate partial_update[PARTIAL_TYPE_MAX]
void(*) free_cb(TransInfo *, TransDataContainer *tc, TransCustomData *custom_data)
Definition transform.hh:655
void foreach_index_selected(FunctionRef< void(int)> fn) const
Definition transform.hh:811
#define TD_MIRROR_EDGE_AXIS_SHIFT
Definition transform.hh:395
#define T_PROP_EDIT_ALL
Definition transform.hh:34
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:48
conversion and adaptation of different datablocks to a common struct.
#define FACE_SUBSTITUTE_INDEX
#define TRANSFORM_MAXDIST_MIRROR
#define PARTIAL_TYPE_MAX