12#include <fmt/format.h>
48#include "RNA_prototypes.hh"
65struct StitchPreviewer {
69 uint *uvs_per_polygon;
74 float *preview_stitchable;
75 float *preview_unstitchable;
78 uint num_unstitchable;
90struct IslandStitchData {
99 int num_rot_elements_neg;
101 char addedForPreview;
103 char stitchableCandidate;
105 bool use_edge_rotation;
107 bool all_boundaries_are_seams;
111struct UVVertAverage {
139struct StitchStateOrigBounds {
141 blender::Vector<bool> island_has_selected;
152 UvElementMap *element_map;
166 bool *island_is_stitchable;
168 StitchStateOrigBounds *orig_bounds;
171 int total_separate_edges;
172 int total_separate_uvs;
174 void **selection_stack;
178 uint *tris_per_island;
180 StitchPreviewer *stitch_preview;
184struct StitchStateContainer {
205 StitchState **states;
207 int active_object_index;
209 bool ignore_seam_boundary;
210 bool only_selected_uvs;
213struct PreviewPosition {
215 int polycount_position;
222 STITCH_STITCHABLE = 2,
223 STITCH_PROCESSED = 4,
225 STITCH_STITCHABLE_CANDIDATE = 16,
228#define STITCH_NO_PREVIEW -1
246struct StitchStateInit {
248 int *objs_selection_count;
250 UvElementID *selected_uvs;
257 MEM_SAFE_DELETE(state_init->objs_selection_count);
258 MEM_SAFE_DELETE(state_init->selected_uvs);
264 StitchPreviewer *stitch_preview;
267 stitch_preview->preview_polys =
nullptr;
268 stitch_preview->preview_stitchable =
nullptr;
269 stitch_preview->preview_unstitchable =
nullptr;
270 stitch_preview->uvs_per_polygon =
nullptr;
272 stitch_preview->preview_uvs = 0;
273 stitch_preview->num_polys = 0;
274 stitch_preview->num_stitchable = 0;
275 stitch_preview->num_unstitchable = 0;
277 stitch_preview->static_tris =
nullptr;
279 stitch_preview->num_static_tris = 0;
281 return stitch_preview;
287 if (stitch_preview) {
288 MEM_SAFE_DELETE(stitch_preview->preview_polys);
289 MEM_SAFE_DELETE(stitch_preview->uvs_per_polygon);
290 MEM_SAFE_DELETE(stitch_preview->preview_stitchable);
291 MEM_SAFE_DELETE(stitch_preview->preview_unstitchable);
292 MEM_SAFE_DELETE(stitch_preview->static_tris);
293 MEM_delete(stitch_preview);
301 status.
item(
IFACE_(
"Confirm"), ICON_MOUSE_LMB);
302 status.
item(
IFACE_(
"Cancel"), ICON_EVENT_ESC);
303 status.
item(fmt::format(
"{} {}",
305 (ssc->mode == STITCH_VERT ?
IFACE_(
"Vertices") :
IFACE_(
"Edges"))),
308 status.
item(fmt::format(
"{} : {}",
310 (ssc->mode == STITCH_VERT ?
IFACE_(
"Vertex") :
IFACE_(
"Edge"))),
312 status.
item(
IFACE_(
"Switch Island"), ICON_EVENT_I);
316 if (ssc->use_limit) {
317 status.
item(fmt::format(
"{} ({:.2f})",
IFACE_(
"Limit Distance"), ssc->limit_dist),
319 ICON_MOUSE_MMB_SCROLL);
324 const float medianPoint[2],
328 float uv_rotation_result[2];
344 StitchStateContainer *ssc)
352 limit = ssc->limit_dist;
354 if (ssc->use_limit) {
362 if (
fabsf(luv[0] - luv_iter[0]) < limit &&
fabsf(luv[1] - luv_iter[1]) < limit) {
373 StitchStateContainer *ssc,
378 if (edge_iter == edge) {
382 limit = ssc->limit_dist;
384 if (ssc->use_limit) {
391 if (
fabsf(luv_orig1[0] - luv_iter1[0]) < limit &&
fabsf(luv_orig1[1] - luv_iter1[1]) < limit &&
392 fabsf(luv_orig2[0] - luv_iter2[0]) < limit &&
fabsf(luv_orig2[1] - luv_iter2[1]) < limit)
404 StitchStateContainer *ssc)
406 if ((ssc->snap_islands &&
element->island == element_iter->
island) ||
407 (!ssc->midpoints &&
element->island == element_iter->
island))
418 StitchStateContainer *ssc,
421 if ((ssc->snap_islands && edge->element->island == edge_iter->element->island) ||
422 (!ssc->midpoints && edge->element->island == edge_iter->element->island))
433 PreviewPosition *preview_position,
434 StitchPreviewer *preview,
435 IslandStitchData *island_stitch_data,
440 for (
int i = 0; i <
state->element_map->total_islands; i++) {
441 if (island_stitch_data[i].addedForPreview) {
442 int numOfIslandUVs = 0, j;
443 int totelem = island_stitch_data[i].num_rot_elements_neg +
444 island_stitch_data[i].num_rot_elements;
446 float rotation_mat[2][2];
449 if (island_stitch_data[i].num_rot_elements > 1) {
450 island_stitch_data[i].rotation /= island_stitch_data[i].num_rot_elements;
453 if (island_stitch_data[i].num_rot_elements_neg > 1) {
454 island_stitch_data[i].rotation_neg /= island_stitch_data[i].num_rot_elements_neg;
457 if (island_stitch_data[i].numOfElements > 1) {
458 island_stitch_data[i].medianPoint[0] /= island_stitch_data[i].numOfElements;
459 island_stitch_data[i].medianPoint[1] /= island_stitch_data[i].numOfElements;
461 island_stitch_data[i].translation[0] /= island_stitch_data[i].numOfElements;
462 island_stitch_data[i].translation[1] /= island_stitch_data[i].numOfElements;
465 island_stitch_data[i].medianPoint[1] /=
state->aspect;
466 if ((island_stitch_data[i].rotation + island_stitch_data[i].rotation_neg <
float(
M_PI_2)) ||
467 island_stitch_data[i].num_rot_elements == 0 ||
468 island_stitch_data[i].num_rot_elements_neg == 0)
470 rotation = (island_stitch_data[i].rotation * island_stitch_data[i].num_rot_elements -
471 island_stitch_data[i].rotation_neg *
472 island_stitch_data[i].num_rot_elements_neg) /
476 rotation = (island_stitch_data[i].rotation * island_stitch_data[i].num_rot_elements +
477 (2.0f *
float(
M_PI) - island_stitch_data[i].rotation_neg) *
478 island_stitch_data[i].num_rot_elements_neg) /
483 numOfIslandUVs =
state->element_map->island_total_uvs[i];
485 for (j = 0; j < numOfIslandUVs; j++,
element++) {
487 if (!(
element->flag & STITCH_PROCESSED)) {
497 add_v2_v2(luv, island_stitch_data[i].translation);
502 int face_preview_pos =
506 island_stitch_data[i].medianPoint,
507 preview->preview_polys + face_preview_pos +
508 2 *
element->loop_of_face_index,
511 add_v2_v2(preview->preview_polys + face_preview_pos + 2 *
element->loop_of_face_index,
512 island_stitch_data[i].translation);
516 element->flag &= STITCH_SELECTED;
524 StitchStateContainer *ssc,
526 UVVertAverage *uv_average,
527 const uint *uvfinal_map,
528 IslandStitchData *island_stitch_data)
531 float uv1[2], uv2[2];
532 float edgecos, edgesin;
536 element1 =
state->uvs[edge->uv1];
537 element2 =
state->uvs[edge->uv2];
542 if (ssc->mode == STITCH_VERT) {
543 index1 = uvfinal_map[element1 -
state->element_map->storage];
544 index2 = uvfinal_map[element2 -
state->element_map->storage];
553 uv1[0] = luv2[0] - luv1[0];
554 uv1[1] = luv2[1] - luv1[1];
556 uv1[1] /=
state->aspect;
558 uv2[0] = uv_average[index2].uv[0] - uv_average[index1].uv[0];
559 uv2[1] = uv_average[index2].uv[1] - uv_average[index1].uv[1];
561 uv2[1] /=
state->aspect;
570 if (edgesin > 0.0f) {
571 island_stitch_data[element1->
island].num_rot_elements++;
572 island_stitch_data[element1->
island].rotation += rotation;
575 island_stitch_data[element1->
island].num_rot_elements_neg++;
576 island_stitch_data[element1->
island].rotation_neg += rotation;
582 StitchStateContainer *ssc,
584 IslandStitchData *island_stitch_data)
586 float rotation = 0, rotation_neg = 0;
587 int rot_elem = 0, rot_elem_neg = 0;
589 if (
element->island == ssc->static_island && !ssc->midpoints) {
594 for (; element_iter; element_iter = element_iter->
next) {
601 if (!ssc->midpoints && element_iter->
island != ssc->static_island) {
605 int index_tmp1 = element_iter -
state->element_map->storage;
606 index_tmp1 =
state->map[index_tmp1];
608 index_tmp2 =
state->map[index_tmp2];
611 float edgecos =
dot_v2v2(normal,
state->normals + index_tmp1 * 2);
613 if (edgesin > 0.0f) {
624 if (ssc->midpoints) {
626 rotation_neg /= 2.0f;
628 island_stitch_data[
element->island].num_rot_elements += rot_elem;
629 island_stitch_data[
element->island].rotation += rotation;
630 island_stitch_data[
element->island].num_rot_elements_neg += rot_elem_neg;
631 island_stitch_data[
element->island].rotation_neg += rotation_neg;
637 if (
state->island_is_stitchable) {
638 MEM_delete(
state->island_is_stitchable);
640 if (
state->orig_bounds) {
641 MEM_delete(
state->orig_bounds);
643 if (
state->element_map) {
647 MEM_delete(
state->uvs);
649 if (
state->selection_stack) {
650 MEM_delete(
state->selection_stack);
652 if (
state->tris_per_island) {
653 MEM_delete(
state->tris_per_island);
656 MEM_delete(
state->map);
658 if (
state->normals) {
659 MEM_delete(
state->normals);
662 MEM_delete(
state->edges);
665 state->stitch_preview =
nullptr;
666 if (
state->edge_hash) {
676 for (
uint ob_index = 0; ob_index < ssc->objects_len; ob_index++) {
679 MEM_delete(ssc->states);
680 MEM_delete(ssc->objects);
687 UvEdge *edges =
state->edges;
688 const int *map =
state->map;
690 for (
int i = 0; i <
state->total_separate_edges; i++) {
691 UvEdge *edge = edges + i;
698 if (edge->flag & STITCH_BOUNDARY) {
704 UvEdge *last_set = edge;
709 for (; iter1; iter1 = iter1->
next) {
721 int index1 = map[iter1 - element_map->
storage];
722 int index2 = map[iter2 - element_map->
storage];
724 UvEdge *edge2, *eiter;
728 if (index1 > index2) {
729 std::swap(index1, index2);
732 edgetmp.uv1 = index1;
733 edgetmp.uv2 = index2;
739 for (eiter = edge; eiter; eiter = eiter->next) {
740 if (edge2 == eiter) {
749 last_set->next = edge2;
769 const StitchState *
state,
770 const IslandStitchData *island_stitch_data,
774 if (ssc->ignore_seam_boundary) {
775 if (island_stitch_data[island_a].all_boundaries_are_seams ||
776 island_stitch_data[island_b].all_boundaries_are_seams)
781 if (ssc->only_selected_uvs) {
783 if (!
state->orig_bounds->island_has_selected[island_a] ||
784 !
state->orig_bounds->island_has_selected[island_b])
795 StitchStateContainer *ssc,
797 IslandStitchData *island_stitch_data)
800 for (; element_iter; element_iter = element_iter->
next) {
809 island_stitch_data[element_iter->
island].stitchableCandidate = 1;
810 island_stitch_data[
element->island].stitchableCandidate = 1;
811 element->flag |= STITCH_STITCHABLE_CANDIDATE;
819 StitchStateContainer *ssc,
821 IslandStitchData *island_stitch_data)
823 UvEdge *edge_iter = edge->first;
825 for (; edge_iter; edge_iter = edge_iter->next) {
827 ssc,
state, island_stitch_data, edge->element->island, edge_iter->element->island))
832 island_stitch_data[edge_iter->element->island].stitchableCandidate = 1;
833 island_stitch_data[edge->element->island].stitchableCandidate = 1;
834 edge->flag |= STITCH_STITCHABLE_CANDIDATE;
841 StitchPreviewer *preview,
842 PreviewPosition *preview_position)
847 preview_position[
index].data_position = preview->preview_uvs * 2;
848 preview_position[
index].polycount_position = preview->num_polys++;
849 preview->preview_uvs += efa->
len;
855 StitchStateContainer *ssc,
857 IslandStitchData *island_stitch_data,
858 PreviewPosition *preview_position)
860 StitchPreviewer *preview =
state->stitch_preview;
863 if (ssc->snap_islands && !ssc->midpoints && ssc->static_island ==
element->island) {
867 if (ssc->snap_islands) {
868 island_stitch_data[
element->island].addedForPreview = 1;
880 StitchStateContainer *ssc,
882 IslandStitchData *island_stitch_data,
883 PreviewPosition *preview_position)
885 StitchPreviewer *preview =
state->stitch_preview;
888 if (ssc->states[ssc->active_object_index] !=
state) {
889 preview->num_unstitchable++;
894 for (; element_iter; element_iter = element_iter->
next) {
900 if ((element_iter->
island == ssc->static_island) ||
901 (
element->island == ssc->static_island))
903 element->flag |= STITCH_STITCHABLE;
904 preview->num_stitchable++;
906 element, ssc,
state, island_stitch_data, preview_position);
914 if (!(
element->flag & STITCH_STITCHABLE)) {
915 preview->num_unstitchable++;
921 StitchStateContainer *ssc,
923 IslandStitchData *island_stitch_data,
924 PreviewPosition *preview_position)
926 StitchPreviewer *preview =
state->stitch_preview;
929 if (ssc->states[ssc->active_object_index] !=
state) {
930 preview->num_unstitchable++;
934 UvEdge *edge_iter = edge->first;
936 for (; edge_iter; edge_iter = edge_iter->next) {
937 if (edge_iter == edge) {
941 if ((edge_iter->element->island == ssc->static_island) ||
942 (edge->element->island == ssc->static_island))
944 edge->flag |= STITCH_STITCHABLE;
945 preview->num_stitchable++;
947 state->uvs[edge->uv1], ssc,
state, island_stitch_data, preview_position);
949 state->uvs[edge->uv2], ssc,
state, island_stitch_data, preview_position);
956 if (!(edge->flag & STITCH_STITCHABLE)) {
957 preview->num_unstitchable++;
964 PreviewPosition *preview_position,
965 UVVertAverage *final_position,
966 StitchStateContainer *ssc,
971 StitchPreviewer *preview =
state->stitch_preview;
975 if (
element->flag & STITCH_STITCHABLE) {
984 element_iter->
flag |= STITCH_PROCESSED;
992 int face_preview_pos =
995 copy_v2_v2(preview->preview_polys + face_preview_pos +
997 final_position[
index].uv);
1002 if ((!ssc->snap_islands) ||
1003 ((!ssc->midpoints) && (element_iter->
island == ssc->static_island)))
1005 element_iter->
flag &= STITCH_SELECTED;
1008 element_iter = element_iter->
next;
1009 }
while (element_iter && !element_iter->
separate);
1018 IslandStitchData *island_stitch_data)
1020 for (
int i = 0; i <
state->element_map->total_islands; i++) {
1021 island_stitch_data[i].all_boundaries_are_seams =
true;
1024 for (
int i = 0; i <
state->total_separate_edges; i++) {
1025 UvEdge *edge = &
state->edges[i];
1027 if (edge->flag & STITCH_BOUNDARY) {
1028 int island1 =
state->uvs[edge->uv1]->island;
1029 int island2 =
state->uvs[edge->uv2]->island;
1032 island_stitch_data[island1].all_boundaries_are_seams =
false;
1033 if (island1 != island2) {
1034 island_stitch_data[island2].all_boundaries_are_seams =
false;
1048 StitchPreviewer *preview;
1049 IslandStitchData *island_stitch_data =
nullptr;
1050 int previous_island = ssc->static_island;
1054 UVVertAverage *final_position =
nullptr;
1055 bool is_active_state = (
state == ssc->states[ssc->active_object_index]);
1059 char stitch_midpoints = ssc->midpoints;
1061 uint *uvfinal_map =
nullptr;
1063 PreviewPosition *preview_position =
nullptr;
1068 if (preview ==
nullptr) {
1073 "stitch_face_preview_position");
1080 "stitch_island_data");
1081 if (!island_stitch_data) {
1091 if (ssc->ignore_seam_boundary) {
1095 for (i = 0; i <
state->selection_size; i++) {
1096 if (ssc->mode == STITCH_VERT) {
1101 UvEdge *edge =
static_cast<UvEdge *
>(
state->selection_stack[i]);
1107 for (
int island_idx = 0; island_idx <
state->element_map->total_islands; island_idx++) {
1108 state->island_is_stitchable[island_idx] = island_stitch_data[island_idx].stitchableCandidate ?
1113 if (is_active_state) {
1115 ssc->static_island %=
state->element_map->total_islands;
1116 while (!(island_stitch_data[ssc->static_island].stitchableCandidate)) {
1117 ssc->static_island++;
1118 ssc->static_island %=
state->element_map->total_islands;
1121 if (ssc->static_island == previous_island) {
1127 for (i = 0; i <
state->selection_size; i++) {
1128 if (ssc->mode == STITCH_VERT) {
1130 if (
element->flag & STITCH_STITCHABLE_CANDIDATE) {
1131 element->flag &= ~STITCH_STITCHABLE_CANDIDATE;
1133 cd_loop_uv_offset,
element, ssc,
state, island_stitch_data, preview_position);
1137 preview->num_unstitchable++;
1141 UvEdge *edge =
static_cast<UvEdge *
>(
state->selection_stack[i]);
1142 if (edge->flag & STITCH_STITCHABLE_CANDIDATE) {
1143 edge->flag &= ~STITCH_STITCHABLE_CANDIDATE;
1145 cd_loop_uv_offset, edge, ssc,
state, island_stitch_data, preview_position);
1148 preview->num_unstitchable++;
1159 int stitchBufferIndex = 0, unstitchBufferIndex = 0;
1160 int preview_size = (ssc->mode == STITCH_VERT) ? 2 : 4;
1163 preview->num_stitchable * preview_size,
"stitch_preview_stitchable_data");
1165 preview->num_unstitchable * preview_size,
"stitch_preview_unstitchable_data");
1168 if (!preview->preview_stitchable || !preview->preview_unstitchable) {
1173 if (ssc->mode == STITCH_VERT) {
1174 for (i = 0; i <
state->total_separate_uvs; i++) {
1176 if (
element->flag & STITCH_STITCHABLE) {
1178 copy_v2_v2(&preview->preview_stitchable[stitchBufferIndex * 2], luv);
1179 stitchBufferIndex++;
1181 else if (
element->flag & STITCH_SELECTED) {
1183 copy_v2_v2(&preview->preview_unstitchable[unstitchBufferIndex * 2], luv);
1184 unstitchBufferIndex++;
1189 for (i = 0; i <
state->total_separate_edges; i++) {
1190 UvEdge *edge =
state->edges + i;
1194 if (edge->flag & STITCH_STITCHABLE) {
1196 copy_v2_v2(&preview->preview_stitchable[stitchBufferIndex * 4], luv);
1199 copy_v2_v2(&preview->preview_stitchable[stitchBufferIndex * 4 + 2], luv);
1201 stitchBufferIndex++;
1202 BLI_assert(stitchBufferIndex <= preview->num_stitchable);
1204 else if (edge->flag & STITCH_SELECTED) {
1206 copy_v2_v2(&preview->preview_unstitchable[unstitchBufferIndex * 4], luv);
1209 copy_v2_v2(&preview->preview_unstitchable[unstitchBufferIndex * 4 + 2], luv);
1211 unstitchBufferIndex++;
1212 BLI_assert(unstitchBufferIndex <= preview->num_unstitchable);
1218 if (ssc->states[ssc->active_object_index] !=
state) {
1220 MEM_delete(island_stitch_data);
1221 MEM_delete(preview_position);
1228 if (ssc->snap_islands) {
1229 for (i = 0; i <
state->element_map->total_islands; i++) {
1230 if (island_stitch_data[i].addedForPreview) {
1231 int numOfIslandUVs =
state->element_map->island_total_uvs[i];
1233 for (
int j = 0; j < numOfIslandUVs; j++,
element++) {
1248 uint buffer_index = 0;
1252 "tri_uv_stitch_prev");
1254 "tri_uv_stitch_prev");
1257 6 *
state->tris_per_island[ssc->static_island],
"static_island_preview_tris");
1259 preview->num_static_tris =
state->tris_per_island[ssc->static_island];
1261 if (!preview->preview_polys) {
1272 int numoftris = efa->
len - 2;
1274 int face_preview_pos = preview_position[
index].data_position;
1276 preview->uvs_per_polygon[preview_position[
index].polycount_position] = efa->
len;
1279 copy_v2_v2(preview->preview_polys + face_preview_pos + i * 2, luv);
1284 if (
element->island == ssc->static_island) {
1289 if (i < numoftris) {
1295 memcpy(preview->static_tris + buffer_index, fuv,
sizeof(
float[2]));
1296 memcpy(preview->static_tris + buffer_index + 2, luv,
sizeof(
float[2]));
1297 memcpy(preview->static_tris + buffer_index + 4, luvnext,
sizeof(
float[2]));
1313 if (ssc->mode == STITCH_VERT) {
1315 "stitch_uv_average");
1320 "stitch_uv_average");
1324 for (i = 0; i <
state->selection_size; i++) {
1325 if (ssc->mode == STITCH_VERT) {
1328 if (
element->flag & STITCH_STITCHABLE) {
1332 uvfinal_map[
element -
state->element_map->storage] = i;
1335 final_position[i].count = 1;
1337 if (ssc->snap_islands &&
element->island == ssc->static_island && !stitch_midpoints) {
1342 for (; element_iter; element_iter = element_iter->
next) {
1345 l = element_iter->
l;
1347 if (stitch_midpoints) {
1349 final_position[i].count++;
1351 else if (element_iter->
island == ssc->static_island) {
1361 if (stitch_midpoints) {
1362 final_position[i].uv[0] /= final_position[i].count;
1363 final_position[i].uv[1] /= final_position[i].count;
1367 UvEdge *edge =
static_cast<UvEdge *
>(
state->selection_stack[i]);
1369 if (edge->flag & STITCH_STITCHABLE) {
1374 l =
state->uvs[edge->uv1]->l;
1376 l =
state->uvs[edge->uv2]->l;
1379 copy_v2_v2(final_position[edge->uv1].uv, luv1);
1380 copy_v2_v2(final_position[edge->uv2].uv, luv2);
1381 final_position[edge->uv1].count = 1;
1382 final_position[edge->uv2].count = 1;
1384 state->uvs[edge->uv1]->flag |= STITCH_STITCHABLE;
1385 state->uvs[edge->uv2]->flag |= STITCH_STITCHABLE;
1387 if (ssc->snap_islands && edge->element->island == ssc->static_island && !stitch_midpoints)
1392 for (edge_iter = edge->first; edge_iter; edge_iter = edge_iter->next) {
1395 l =
state->uvs[edge_iter->uv1]->l;
1397 l =
state->uvs[edge_iter->uv2]->l;
1400 if (stitch_midpoints) {
1401 add_v2_v2(final_position[edge->uv1].uv, luv1);
1402 final_position[edge->uv1].count++;
1403 add_v2_v2(final_position[edge->uv2].uv, luv2);
1404 final_position[edge->uv2].count++;
1406 else if (edge_iter->element->island == ssc->static_island) {
1407 copy_v2_v2(final_position[edge->uv1].uv, luv1);
1408 copy_v2_v2(final_position[edge->uv2].uv, luv2);
1418 if (ssc->mode == STITCH_EDGE && stitch_midpoints) {
1419 for (i = 0; i <
state->total_separate_uvs; i++) {
1420 final_position[i].uv[0] /= final_position[i].count;
1421 final_position[i].uv[1] /= final_position[i].count;
1426 if (ssc->snap_islands) {
1427 if (ssc->mode == STITCH_VERT) {
1428 for (i = 0; i <
state->selection_size; i++) {
1431 if (
element->flag & STITCH_STITCHABLE) {
1441 island_stitch_data[
element->island].translation[0] += final_position[i].uv[0] - luv[0];
1442 island_stitch_data[
element->island].translation[1] += final_position[i].uv[1] - luv[1];
1443 island_stitch_data[
element->island].medianPoint[0] += luv[0];
1444 island_stitch_data[
element->island].medianPoint[1] += luv[1];
1445 island_stitch_data[
element->island].numOfElements++;
1450 for (i = 0; i <
state->total_separate_edges; i++) {
1451 UvEdge *edge =
state->edges + i;
1452 if ((edge->flag & STITCH_BOUNDARY) && (
state->uvs[edge->uv1]->flag & STITCH_STITCHABLE) &&
1453 (
state->uvs[edge->uv2]->flag & STITCH_STITCHABLE))
1461 island_stitch_data);
1462 island_stitch_data[
state->uvs[edge->uv1]->island].use_edge_rotation =
true;
1467 if (
final && ssc->clear_seams) {
1468 for (i = 0; i <
state->total_separate_edges; i++) {
1469 UvEdge *edge =
state->edges + i;
1470 if ((
state->uvs[edge->uv1]->flag & STITCH_STITCHABLE) &&
1471 (
state->uvs[edge->uv2]->flag & STITCH_STITCHABLE))
1478 for (i = 0; i <
state->selection_size; i++) {
1480 if (!island_stitch_data[
element->island].use_edge_rotation) {
1481 if (
element->flag & STITCH_STITCHABLE) {
1483 cd_loop_uv_offset,
element, ssc,
state, island_stitch_data);
1489 for (i = 0; i <
state->total_separate_uvs; i++) {
1492 if (
element->flag & STITCH_STITCHABLE) {
1502 island_stitch_data[
element->island].translation[0] += final_position[i].uv[0] - luv[0];
1503 island_stitch_data[
element->island].translation[1] += final_position[i].uv[1] - luv[1];
1504 island_stitch_data[
element->island].medianPoint[0] += luv[0];
1505 island_stitch_data[
element->island].medianPoint[1] += luv[1];
1506 island_stitch_data[
element->island].numOfElements++;
1510 for (i = 0; i <
state->selection_size; i++) {
1511 UvEdge *edge =
static_cast<UvEdge *
>(
state->selection_stack[i]);
1513 if (edge->flag & STITCH_STITCHABLE) {
1515 cd_loop_uv_offset, edge, ssc,
state, final_position,
nullptr, island_stitch_data);
1516 island_stitch_data[
state->uvs[edge->uv1]->island].use_edge_rotation =
true;
1521 if (
final && ssc->clear_seams) {
1522 for (i = 0; i <
state->selection_size; i++) {
1523 UvEdge *edge =
static_cast<UvEdge *
>(
state->selection_stack[i]);
1524 if (edge->flag & STITCH_STITCHABLE) {
1533 for (i = 0; i <
state->selection_size; i++) {
1534 if (ssc->mode == STITCH_VERT) {
1538 scene,
element, i, preview_position, final_position, ssc,
state,
final);
1541 UvEdge *edge =
static_cast<UvEdge *
>(
state->selection_stack[i]);
1544 state->uvs[edge->uv1],
1552 state->uvs[edge->uv2],
1560 edge->flag &= (STITCH_SELECTED | STITCH_BOUNDARY);
1565 if (ssc->snap_islands) {
1567 cd_loop_uv_offset,
state, preview_position, preview, island_stitch_data,
final);
1570 MEM_delete(final_position);
1571 if (ssc->mode == STITCH_VERT) {
1572 MEM_delete(uvfinal_map);
1574 MEM_delete(island_stitch_data);
1575 MEM_delete(preview_position);
1582 for (
uint ob_index = 0; ob_index < ssc->objects_len; ob_index++) {
1594 const UvEdge *edge =
static_cast<const UvEdge *
>(key);
1601 const UvEdge *edge1 =
static_cast<const UvEdge *
>(a);
1602 const UvEdge *edge2 =
static_cast<const UvEdge *
>(
b);
1606 if ((edge1->uv1 == edge2->uv1) && (edge1->uv2 == edge2->uv2)) {
1616 UvEdge **selection_stack =
reinterpret_cast<UvEdge **
>(
state->selection_stack);
1618 for (eiter = edge->first; eiter; eiter = eiter->next) {
1619 if (eiter->flag & STITCH_SELECTED) {
1621 if (always_select) {
1625 eiter->flag &= ~STITCH_SELECTED;
1626 for (i = 0; i <
state->selection_size; i++) {
1627 if (selection_stack[i] == eiter) {
1628 (
state->selection_size)--;
1629 selection_stack[i] = selection_stack[
state->selection_size];
1635 eiter->flag |= STITCH_SELECTED;
1636 selection_stack[
state->selection_size++] = eiter;
1647 for (; element_iter; element_iter = element_iter->
next) {
1650 if (element_iter->
flag & STITCH_SELECTED) {
1652 if (always_select) {
1656 element_iter->
flag &= ~STITCH_SELECTED;
1657 for (i = 0; i <
state->selection_size; i++) {
1658 if (selection_stack[i] == element_iter) {
1659 (
state->selection_size)--;
1660 selection_stack[i] = selection_stack[
state->selection_size];
1666 element_iter->
flag |= STITCH_SELECTED;
1667 selection_stack[
state->selection_size++] = element_iter;
1675 void **old_selection_stack =
state->selection_stack;
1676 int old_selection_size =
state->selection_size;
1677 state->selection_size = 0;
1679 if (from_stitch_mode == STITCH_VERT) {
1682 state->total_separate_edges,
"stitch_new_edge_selection_stack");
1685 for (i = 0; i <
state->total_separate_edges; i++) {
1686 UvEdge *edge =
state->edges + i;
1690 if ((element1->
flag & STITCH_SELECTED) && (element2->
flag & STITCH_SELECTED)) {
1696 for (i = 0; i < old_selection_size; i++) {
1699 element->flag &= ~STITCH_SELECTED;
1705 state->total_separate_uvs,
"stitch_new_vert_selection_stack");
1707 for (i = 0; i < old_selection_size; i++) {
1708 UvEdge *edge =
static_cast<UvEdge *
>(old_selection_stack[i]);
1715 edge->flag &= ~STITCH_SELECTED;
1718 MEM_delete(old_selection_stack);
1723 for (
uint ob_index = 0; ob_index < ssc->objects_len; ob_index++) {
1727 if (ssc->mode == STITCH_VERT) {
1728 ssc->mode = STITCH_EDGE;
1731 ssc->mode = STITCH_VERT;
1740 BMLoop *l1 = edge->element->l;
1748 tangent[1] /= aspect;
1750 normal[0] = tangent[1];
1751 normal[1] = -tangent[0];
1772 StitchStateContainer *ssc =
static_cast<StitchStateContainer *
>(arg);
1774 for (
uint ob_index = 0; ob_index < ssc->objects_len; ob_index++) {
1776 uint num_line = 0, num_tri, tri_idx = 0, line_idx = 0;
1777 StitchState *
state = ssc->states[ob_index];
1778 StitchPreviewer *stitch_preview =
state->stitch_preview;
1784 if (format.attr_len == 0) {
1791 if (stitch_preview->static_tris) {
1793 vbo = GPU_vertbuf_create_with_format(format);
1795 for (
int i = 0; i < stitch_preview->num_static_tris * 3; i++) {
1802 if (stitch_preview->preview_polys) {
1803 for (
int i = 0; i < stitch_preview->num_polys; i++) {
1804 num_line += stitch_preview->uvs_per_polygon[i];
1807 num_tri = num_line - 2 * stitch_preview->num_polys;
1810 vbo = GPU_vertbuf_create_with_format(format);
1811 vbo_line = GPU_vertbuf_create_with_format(format);
1816 for (
int i = 0; i < stitch_preview->num_polys; i++) {
1817 BLI_assert(stitch_preview->uvs_per_polygon[i] >= 3);
1822 vbo_line, pos_id, line_idx++, &stitch_preview->preview_polys[
index + 2]);
1824 for (j = 1; j < stitch_preview->uvs_per_polygon[i] - 1; j++) {
1827 vbo, pos_id, tri_idx++, &stitch_preview->preview_polys[
index + (j + 0) * 2]);
1829 vbo, pos_id, tri_idx++, &stitch_preview->preview_polys[
index + (j + 1) * 2]);
1832 vbo_line, pos_id, line_idx++, &stitch_preview->preview_polys[
index + (j + 0) * 2]);
1834 vbo_line, pos_id, line_idx++, &stitch_preview->preview_polys[
index + (j + 1) * 2]);
1841 vbo_line, pos_id, line_idx++, &stitch_preview->preview_polys[
index + j * 2]);
1843 index += stitch_preview->uvs_per_polygon[i] * 2;
1855 if (ssc->mode == STITCH_VERT) {
1859 vbo = GPU_vertbuf_create_with_format(format);
1861 for (
int i = 0; i < stitch_preview->num_stitchable; i++) {
1867 vbo = GPU_vertbuf_create_with_format(format);
1869 for (
int i = 0; i < stitch_preview->num_unstitchable; i++) {
1876 vbo = GPU_vertbuf_create_with_format(format);
1878 for (
int i = 0; i < stitch_preview->num_stitchable * 2; i++) {
1884 vbo = GPU_vertbuf_create_with_format(format);
1886 for (
int i = 0; i < stitch_preview->num_unstitchable * 2; i++) {
1901 if (!element1 || !element2) {
1905 int uv1 =
state->map[element1 -
state->element_map->storage];
1906 int uv2 =
state->map[element2 -
state->element_map->storage];
1921 StitchStateContainer *ssc,
1923 const StitchModes stored_mode,
1947 state->obedit = obedit;
1958 if (!
state->element_map) {
1967 if (ssc->only_selected_uvs) {
1968 state->orig_bounds = MEM_new<StitchStateOrigBounds>(
"stitch state orig bounds");
1969 state->orig_bounds->island_has_selected.resize(
state->element_map->total_islands,
false);
1977 state->orig_bounds->island_has_selected[
element->island] =
true;
1983 int unique_uvs =
state->element_map->total_unique_uvs;
1984 state->total_separate_uvs = unique_uvs;
1993 "uv_stitch_unique_map");
1999 if (!
state->uvs || !map || !edge_hash || !all_edges) {
2036 int offset1 = map[itmp1];
2037 int offset2 = map[itmp2];
2039 all_edges[counter].next =
nullptr;
2040 all_edges[counter].first =
nullptr;
2041 all_edges[counter].flag = 0;
2042 all_edges[counter].element =
element;
2045 if (offset1 < offset2) {
2046 all_edges[counter].uv1 = offset1;
2047 all_edges[counter].uv2 = offset2;
2050 all_edges[counter].uv1 = offset2;
2051 all_edges[counter].uv2 = offset1;
2054 edge =
static_cast<UvEdge *
>(
BLI_ghash_lookup(edge_hash, &all_edges[counter]));
2060 all_edges[counter].flag = STITCH_BOUNDARY;
2075 state->total_separate_edges = total_edges;
2084 MEM_delete(all_edges);
2090 for (i = 0; i < total_edges; i++) {
2102 for (i = 0; i < total_edges; i++) {
2103 UvEdge *edge = edges + i;
2105 if (edge->flag & STITCH_BOUNDARY) {
2118 state->selection_size = 0;
2123 int faceIndex, elementIndex;
2128 int selected_count = to_select.
size();
2130 if (stored_mode == STITCH_VERT) {
2132 "uv_stitch_selection_stack");
2134 while (selected_count--) {
2135 faceIndex = to_select[selected_count].faceIndex;
2136 elementIndex = to_select[selected_count].elementIndex;
2146 "uv_stitch_selection_stack");
2148 while (selected_count--) {
2149 UvEdge tmp_edge, *edge;
2151 faceIndex = to_select[selected_count].faceIndex;
2152 elementIndex = to_select[selected_count].elementIndex;
2181 if (ssc->mode != stored_mode) {
2186 if (ssc->mode == STITCH_VERT) {
2188 "uv_stitch_selection_stack");
2203 "uv_stitch_selection_stack");
2227 "stitch island tris");
2228 for (i = 0; i <
state->element_map->total_islands; i++) {
2229 state->tris_per_island[i] = 0;
2242 if (!
state->island_is_stitchable) {
2257 StitchState *active_state = ssc->states[ssc->active_object_index];
2258 StitchState *original_active_state = active_state;
2260 int original_island = ssc->static_island;
2263 ssc->static_island++;
2264 if (ssc->static_island >= active_state->element_map->total_islands) {
2266 ssc->active_object_index++;
2267 ssc->active_object_index %= ssc->objects_len;
2269 active_state = ssc->states[ssc->active_object_index];
2270 ssc->static_island = 0;
2273 if (active_state->island_is_stitchable[ssc->static_island]) {
2277 }
while (!(active_state == original_active_state && ssc->static_island == original_island));
2284 StitchStateInit state_init = {};
2289 "objects_selection_count");
2292 int total_selected = 0;
2293 for (
uint ob_index = 0; ob_index < objects.
size(); ob_index++) {
2294 total_selected += state_init.objs_selection_count[ob_index];
2301 state_init.selected_uvs[sel_idx].faceIndex =
RNA_int_get(&itemptr,
"face_index");
2302 state_init.selected_uvs[sel_idx].elementIndex =
RNA_int_get(&itemptr,
"element_index");
2324 "Stitching only works with less than %i objects selected (%i selected)",
2326 int(objects.
size()));
2330 StitchStateContainer *ssc = MEM_new<StitchStateContainer>(
"stitch collection");
2338 ssc->active_object_index =
RNA_int_get(op->
ptr,
"active_object_index");
2340 ssc->ignore_seam_boundary =
false;
2341 ssc->only_selected_uvs =
false;
2348 ssc->mode = STITCH_VERT;
2351 ssc->mode = STITCH_EDGE;
2356 ssc->mode = STITCH_VERT;
2359 ssc->mode = STITCH_EDGE;
2374 StitchStateContainer *ssc = MEM_new<StitchStateContainer>(
"stitch collection");
2375 ssc->use_limit =
false;
2376 ssc->snap_islands =
true;
2377 ssc->midpoints =
false;
2378 ssc->clear_seams =
false;
2379 ssc->mode = STITCH_VERT;
2380 ssc->only_selected_uvs =
true;
2381 ssc->ignore_seam_boundary =
true;
2388 StitchStateContainer *ssc,
2389 const StitchModes stored_mode,
2399 StitchStateInit state_init = {};
2408 ssc->objects_len = 0;
2411 int selection_offset = 0;
2412 for (
uint ob_index = 0; ob_index < objects.
size(); ob_index++) {
2413 Object *obedit = objects[ob_index];
2416 if (state_init.objs_selection_count) {
2417 const int selected_count = state_init.objs_selection_count[ob_index];
2418 to_select =
Span<UvElementID>(state_init.selected_uvs + selection_offset, selected_count);
2419 selection_offset += selected_count;
2421 StitchState *stitch_state_ob =
stitch_init(scene, ssc, obedit, stored_mode, to_select);
2423 if (stitch_state_ob) {
2424 ssc->objects[ssc->objects_len] = obedit;
2425 ssc->states[ssc->objects_len] = stitch_state_ob;
2433 if (ssc->objects_len == 0) {
2435 MEM_SAFE_DELETE(ssc->states);
2436 MEM_SAFE_DELETE(ssc->objects);
2440 ssc->active_object_index %= ssc->objects_len;
2442 StitchState *
state = ssc->states[ssc->active_object_index];
2443 ssc->static_island %=
state->element_map->total_islands;
2448 if (!
state->island_is_stitchable[ssc->static_island]) {
2450 state = ssc->states[ssc->active_object_index];
2472 if (!
stitch_init_all(scene, objects,
nullptr, ssc, STITCH_VERT,
nullptr)) {
2504 MEM_SAFE_DELETE(ssc);
2525 for (
uint ob_index = 0; ob_index < ssc->objects_len; ob_index++) {
2526 StitchState *
state = ssc->states[ob_index];
2545 StitchStateContainer *ssc =
static_cast<StitchStateContainer *
>(op->
customdata);
2555 RNA_int_set(op->
ptr,
"active_object_index", ssc->active_object_index);
2560 "objects_selection_count");
2566 for (
uint ob_index = 0; ob_index < ssc->objects_len; ob_index++) {
2567 StitchState *
state = ssc->states[ob_index];
2571 for (
int i = 0; i <
state->selection_size; i++) {
2574 if (ssc->mode == STITCH_VERT) {
2587 objs_selection_count[ob_index] =
state->selection_size;
2593 MEM_delete(objs_selection_count);
2605 for (
uint ob_index = 0; ob_index < ssc->objects_len; ob_index++) {
2606 StitchState *
state = ssc->states[ob_index];
2646 StitchStateContainer *ssc)
2655 if (ssc->mode == STITCH_VERT) {
2662 StitchState *
state =
nullptr;
2663 for (
uint ob_index = 0; ob_index < ssc->objects_len; ob_index++) {
2664 if (hit.
ob == ssc->objects[ob_index]) {
2665 state = ssc->states[ob_index];
2681 StitchState *
state =
nullptr;
2682 for (
uint ob_index = 0; ob_index < ssc->objects_len; ob_index++) {
2683 if (hit.
ob == ssc->objects[ob_index]) {
2684 state = ssc->states[ob_index];
2700 StitchStateContainer *ssc;
2703 ssc =
static_cast<StitchStateContainer *
>(op->
customdata);
2704 StitchState *active_state = ssc->states[ssc->active_object_index];
2706 switch (event->
type) {
2733 ssc->limit_dist += 0.01f;
2747 ssc->limit_dist -= 0.01f;
2748 ssc->limit_dist = std::max(0.01f, ssc->limit_dist);
2762 ssc->use_limit = !ssc->use_limit;
2776 StitchState *new_active_state = ssc->states[ssc->active_object_index];
2779 if (active_state != new_active_state) {
2797 ssc->midpoints = !ssc->midpoints;
2812 StitchState *selected_state =
stitch_select(
C, scene, event, ssc);
2825 ssc->snap_islands = !ssc->snap_islands;
2864 {STITCH_VERT,
"VERTEX", 0,
"Vertex",
""},
2865 {STITCH_EDGE,
"EDGE", 0,
"Edge",
""},
2866 {0,
nullptr, 0,
nullptr,
nullptr},
2870 ot->
name =
"Stitch";
2871 ot->
description =
"Stitch selected UV vertices by proximity";
2872 ot->
idname =
"UV_OT_stitch";
2884 ot->
srna,
"use_limit",
false,
"Use Limit",
"Stitch UVs within a specified limit distance");
2889 "Snap islands together (on edge stitch mode, rotates the islands too)");
2897 "Limit distance in normalized coordinates",
2906 "Island that stays in place when stitching islands",
2910 "active_object_index",
2915 "Index of the active object",
2922 "UVs are stitched at midpoint instead of at static island");
2923 RNA_def_boolean(ot->
srna,
"clear_seams",
true,
"Clear Seams",
"Clear seams of stitched edges");
2929 "Use vertex or edge stitching");
2934 "Stored Operation Mode",
2935 "Use vertex or edge stitching");
2943 "objects_selection_count",
2948 "Objects Selection Count",
CustomData interface, see also DNA_customdata_types.h.
#define GHASH_ITER(gh_iter_, ghash_)
Object is a sort of wrapper for general info.
#define REGION_DRAW_POST_VIEW
#define GPU_batch_uniform_4fv(batch, name, val)
Read Blender memory allocation and freeing.
#define RNA_BEGIN(sptr, itemptr, propname)
#define RNA_MAX_ARRAY_LENGTH
#define BM_FACE_FIRST_LOOP(p)
#define BM_ELEM_CD_GET_FLOAT_P(ele, offset)
#define BM_elem_index_get(ele)
#define BM_elem_flag_disable(ele, hflag)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BM_ITER_ELEM_INDEX(ele, iter, data, itype, indexvar)
constexpr int64_t size() const
constexpr bool is_empty() const
void item(std::string text, int icon1, int icon2=0)
void item_bool(std::string text, bool inverted, int icon1, int icon2=0)
void get_color_4fv(int colorid, float col[4])
float get_value_f(int colorid)
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
MINLINE float min_ff(float a, float b)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static void stitch_setup_face_preview_for_uv_group(UvElement *element, StitchStateContainer *ssc, StitchState *state, IslandStitchData *island_stitch_data, PreviewPosition *preview_position)
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)
void uvedit_live_unwrap_update(SpaceImage *sima, Scene *scene, Object *obedit)
unsigned int BLI_ghashutil_uinthash(unsigned int key)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
bool ED_operator_uvedit(bContext *C)
static void stitch_switch_selection_mode_all(StitchStateContainer *ssc)
ScrArea * CTX_wm_area(const bContext *C)
BLI_INLINE void * BLI_ghashIterator_getKey(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
static UvEdge * uv_edge_get(BMLoop *l, StitchState *state)
int RNA_enum_get(PointerRNA *ptr, const char *name)
gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
bool uvedit_edge_select_test(const Scene *scene, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool uv_stitch_selected_islands_for_original_bounds(const Scene *scene, Span< Object * > objects)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
float ED_uvedit_get_aspect_y(Object *obedit)
static bool stitch_island_pair_excluded(const StitchStateContainer *ssc, const StitchState *state, const IslandStitchData *island_stitch_data, const int island_a, const int island_b)
static void stitch_preview_delete(StitchPreviewer *stitch_preview)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
static int stitch_process_data_all(StitchStateContainer *ssc, const Scene *scene, int final)
MINLINE float cross_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
MINLINE void negate_v2_v2(float r[2], const float a[2])
MINLINE void copy_v2_v2(float r[2], const float a[2])
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
static void stitch_set_face_preview_buffer_position(BMFace *efa, StitchPreviewer *preview, PreviewPosition *preview_position)
void GPU_point_size(float size)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
int RNA_int_get(PointerRNA *ptr, const char *name)
static void stitch_island_calculate_edge_rotation(const int cd_loop_uv_offset, UvEdge *edge, StitchStateContainer *ssc, StitchState *state, UVVertAverage *uv_average, const uint *uvfinal_map, IslandStitchData *island_stitch_data)
static void stitch_validate_edge_stitchability(const int cd_loop_uv_offset, UvEdge *edge, StitchStateContainer *ssc, StitchState *state, IslandStitchData *island_stitch_data, PreviewPosition *preview_position)
static void stitch_determine_seam_bounded_islands(StitchState *state, IslandStitchData *island_stitch_data)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
void GPU_batch_discard(gpu::Batch *batch)
static void stitch_state_init_free(StitchStateInit *state_init)
MINLINE float normalize_v2(float n[2])
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
PropertyRNA * RNA_def_collection_runtime(StructOrFunctionRNA *cont, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
@ TH_STITCH_PREVIEW_ACTIVE
@ TH_STITCH_PREVIEW_STITCHABLE
@ TH_STITCH_PREVIEW_UNSTITCHABLE
UvElement * BM_uv_element_get_head(UvElementMap *element_map, UvElement *child)
static void stitch_uv_edge_generate_linked_edges(GHash *edge_hash, StitchState *state)
bool uv_find_nearest_edge_multi(Scene *scene, Span< Object * > objects, const float co[2], float penalty, UvNearestHit *hit)
static bool stitch_check_uvs_stitchable(const int cd_loop_uv_offset, UvElement *element, UvElement *element_iter, StitchStateContainer *ssc)
void ED_region_tag_redraw(ARegion *region)
void BM_uv_element_map_free(UvElementMap *element_map)
void uvedit_select_prepare(const Scene *scene, BMesh *bm)
static void stitch_propagate_uv_final_position(const Scene *scene, UvElement *element, int index, PreviewPosition *preview_position, UVVertAverage *final_position, StitchStateContainer *ssc, StitchState *state, const bool final)
static bool stitch_check_edges_state_stitchable(const int cd_loop_uv_offset, UvEdge *edge, UvEdge *edge_iter, StitchStateContainer *ssc, StitchState *state)
ViewLayer * CTX_data_view_layer(const bContext *C)
static int stitch_process_data(StitchStateContainer *ssc, StitchState *state, const Scene *scene, int final)
void BLI_ghash_insert(GHash *gh, void *key, void *val)
void * BM_iter_at_index(BMesh *bm, const char itype, void *data, int index)
bool uvedit_uv_select_test(const Scene *scene, const BMesh *bm, const BMLoop *l, const BMUVOffsets &offsets)
bool uv_find_nearest_vert_multi(Scene *scene, Span< Object * > objects, const float co[2], float penalty_dist, UvNearestHit *hit)
static void determine_uv_stitchability(const int cd_loop_uv_offset, UvElement *element, StitchStateContainer *ssc, StitchState *state, IslandStitchData *island_stitch_data)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
void uvedit_uv_select_enable(const Scene *scene, BMesh *bm, BMLoop *l)
static void stitch_set_selection_mode(StitchState *state, const char from_stitch_mode)
void RNA_collection_clear(PointerRNA *ptr, const char *name)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
MINLINE void add_v2_v2(float r[2], const float a[2])
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
static bool goto_next_island(StitchStateContainer *ssc)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
static bool stitch_check_edges_stitchable(const int cd_loop_uv_offset, UvEdge *edge, UvEdge *edge_iter, StitchStateContainer *ssc, StitchState *state)
static void stitch_draw_vbo(gpu::VertBuf *vbo, GPUPrimType prim_type, const float col[4])
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
void GPU_vertbuf_attr_set(gpu::VertBuf *, uint a_idx, uint v_idx, const void *data)
@ GPU_SHADER_3D_UNIFORM_COLOR
static wmOperatorStatus stitch_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void stitch_island_calculate_vert_rotation(const int cd_loop_uv_offset, UvElement *element, StitchStateContainer *ssc, StitchState *state, IslandStitchData *island_stitch_data)
static void stitch_calculate_island_snapping(const int cd_loop_uv_offset, StitchState *state, PreviewPosition *preview_position, StitchPreviewer *preview, IslandStitchData *island_stitch_data, int final)
UvNearestHit uv_nearest_hit_init_max(const View2D *v2d)
static int stitch_init_all(const Scene *scene, Span< Object * > objects, ARegion *region, StitchStateContainer *ssc, const StitchModes stored_mode, wmOperator *op)
void mul_v2_m2v2(float r[2], const float mat[2][2], const float vec[2])
void GPU_batch_draw(gpu::Batch *batch)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
static StitchPreviewer * stitch_preview_init()
static void determine_uv_edge_stitchability(const int cd_loop_uv_offset, UvEdge *edge, StitchStateContainer *ssc, StitchState *state, IslandStitchData *island_stitch_data)
static StitchStateContainer * stitch_init_from_operator(bContext *C, wmOperator *op)
static void stitch_uv_rotate(const float mat[2][2], const float medianPoint[2], float uv[2], float aspect)
static wmOperatorStatus stitch_invoke(bContext *C, wmOperator *op, const wmEvent *)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
unsigned int BLI_ghash_len(const GHash *gh) ATTR_WARN_UNUSED_RESULT
static wmOperatorStatus stitch_exec(bContext *C, wmOperator *op)
void angle_to_mat2(float R[2][2], float angle)
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void GPU_batch_program_set_builtin(gpu::Batch *batch, GPUBuiltinShader shader_id)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
SpaceImage * CTX_wm_space_image(const bContext *C)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
static void stitch_select_edge(UvEdge *edge, StitchState *state, int always_select)
static bool uv_edge_compare(const void *a, const void *b)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Main * CTX_data_main(const bContext *C)
static StitchState * stitch_init(const Scene *scene, StitchStateContainer *ssc, Object *obedit, const StitchModes stored_mode, const Span< UvElementID > to_select)
static StitchStateInit stitch_extract_rna_selection(wmOperator *op, const Span< Object * > objects)
static void stitch_validate_uv_stitchability(const int cd_loop_uv_offset, UvElement *element, StitchStateContainer *ssc, StitchState *state, IslandStitchData *island_stitch_data, PreviewPosition *preview_position)
static void state_delete_all(StitchStateContainer *ssc)
static bool stitch_check_uvs_state_stitchable(const int cd_loop_uv_offset, UvElement *element, UvElement *element_iter, StitchStateContainer *ssc)
MINLINE float max_ff(float a, float b)
UvElementMap * BM_uv_element_map_create(BMesh *bm, const Scene *scene, bool uv_selected, bool use_winding, bool use_seams, bool do_islands)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
static void stitch_exit(bContext *C, wmOperator *op, int finished)
PropertyRNA * RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
Scene * CTX_data_scene(const bContext *C)
MINLINE void sub_v2_v2(float r[2], const float a[2])
void GPU_blend(GPUBlend blend)
static void stitch_select_uv(UvElement *element, StitchState *state, int always_select)
BLI_INLINE BMFace * BM_face_at_index(BMesh *bm, const int index)
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
BMUVOffsets BM_uv_map_offsets_get(const BMesh *bm)
Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
ATTR_WARN_UNUSED_RESULT const void * element
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
static StitchStateContainer * stitch_settings_init_for_original_bounds()
static StitchStateContainer * stitch_settings_init_for_operator(const Span< Object * > objects, Scene *scene, wmOperator *op)
static void stitch_update_header(StitchStateContainer *ssc, bContext *C)
static uint uv_edge_hash(const void *key)
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
static void state_delete(StitchState *state)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_def_property_array(PropertyRNA *prop, int length)
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
float RNA_float_get(PointerRNA *ptr, const char *name)
static StitchState * stitch_select(bContext *C, Scene *scene, const wmEvent *event, StitchStateContainer *ssc)
View3D * CTX_wm_view3d(const bContext *C)
static void stitch_calculate_edge_normal(const int cd_loop_uv_offset, UvEdge *edge, float *normal, float aspect)
static void stitch_cancel(bContext *C, wmOperator *op)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void stitch_draw(const bContext *, ARegion *, void *arg)
void UV_OT_stitch(wmOperatorType *ot)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::ARegionRuntime * runtime
struct ToolSettings * toolsettings
unsigned short loop_of_face_index
struct ARegionType * type
wmEventModifierFlag modifier
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
void(*) cancel(bContext *C, wmOperator *op)
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
#define STITCH_NO_PREVIEW