40#define param_warning(message) \
45# define UNUSED_FUNCTION_NO_SLIM(x) x
47# define UNUSED_FUNCTION_NO_SLIM UNUSED_FUNCTION
140#define PEDGE_VERTEX_FLAGS (PEDGE_PIN)
195 1, 3, 5, 11, 17, 37, 67, 131, 257, 521,
196 1031, 2053, 4099, 8209, 16411, 32771, 65537, 131101, 262147, 524309,
197 1048583, 2097169, 4194319, 8388617, 16777259, 33554467, 67108879, 134217757, 268435459,
200#define PHASH_hash(ph, item) (uintptr_t(item) % uint((ph)->cursize))
201#define PHASH_edge(v1, v2) (((v1) < (v2)) ? ((v1) * 39) ^ ((v2) * 31) : ((v1) * 31) ^ ((v2) * 39))
225 MEM_SAFE_DELETE((*pph)->buckets);
241 if (lookup ==
nullptr) {
249 link->
next = lookup->next;
255 if (ph->
size > (size * 3)) {
262 *(ph->
list) =
nullptr;
264 for (link = first; link; link = next) {
277 if (link->
key == key) {
292 for (link = link->
next; link; link = link->
next) {
293 if (link->
key == key) {
315 const double max_angle =
DEG2RAD(179.0);
316 const double fix_amount = *r_fix - max_angle;
317 if (fix_amount < 0.0f) {
340 const double dist_v1 =
len_v3v3(v_fix, v1);
342 const double sum = dist_v1 + dist_v2;
343 const double weight = (sum > 1e-20f) ? dist_v2 / sum : 0.5f;
346 *r_fix -= fix_amount;
347 *r_a1 += fix_amount * weight;
348 *r_a2 += fix_amount * (1.0f - weight);
368 *r_a1 =
max_dd(*r_a1, 0.001f);
369 *r_a2 =
max_dd(*r_a2, 0.001f);
370 *r_a3 =
max_dd(*r_a3, 0.001f);
376 PVert *v1 = e1->
vert, *
v2 = e2->vert, *v3 = e3->vert;
381static float p_vec_cos(
const float v1[3],
const float v2[3],
const float v3[3])
401 PVert *v1 = e1->
vert, *
v2 = e2->vert, *v3 = e3->vert;
409 PVert *v1 = e1->
vert, *
v2 = e2->vert, *v3 = e3->vert;
416 return 0.5f * (((
v2[0] - v1[0]) * (v3[1] - v1[1])) - ((v3[0] - v1[0]) * (
v2[1] - v1[1])));
422 PVert *v1 = e1->
vert, *
v2 = e2->vert, *v3 = e3->vert;
424 return 0.5f * (((
v2->uv[0] - v1->
uv[0]) * (v3->uv[1] - v1->
uv[1])) -
425 ((v3->uv[0] - v1->
uv[0]) * (
v2->uv[1] - v1->
uv[1])));
440 return len_v2v2(
e->vert->uv,
e->next->vert->uv);
449 for (
v = chart->
verts;
v;
v =
v->nextlink) {
479 if (scale_x == 1.0f) {
484 for (
int i = 0; i < phandle->
ncharts; i++) {
500 float x =
v->uv[0] - chart->
origin[0];
501 float y =
v->uv[1] - chart->
origin[1];
502 float x_rot = cos_angle *
x - sin_angle *
y;
503 float y_rot = sin_angle *
x + cos_angle *
y;
504 v->uv[0] = x_rot + chart->
origin[0];
505 v->uv[1] = y_rot + chart->
origin[1];
512 v->uv[0] += trans[0];
513 v->uv[1] += trans[1];
529 for (
v = chart->
verts;
v;
v =
v->nextlink) {
542 div = dir2[0] * dir1[1] - dir2[1] * dir1[0];
548 lmbda = ((v1[1] -
v2[1]) * dir1[0] - (v1[0] -
v2[0]) * dir1[1]) / div;
549 r_isect[0] = v1[0] + lmbda * dir2[0];
550 r_isect[1] = v1[1] + lmbda * dir2[1];
559 return e->next->next->pair;
564 return e->next->next->pair;
569 return (
e->pair) ?
e->pair->next :
nullptr;
574 return e->next->vert->edge;
584 }
while (we && (we !=
e));
586 return last->next->next;
591 return v->edge->pair;
597 PVert *v1 = e1->
vert, *
v2 = e2->vert, *v3 = e3->vert;
598 int f1 = e1->
flag, f2 = e2->flag, f3 = e3->flag;
599 float *orig_uv1 = e1->
orig_uv, *orig_uv2 = e2->orig_uv, *orig_uv3 = e3->orig_uv;
613 e3->orig_uv = orig_uv1;
618static void p_chart_topological_sanity_check(PChart *chart)
623 for (
v = chart->verts;
v;
v =
v->nextlink) {
624 GEO_uv_parametrizer_test_equals_ptr(
"v->edge->vert",
v,
v->edge->vert);
627 for (
e = chart->edges;
e;
e =
e->nextlink) {
629 GEO_uv_parametrizer_test_equals_ptr(
"e->pair->pair",
e,
e->pair->pair);
630 GEO_uv_parametrizer_test_equals_ptr(
"pair->vert",
e->vert,
e->pair->next->vert);
631 GEO_uv_parametrizer_test_equals_ptr(
"pair->next->vert",
e->next->vert,
e->pair->vert);
642 int nedges = 0, npins = 0;
645 v->uv[0] =
v->uv[1] = 0.0f;
646 pinuv[0] = pinuv[1] = 0.0f;
655 pinuv[0] +=
e->orig_uv[0] * handle->
aspect_y;
656 pinuv[1] +=
e->orig_uv[1];
661 v->uv[1] +=
e->orig_uv[1];
668 }
while (
e &&
e != (
v->edge));
671 v->uv[0] = pinuv[0] / npins;
672 v->uv[1] = pinuv[1] / npins;
675 else if (nedges > 0) {
685 const float blend = handle->
blend;
686 const float invblend = 1.0f - blend;
687 const float invblend_x = invblend / handle->
aspect_y;
690 e->orig_uv[0] = blend *
e->old_uv[0] + invblend_x *
e->vert->uv[0];
691 e->orig_uv[1] = blend *
e->old_uv[1] + invblend *
e->vert->uv[1];
700 e->orig_uv[0] = blend *
e->old_uv[0] + invblend_x *
e->vert->uv[0];
701 e->orig_uv[1] = blend *
e->old_uv[1] + invblend *
e->vert->uv[1];
716 e2->old_uv[0] = e2->orig_uv[0];
717 e2->old_uv[1] = e2->orig_uv[1];
720 e3->old_uv[0] = e3->orig_uv[0];
721 e3->old_uv[1] = e3->orig_uv[1];
734 e2->orig_uv[0] = e2->old_uv[0];
735 e2->orig_uv[1] = e2->old_uv[1];
738 e3->orig_uv[0] = e3->old_uv[0];
739 e3->orig_uv[1] = e3->old_uv[1];
755 for (
int i = 0; i < 3; i++) {
756 if (!isfinite(
v->
co[i])) [[unlikely]] {
766 v->on_boundary_flag =
false;
790 nv->
uv[0] =
v->uv[0];
791 nv->
uv[1] =
v->uv[1];
792 nv->
u.
key =
v->u.key;
809 if ((
e->vert->u.key == vkeys[0]) && (
e->next->vert->u.key == vkeys[1])) {
812 if ((
e->vert->u.key == vkeys[1]) && (
e->next->vert->u.key == vkeys[0])) {
816 e =
reinterpret_cast<PEdge *
>(
830 if ((
e->vert->u.key == vkeys[i1]) && (
e->next->vert->u.key == vkeys[i2])) {
831 if (
e->next->next->vert->u.key == vkeys[i3]) {
835 else if ((
e->vert->u.key == vkeys[i2]) && (
e->next->vert->u.key == vkeys[i1])) {
836 if (
e->next->next->vert->u.key == vkeys[i3]) {
841 e =
reinterpret_cast<PEdge *
>(
850 const float *uv1, *uv2, *uvp1, *uvp2;
857 uv2 =
e->next->orig_uv;
868 if ((
fabsf(uv1[0] - uvp1[0]) > limit[0]) || (
fabsf(uv1[1] - uvp1[1]) > limit[1])) {
873 if ((
fabsf(uv2[0] - uvp2[0]) > limit[0]) || (
fabsf(uv2[1] - uvp2[1]) > limit[1])) {
903 if (((v1->
u.
key == key1) && (
v2->u.key == key2)) ||
904 ((v1->
u.
key == key2) && (
v2->u.key == key1)))
919 pe =
reinterpret_cast<PEdge *
>(
923 if (*r_pair && (
e->vert == (*r_pair)->vert)) {
924 if ((*r_pair)->next->pair || (*r_pair)->next->next->pair) {
931 return (*r_pair !=
nullptr);
936 bool topology_from_uvs,
939 PEdge *pair =
nullptr;
942 if (
e->vert == pair->
vert) {
955 return (
e->pair !=
nullptr);
962 PEdge **stack = stackbase;
974 *stack = first->
edge;
977 while (stack != stackbase) {
1003 MEM_delete(stackbase);
1010 PEdge *we, *lastwe =
nullptr;
1036 if (we ==
v->edge) {
1039 v->nextlink = chart->
verts;
1051 v->nextlink = chart->
verts;
1061 }
while (we && (we != lastwe));
1069 for (
int i = 0; i < ncharts; i++) {
1130 const float *weight,
1140 float weight1, weight2, weight3;
1142 weight1 = weight[i1];
1143 weight2 = weight[i2];
1144 weight3 = weight[i3];
1153 e2->vert =
p_vert_lookup(handle, vkeys[i2], co[i2], weight2, e2);
1154 e3->vert =
p_vert_lookup(handle, vkeys[i3], co[i3], weight3, e3);
1157 e2->orig_uv =
uv[i2];
1158 e3->orig_uv =
uv[i3];
1188 e2->u.key =
PHASH_edge(vkeys[i2], vkeys[i3]);
1189 e3->u.key =
PHASH_edge(vkeys[i3], vkeys[i1]);
1207 e1->
orig_uv = e2->orig_uv = e3->orig_uv =
nullptr;
1229 float len, maxlen = -1.0;
1236 for (
e = chart->
edges;
e;
e =
e->nextlink) {
1252 if (r_outer && (
len > maxlen)) {
1258 for (
e = chart->
edges;
e;
e =
e->nextlink) {
1274 uint nfilltri = nverts - 2;
1275 *r_tris =
static_cast<uint(*)[3]
>(
1277 float (*projverts)[2] =
static_cast<float (*)[2]
>(
1283 const float *co_curr, *co_prev = co[nverts - 1];
1284 for (
int j = 0; j < nverts; j++) {
1294 float axis_mat[3][3];
1296 for (
int j = 0; j < nverts; j++) {
1312 int nedges = border_edges.
size();
1313 uint nfilltri = nedges - 2;
1318 while (nedges >= 3) {
1320 for (
uint tris_idx = 0; tris_idx < nfilltri; tris_idx++) {
1321 if (filled_indices[tris_idx] ==
true) {
1325 uint i1 = tris[tris_idx][0];
1326 uint i2 = tris[tris_idx][1];
1327 uint i3 = tris[tris_idx][2];
1329 for (
int i = 0; i < 3; i++) {
1330 PEdge *inner_edge = border_edges[i2];
1335 if ((prev_bound_edge->
vert->
u.
id != i1) || (next_bound_edge->
vert->
u.
id != i3)) {
1344 handle, chart, inner_edge->
vert, prev_bound_edge->
vert, next_bound_edge->
vert);
1353 inner_edge->
pair = new_inner_edge;
1354 new_inner_edge->
pair = inner_edge;
1355 prev_bound_edge->
pair = new_next_edge;
1356 new_next_edge->
pair = prev_bound_edge;
1358 new_inner_edge->
vert = next_bound_edge->
vert;
1359 new_next_edge->
vert = inner_edge->
vert;
1360 new_prev_edge->
vert = prev_bound_edge->
vert;
1363 next_bound_edge->
pair = new_prev_edge;
1364 new_prev_edge->
pair = next_bound_edge;
1367 filled_indices[tris_idx] =
true;
1368 new_prev_edge->
vert->
edge = new_prev_edge;
1370 border_edges[new_prev_edge->
vert->
u.
id] = new_prev_edge;
1371 border_edges[next_bound_edge->
vert->
u.
id] = next_bound_edge;
1385 for (
e = chart->
edges;
e;
e =
e->nextlink) {
1406 be =
e->next->vert->edge;
1414 for (
int i = 0; i < nedges; i++) {
1415 PVert *bv = border_edges[i]->vert;
1417 stored_indexes[i] = bv->
u.
key;
1423 for (
int i = 0; i < nedges; i++) {
1424 border_edges[i]->vert->u.key = stored_indexes[i];
1433static int p_polygon_point_in(
const float cp1[2],
const float cp2[2],
const float p[2])
1435 if ((cp1[0] == p[0]) && (cp1[1] == p[1])) {
1438 else if ((cp2[0] == p[0]) && (cp2[1] == p[1])) {
1446static void p_polygon_kernel_clip(
float (*oldpoints)[2],
1448 float (*newpoints)[2],
1453 float *p2, *p1, isect[2];
1456 p1 = oldpoints[noldpoints - 1];
1457 p1in = p_polygon_point_in(cp1, cp2, p1);
1460 for (i = 0; i < noldpoints; i++) {
1462 p2in = p_polygon_point_in(cp1, cp2, p2);
1464 if ((p2in >= 2) || (p1in && p2in)) {
1465 newpoints[*r_nnewpoints][0] = p2[0];
1466 newpoints[*r_nnewpoints][1] = p2[1];
1469 else if (p1in && !p2in) {
1471 p_intersect_line_2d(p1, p2, cp1, cp2, isect);
1472 newpoints[*r_nnewpoints][0] = isect[0];
1473 newpoints[*r_nnewpoints][1] = isect[1];
1477 else if (!p1in && p2in) {
1478 p_intersect_line_2d(p1, p2, cp1, cp2, isect);
1479 newpoints[*r_nnewpoints][0] = isect[0];
1480 newpoints[*r_nnewpoints][1] = isect[1];
1483 newpoints[*r_nnewpoints][0] = p2[0];
1484 newpoints[*r_nnewpoints][1] = p2[1];
1493static void p_polygon_kernel_center(
float (*points)[2],
int npoints,
float *center)
1495 int i,
size, nnewpoints = npoints;
1496 float(*oldpoints)[2], (*newpoints)[2], *p1, *p2;
1502 memcpy(oldpoints, points,
sizeof(
float[2]) * npoints);
1504 for (i = 0; i < npoints; i++) {
1506 p2 = points[(i + 1) % npoints];
1507 p_polygon_kernel_clip(oldpoints, nnewpoints, newpoints, &nnewpoints, p1, p2);
1509 if (nnewpoints == 0) {
1511 memcpy(oldpoints, points,
sizeof(
float[2]) * npoints);
1512 nnewpoints = npoints;
1515 else if (nnewpoints == 1) {
1517 center[0] = newpoints[0][0];
1518 center[1] = newpoints[0][1];
1520 MEM_delete(oldpoints);
1521 MEM_delete(newpoints);
1526 if (nnewpoints * 2 > size) {
1528 MEM_delete(oldpoints);
1530 memcpy(oldpoints, newpoints,
sizeof(
float[2]) * nnewpoints);
1531 MEM_delete(newpoints);
1535 float(*sw_points)[2] = oldpoints;
1536 oldpoints = newpoints;
1537 newpoints = sw_points;
1541 center[0] = center[1] = 0.0f;
1543 for (i = 0; i < nnewpoints; i++) {
1544 center[0] += oldpoints[i][0];
1545 center[1] += oldpoints[i][1];
1548 center[0] /= nnewpoints;
1549 center[1] /= nnewpoints;
1551 MEM_delete(oldpoints);
1552 MEM_delete(newpoints);
1564static float p_vert_cotan(
const float v1[3],
const float v2[3],
const float v3[3])
1566 float a[3],
b[3], c[3], clen;
1581static bool p_vert_flipped_wheel_triangle(
PVert *
v)
1591 }
while (
e && (
e !=
v->edge));
1596static bool p_vert_map_harmonic_weights(
PVert *
v)
1598 float weightsum, positionsum[2], olduv[2];
1601 positionsum[0] = positionsum[1] = 0.0f;
1607 float t1, t2, weight;
1611 v2 =
e->next->next->vert;
1612 t1 = p_vert_cotan(
v2->
co,
e->vert->
co, v1->co);
1614 v1 =
e->pair->next->vert;
1615 v2 =
e->pair->next->next->vert;
1616 t2 = p_vert_cotan(
v2->
co,
e->pair->vert->
co, v1->co);
1618 weight = 0.5f * (t1 + t2);
1619 weightsum += weight;
1620 positionsum[0] += weight *
e->pair->vert->uv[0];
1621 positionsum[1] += weight *
e->pair->vert->uv[1];
1624 }
while (
e && (
e !=
v->edge));
1634 v1 =
e->next->next->vert;
1636 t1 = p_vert_cotan(v1->co,
v->
co,
v2->
co);
1637 t2 = p_vert_cotan(
v2->
co,
v->
co, v1->co);
1639 weightsum += t1 + t2;
1640 positionsum[0] += (
v2->uv[1] - v1->uv[1]) + (t1 *
v2->uv[0] + t2 * v1->uv[0]);
1641 positionsum[1] += (v1->uv[0] -
v2->uv[0]) + (t1 *
v2->uv[1] + t2 * v1->uv[1]);
1644 }
while (
e && (
e !=
v->edge));
1647 if (weightsum != 0.0f) {
1648 weightsum = 1.0f / weightsum;
1649 positionsum[0] *= weightsum;
1650 positionsum[1] *= weightsum;
1653 olduv[0] =
v->uv[0];
1654 olduv[1] =
v->uv[1];
1655 v->uv[0] = positionsum[0];
1656 v->uv[1] = positionsum[1];
1658 if (p_vert_flipped_wheel_triangle(
v)) {
1659 v->uv[0] = olduv[0];
1660 v->uv[1] = olduv[1];
1668static void p_vert_harmonic_insert(
PVert *
v)
1672 if (!p_vert_map_harmonic_weights(
v)) {
1684 }
while (
e && (
e !=
v->edge));
1697 points[i][0] =
e->next->vert->uv[0];
1698 points[i][1] =
e->next->vert->uv[1];
1700 if (nexte ==
nullptr) {
1702 points[i][0] =
e->next->next->vert->uv[0];
1703 points[i][1] =
e->next->next->vert->uv[1];
1709 }
while (
e !=
v->edge);
1711 p_polygon_kernel_center(points, npoints,
v->uv);
1719 p_vert_map_harmonic_weights(
e->next->vert);
1722 }
while (
e && (
e !=
v->edge));
1724 p_vert_map_harmonic_weights(
v);
1733 while (
v->edge->pair) {
1736 if (
v->edge == start) {
1746 *r_newv = edge->
vert;
1751 *r_keepv = pair->
vert;
1757 PVert *oldv, *keepv;
1765 if ((
e != edge) && !(pair && pair->
next ==
e)) {
1770 }
while (
e && (
e != oldv->
edge));
1773 if ((edge && (keepv->
edge == edge->
next)) || (keepv->
edge == pair)) {
1797 e2->pair->pair = e1->
pair;
1815 e2->pair->pair = e1->
pair;
1852static void p_split_vertex(PEdge *edge, PEdge *pair)
1854 PVert *newv, *keepv;
1861 PEdge *e1 = edge->next, *e2 = e1->next;
1864 e1->pair->pair = e1;
1867 e2->pair->pair = e2;
1870 e2->vert->edge = e2;
1879 e1->pair->pair = e1;
1882 e2->pair->pair = e2;
1897 }
while (
e && (
e != newv->edge));
1903 PVert *oldv, *keepv;
1908 if (!edge || !pair) {
1927static bool p_collapse_normal_flipped(
float *v1,
float *
v2,
float *vold,
float *vnew)
1929 float nold[3], nnew[3], sub1[3], sub2[3];
1939 return (
dot_v3v3(nold, nnew) <= 0.0f);
1942static bool p_collapse_allowed_geometric(PEdge *edge, PEdge *pair)
1944 PVert *oldv, *keepv;
1946 float angulardefect,
angle;
1950 angulardefect = 2 *
M_PI;
1954 float a[3],
b[3], minangle, maxangle;
1955 PEdge *e1 =
e->next, *e2 = e1->next;
1956 PVert *v1 = e1->vert, *
v2 = e2->vert;
1959 angle = p_vec_angle(v1->co, oldv->co,
v2->
co);
1960 angulardefect -=
angle;
1963 if (v1 == keepv ||
v2 == keepv) {
1968 if (p_collapse_normal_flipped(v1->co,
v2->
co, oldv->co, keepv->co)) {
1973 a[1] = p_vec_angle(
v2->
co, v1->co, oldv->co);
1974 a[2] =
M_PI - a[0] - a[1];
1976 b[0] = p_vec_angle(v1->co, keepv->co,
v2->
co);
1977 b[1] = p_vec_angle(
v2->
co, v1->co, keepv->co);
1982 maxangle =
M_PI - minangle;
1984 for (i = 0; i < 3; i++) {
1985 if ((
b[i] < a[i]) && (
b[i] < minangle)) {
1988 else if ((
b[i] > a[i]) && (
b[i] > maxangle)) {
1994 }
while (
e && (
e != oldv->edge));
2012 angle = p_vec_angle(v1->co, oldv->co,
v2->
co);
2021static bool p_collapse_allowed(
PEdge *edge,
PEdge *pair)
2023 PVert *oldv, *keepv;
2034static float p_collapse_cost(
PEdge *edge,
PEdge *pair)
2039 PVert *oldv, *keepv;
2041 PFace *oldf1, *oldf2;
2042 float volumecost = 0.0f, areacost = 0.0f, edgevec[3], cost, weight, elen;
2043 float shapecost = 0.0f;
2044 float shapeold = 0.0f, shapenew = 0.0f;
2045 int nshapeold = 0, nshapenew = 0;
2048 oldf1 = (edge) ? edge->face :
nullptr;
2049 oldf2 = (pair) ? pair->face :
nullptr;
2056 float *co1 =
e->next->vert->
co;
2057 float *co2 =
e->next->next->vert->
co;
2059 if (!
ELEM(
e->face, oldf1, oldf2)) {
2060 float tetrav2[3], tetrav3[3];
2068 shapecost +=
dot_v3v3(co1, keepv->co);
2071 shapecost +=
dot_v3v3(co2, keepv->co);
2076 a1 = a1 -
M_PI / 3.0;
2077 a2 = a2 -
M_PI / 3.0;
2078 a3 = a3 -
M_PI / 3.0;
2079 shapeold = (a1 * a1 + a2 * a2 + a3 * a3) / (
M_PI_2 *
M_PI_2);
2085 a1 = a1 -
M_PI / 3.0;
2086 a2 = a2 -
M_PI / 3.0;
2087 a3 = a3 -
M_PI / 3.0;
2088 shapenew = (a1 * a1 + a2 * a2 + a3 * a3) / (
M_PI_2 *
M_PI_2);
2094 }
while (
e && (
e != oldv->edge));
2105 cost = weight * volumecost * volumecost + elen * elen * areacost * areacost;
2109 shapeold /= nshapeold;
2110 shapenew /= nshapenew;
2111 shapecost = (shapeold + 0.00001) / (shapenew + 0.00001);
2124 const std::function<
float(
PEdge *,
PEdge *)> &collapse_cost_fn,
2125 const std::function<
float(
PEdge *,
PEdge *)> &collapse_allowed_fn)
2133 if (collapse_allowed_fn(
e,
e->pair)) {
2134 float cost = collapse_cost_fn(
e,
e->pair);
2136 if ((*r_mine ==
nullptr) || (cost < *r_mincost)) {
2144 if (enext ==
nullptr) {
2146 pair =
e->next->next;
2148 if (collapse_allowed_fn(
nullptr, pair)) {
2149 float cost = collapse_cost_fn(
nullptr, pair);
2151 if ((*r_mine ==
nullptr) || (cost < *r_mincost)) {
2161 }
while (
e != vert->edge);
2168 PVert *
v, *nextv =
nullptr, *verts = chart->
verts;
2169 PEdge *
e, *nexte =
nullptr, *edges = chart->
edges, *laste =
nullptr;
2170 PFace *f, *nextf =
nullptr, *faces = chart->
faces;
2178 for (
v = verts;
v;
v = nextv) {
2179 nextv =
v->nextlink;
2186 v->nextlink = chart->
verts;
2192 for (
e = edges;
e;
e = nexte) {
2193 nexte =
e->nextlink;
2201 e->nextlink = chart->
edges;
2210 for (
e = collapsed;
e;
e =
e->nextlink) {
2211 e->nextlink =
e->u.nextcollapse;
2219 for (f = faces; f; f = nextf) {
2235 std::function<
float(
PEdge *,
PEdge *)> collapse_cost_fn,
2236 std::function<
float(
PEdge *,
PEdge *)> collapse_allowed_fn)
2239 static const int MAX_SIMPLIFY =
INT_MAX;
2247 PEdge *collapsededges =
nullptr;
2263 v->u.heaplink =
nullptr;
2268 e->u.nextcollapse =
nullptr;
2273 if (ncollapsed == MAX_SIMPLIFY) {
2279 PVert *oldv, *keepv;
2280 PEdge *wheele, *nexte;
2284 collapsededges = edge;
2289 std::swap(edge, pair);
2300 wheele = oldv->
edge;
2306 if (nexte ==
nullptr) {
2311 }
while (wheele && (wheele != oldv->
edge));
2316 for (
PVert *
v : wheelverts) {
2318 PEdge *collapse =
nullptr;
2320 if (
v->u.heaplink) {
2322 v->u.heaplink =
nullptr;
2341static void p_chart_post_split_flush(PChart *chart)
2345 PVert *
v, *nextv =
nullptr;
2346 PEdge *
e, *nexte =
nullptr;
2347 PFace *f, *nextf =
nullptr;
2349 for (
v = chart->collapsed_verts;
v;
v = nextv) {
2350 nextv =
v->nextlink;
2351 v->nextlink = chart->verts;
2356 for (
e = chart->collapsed_edges;
e;
e = nexte) {
2357 nexte =
e->nextlink;
2358 e->nextlink = chart->edges;
2363 for (f = chart->collapsed_faces; f; f = nextf) {
2364 nextf = f->nextlink;
2365 f->nextlink = chart->faces;
2370 chart->collapsed_verts =
nullptr;
2371 chart->collapsed_edges =
nullptr;
2372 chart->collapsed_faces =
nullptr;
2375static void p_chart_complexify(
PChart *chart)
2378 static const int MAX_COMPLEXIFY =
INT_MAX;
2381 PVert *newv, *keepv;
2384 for (
e = chart->collapsed_edges;
e;
e =
e->nextlink) {
2393 std::swap(edge, pair);
2396 p_split_vertex(edge, pair);
2399 if (
x >= MAX_COMPLEXIFY) {
2400 newv->uv[0] = keepv->uv[0];
2401 newv->uv[1] = keepv->uv[1];
2404 p_vert_harmonic_insert(newv);
2409 p_chart_post_split_flush(chart);
2412static void p_chart_simplify(
PChart *chart)
2420#define ABF_MAX_ITER 20
2466 for (
int i = 0; i < sys->
nangles; i++) {
2485 if (aid == e1->
u.
id) {
2495 if (aid == e2->
u.
id) {
2504 e =
e->next->next->pair;
2505 }
while (
e && (
e !=
v->edge));
2507 return (sin1 - sin2);
2512 PVert *
v =
e->vert, *v1 =
e->next->vert, *
v2 =
e->next->next->vert;
2544 float gtriangle, galpha1, galpha2, galpha3;
2551 sys->
bAlpha[e2->u.id] = -galpha2;
2552 sys->
bAlpha[e3->u.id] = -galpha3;
2554 norm += galpha1 * galpha1 + galpha2 * galpha2 + galpha3 * galpha3;
2558 norm += gtriangle * gtriangle;
2561 for (
v = chart->
verts;
v;
v =
v->nextlink) {
2563 float gplanar = -2 *
M_PI, glength;
2567 gplanar += sys->
alpha[
e->u.id];
2568 e =
e->next->next->pair;
2569 }
while (
e && (
e !=
v->edge));
2572 norm += gplanar * gplanar;
2576 norm += glength * glength;
2585 const float dlambda1,
2589 const float dalpha = (sys->
bAlpha[
id] - dlambda1);
2590 alpha += dalpha / sys->
weight[
id] - pre;
2597 int nvar = 2 * ninterior;
2600 for (
int i = 0; i < nvar; i++) {
2605 float wi1, wi2, wi3,
b, si,
beta[3], j2[3][3],
W[3][3];
2606 float row1[6], row2[6], row3[6];
2609 PVert *v1 = e1->
vert, *
v2 = e2->vert, *v3 = e3->vert;
2612 wi2 = 1.0f / sys->
weight[e2->u.id];
2613 wi3 = 1.0f / sys->
weight[e3->u.id];
2617 b += sys->
bAlpha[e2->u.id] * wi2;
2618 b += sys->
bAlpha[e3->u.id] * wi3;
2622 si = 1.0f / (wi1 + wi2 + wi3);
2631 sys->
dstar[f->u.id] = si;
2638 W[1][1] = si - sys->
weight[e2->u.id];
2642 W[2][2] = si - sys->
weight[e3->u.id];
2644 vid[0] = vid[1] = vid[2] = vid[3] = vid[4] = vid[5] = -1;
2648 vid[3] = ninterior + v1->
u.
id;
2650 sys->
J2dt[e1->
u.
id][0] = j2[0][0] = 1.0f * wi1;
2656 context, 0, ninterior + v1->
u.
id, j2[1][0] *
beta[1] + j2[2][0] *
beta[2]);
2658 row1[0] = j2[0][0] *
W[0][0];
2659 row2[0] = j2[0][0] *
W[1][0];
2660 row3[0] = j2[0][0] *
W[2][0];
2662 row1[3] = j2[1][0] *
W[0][1] + j2[2][0] *
W[0][2];
2663 row2[3] = j2[1][0] *
W[1][1] + j2[2][0] *
W[1][2];
2664 row3[3] = j2[1][0] *
W[2][1] + j2[2][0] *
W[2][2];
2669 vid[4] = ninterior +
v2->u.id;
2672 sys->
J2dt[e2->u.id][1] = j2[1][1] = 1.0f * wi2;
2677 context, 0, ninterior +
v2->u.id, j2[0][1] *
beta[0] + j2[2][1] *
beta[2]);
2679 row1[1] = j2[1][1] *
W[0][1];
2680 row2[1] = j2[1][1] *
W[1][1];
2681 row3[1] = j2[1][1] *
W[2][1];
2683 row1[4] = j2[0][1] *
W[0][0] + j2[2][1] *
W[0][2];
2684 row2[4] = j2[0][1] *
W[1][0] + j2[2][1] *
W[1][2];
2685 row3[4] = j2[0][1] *
W[2][0] + j2[2][1] *
W[2][2];
2690 vid[5] = ninterior + v3->u.id;
2694 sys->
J2dt[e3->u.id][2] = j2[2][2] = 1.0f * wi3;
2698 context, 0, ninterior + v3->u.id, j2[0][2] *
beta[0] + j2[1][2] *
beta[1]);
2700 row1[2] = j2[2][2] *
W[0][2];
2701 row2[2] = j2[2][2] *
W[1][2];
2702 row3[2] = j2[2][2] *
W[2][2];
2704 row1[5] = j2[0][2] *
W[0][0] + j2[1][2] *
W[0][1];
2705 row2[5] = j2[0][2] *
W[1][0] + j2[1][2] *
W[1][1];
2706 row3[5] = j2[0][2] *
W[2][0] + j2[1][2] *
W[2][1];
2709 for (
int i = 0; i < 3; i++) {
2716 for (
int j = 0; j < 6; j++) {
2753 PVert *v1 = e1->
vert, *
v2 = e2->vert, *v3 = e3->vert;
2755 pre[0] = pre[1] = pre[2] = 0.0f;
2760 pre[0] += sys->
J2dt[e1->
u.
id][0] *
x;
2761 pre[1] += sys->
J2dt[e2->u.id][0] * x2;
2762 pre[2] += sys->
J2dt[e3->u.id][0] * x2;
2768 pre[0] += sys->
J2dt[e1->
u.
id][1] * x2;
2769 pre[1] += sys->
J2dt[e2->u.id][1] *
x;
2770 pre[2] += sys->
J2dt[e3->u.id][1] * x2;
2776 pre[0] += sys->
J2dt[e1->
u.
id][2] * x2;
2777 pre[1] += sys->
J2dt[e2->u.id][2] * x2;
2778 pre[2] += sys->
J2dt[e3->u.id][2] *
x;
2781 float dlambda1 = pre[0] + pre[1] + pre[2];
2782 dlambda1 = sys->
dstar[f->u.id] * (sys->
bstar[f->u.id] - dlambda1);
2791 for (
int i = 0; i < ninterior; i++) {
2809 float limit = (chart->
nfaces > 100) ? 1.0f : 0.001f;
2814 for (
v = chart->
verts;
v;
v =
v->nextlink) {
2851 sys.
weight[e1->
u.
id] = 2.0f / (a1 * a1);
2852 sys.
weight[e2->
u.
id] = 2.0f / (a2 * a2);
2853 sys.
weight[e3->
u.
id] = 2.0f / (a3 * a3);
2856 for (
v = chart->
verts;
v;
v =
v->nextlink) {
2858 float anglesum = 0.0,
scale;
2862 anglesum += sys.
beta[
e->u.id];
2863 e =
e->next->next->pair;
2864 }
while (
e && (
e !=
v->edge));
2866 scale = (anglesum == 0.0f) ? 0.0f : 2.0f *
float(
M_PI) / anglesum;
2871 e =
e->next->next->pair;
2872 }
while (
e && (
e !=
v->edge));
2915 if (!*pin1 || !*pin2 || *pin1 == *pin2) {
2921 (*pin1)->
uv[0] = 0.0f;
2922 (*pin1)->uv[1] = 0.5f;
2923 (*pin2)->uv[0] = 1.0f;
2924 (*pin2)->uv[1] = 0.5f;
2927 int diru, dirv, dirx, diry;
2931 sub[0] =
fabsf(sub[0]);
2932 sub[1] =
fabsf(sub[1]);
2933 sub[2] =
fabsf(sub[2]);
2935 if ((sub[0] > sub[1]) && (sub[0] > sub[2])) {
2937 diry = (sub[1] > sub[2]) ? 1 : 2;
2939 else if ((sub[1] > sub[0]) && (sub[1] > sub[2])) {
2941 diry = (sub[0] > sub[2]) ? 0 : 2;
2945 diry = (sub[0] > sub[1]) ? 0 : 1;
2957 (*pin1)->uv[diru] = (*pin1)->co[dirx];
2958 (*pin1)->uv[dirv] = (*pin1)->co[diry];
2959 (*pin2)->uv[diru] = (*pin2)->co[dirx];
2960 (*pin2)->uv[dirv] = (*pin2)->co[diry];
2966 PEdge *be, *lastbe =
nullptr, *maxe1 =
nullptr, *maxe2 =
nullptr, *be1, *be2;
2967 PEdge *cure =
nullptr, *firste1 =
nullptr, *firste2 =
nullptr, *nextbe;
2968 float maxlen = 0.0f, curlen = 0.0f, totlen = 0.0f, firstlen = 0.0f;
2994 if (curlen > maxlen) {
3000 if (firste1 == cure) {
3011 }
while (be != outer);
3014 if (cure && (cure != outer)) {
3017 if (firstlen > maxlen) {
3024 if (!maxe1 || !maxe2 || (maxlen < 0.5f * totlen)) {
3043 }
while (be1 != be2);
3062 }
while (be1 != be2);
3073 float minv[3], maxv[3], dirlen;
3074 PVert *
v, *minvert[3], *maxvert[3];
3078 minv[0] = minv[1] = minv[2] = 1e20;
3079 maxv[0] = maxv[1] = maxv[2] = -1e20;
3081 minvert[0] = minvert[1] = minvert[2] =
nullptr;
3082 maxvert[0] = maxvert[1] = maxvert[2] =
nullptr;
3084 for (
v = chart->
verts;
v;
v =
v->nextlink) {
3085 for (i = 0; i < 3; i++) {
3086 if (
v->
co[i] < minv[i]) {
3090 if (
v->
co[i] > maxv[i]) {
3101 for (i = 0; i < 3; i++) {
3102 if (maxv[i] - minv[i] > dirlen) {
3104 dirlen = maxv[i] - minv[i];
3108 *pin1 = minvert[dir];
3109 *pin2 = maxvert[dir];
3120 chart->
orig_bounds = MEM_new<PChartOrigBounds>(
"PChartOrigBounds");
3130 bool deselect =
false;
3132 if (use_original_bounds) {
3149 if (live && (!
select || !deselect)) {
3155 p_chart_topological_sanity_check(chart);
3170 param_warning(
"ABF solving failed: falling back to LSCM.\n");
3241 float area_pinned_up = 0.0f;
3242 float area_pinned_down = 0.0f;
3246 PVert *v1 = e1->
vert, *
v2 = e2->vert, *v3 = e3->vert;
3252 area_pinned_up += area;
3255 area_pinned_down -= area;
3260 const bool flip_faces = (area_pinned_down > area_pinned_up);
3267 PVert *v1 = e1->
vert, *
v2 = e2->vert, *v3 = e3->vert;
3286 double sina1 =
sin(a1);
3287 double sina2 =
sin(a2);
3288 double sina3 =
sin(a3);
3290 const double sinmax = std::max({sina1, sina2, sina3});
3293 if (sina3 != sinmax) {
3295 SHIFT3(
double, a1, a2, a3);
3296 SHIFT3(
double, sina1, sina2, sina3);
3298 if (sina2 == sinmax) {
3300 SHIFT3(
double, a1, a2, a3);
3301 SHIFT3(
double, sina1, sina2, sina3);
3306 const double ratio = (sina3 == 0.0f) ? 1.0f : sina2 / sina3;
3307 const double cosine =
cos(a1) * ratio;
3308 const double sine = sina1 * ratio;
3347 if (new_area > 0.0f) {
3367 chart->
pin1 =
nullptr;
3368 chart->
pin2 =
nullptr;
3374#define P_STRETCH_ITER 20
3380 for (
v = chart->
verts;
v;
v =
v->nextlink) {
3381 if (
v->edge->pair ==
nullptr) {
3396 PVert *v1 = e1->
vert, *
v2 = e2->vert, *v3 = e3->vert;
3406 w = 1.0f / (2.0f * area);
3439 T =
sqrtf(0.5f * (a + c));
3455 }
while (
e &&
e != (
v->edge));
3465 float orig_stretch, low, stretch_low, high, stretch_high, mid, stretch;
3466 float orig_uv[2], dir[2], random_angle, trusted_radius;
3468 for (
v = chart->
verts;
v;
v =
v->nextlink) {
3474 orig_uv[0] =
v->uv[0];
3475 orig_uv[1] =
v->uv[1];
3478 trusted_radius = 0.0f;
3487 }
while (
e &&
e != (
v->edge));
3489 trusted_radius /= 2 * nedges;
3492 dir[0] = trusted_radius *
cosf(random_angle);
3493 dir[1] = trusted_radius *
sinf(random_angle);
3497 stretch_low = orig_stretch;
3505 mid = 0.5f * (low + high);
3506 v->uv[0] = orig_uv[0] + mid * dir[0];
3507 v->uv[1] = orig_uv[1] + mid * dir[1];
3510 if (stretch_low < stretch_high) {
3512 stretch_high = stretch;
3516 stretch_low = stretch;
3521 if (stretch >= orig_stretch) {
3531 const PVert *v1 = *
static_cast<const PVert *
const *
>(a);
3534 if (v1->
uv[0] <
v2->uv[0]) {
3537 if (v1->
uv[0] ==
v2->uv[0]) {
3538 if (v1->
uv[1] <
v2->uv[1]) {
3541 if (v1->
uv[1] ==
v2->uv[1]) {
3555 int npoints = 0, i, ulen, llen;
3556 PVert **
U, **
L, **points, **p;
3584 for (p = points, i = 0; i < npoints; i++, p++) {
3585 while ((ulen > 1) && (
p_area_signed(
U[ulen - 2]->
uv, (*p)->uv,
U[ulen - 1]->uv) <= 0)) {
3588 while ((llen > 1) && (
p_area_signed(
L[llen - 2]->
uv, (*p)->uv,
L[llen - 1]->uv) >= 0)) {
3599 for (p = points, i = 0; i < ulen; i++, p++, npoints++) {
3604 for (i = llen - 2; i > 0; i--, p++, npoints++) {
3609 *r_nverts = npoints;
3610 *r_right = ulen - 1;
3623 float orthodir[2], corner1[2], corner2[2], corner3[2];
3625 orthodir[0] = dir[1];
3626 orthodir[1] = -dir[0];
3648 float rotated, minarea, minangle, area,
len;
3649 float *angles, miny, maxy,
v[2], a[4], mina;
3650 int npoints, right, i_min, i_max, i, idx[4], nextidx;
3651 PVert **points, *p1, *p2, *p3, *p4, *p1n;
3665 for (i = 0; i < npoints; i++) {
3666 p1 = (i == 0) ? points[npoints - 1] : points[i - 1];
3668 p3 = (i == npoints - 1) ? points[0] : points[i + 1];
3672 if (points[i]->
uv[1] < miny) {
3673 miny = points[i]->
uv[1];
3676 if (points[i]->
uv[1] > maxy) {
3677 maxy = points[i]->
uv[1];
3688 v[0] = points[idx[0]]->
uv[0];
3689 v[1] = points[idx[0]]->
uv[1] + 1.0f;
3692 v[0] = points[idx[1]]->
uv[0] + 1.0f;
3693 v[1] = points[idx[1]]->
uv[1];
3696 v[0] = points[idx[2]]->
uv[0];
3697 v[1] = points[idx[2]]->
uv[1] - 1.0f;
3700 v[0] = points[idx[3]]->
uv[0] - 1.0f;
3701 v[1] = points[idx[3]]->
uv[1];
3710 while (rotated <=
float(
M_PI_2)) {
3715 for (i = 0; i < 4; i++) {
3723 nextidx = (idx[i_min] + 1) % npoints;
3725 a[i_min] = angles[nextidx];
3726 a[(i_min + 1) % 4] = a[(i_min + 1) % 4] - mina;
3727 a[(i_min + 2) % 4] = a[(i_min + 2) % 4] - mina;
3728 a[(i_min + 3) % 4] = a[(i_min + 3) % 4] - mina;
3731 p1 = points[idx[i_min]];
3732 p1n = points[nextidx];
3733 p2 = points[idx[(i_min + 1) % 4]];
3734 p3 = points[idx[(i_min + 2) % 4]];
3735 p4 = points[idx[(i_min + 3) % 4]];
3741 v[0] = (p1n->
uv[0] - p1->
uv[0]) *
len;
3742 v[1] = (p1n->
uv[1] - p1->
uv[1]) *
len;
3747 if (area < minarea) {
3753 idx[i_min] = nextidx;
3757 if (minangle >
float(
M_PI_4)) {
3774 for (
v = chart->
verts;
v;
v =
v->nextlink) {
3775 float oldu =
v->uv[0], oldv =
v->uv[1];
3776 v->uv[0] = cosine * oldu - sine * oldv;
3777 v->uv[1] = sine * oldu + cosine * oldv;
3829 for (
int i = 0; i <
ncharts; i++) {
3830 MEM_SAFE_DELETE(
charts[i]->orig_bounds);
3831 MEM_SAFE_DELETE(
charts[i]);
3868 pinuvlist = pinuvlist->
next;
3871 if (bestdistsquared > distsquared) {
3872 bestdistsquared = distsquared;
3875 pinuvlist = pinuvlist->
next;
3884 pinuv->
next =
nullptr;
3908 if (!pinuvlist->
next) {
3912 pinuvlist = pinuvlist->
next;
3922 const float *weight,
3927 uint nfilltri = nverts - 2;
3932 for (
uint j = 0; j < nfilltri; j++) {
3933 uint *tri = tris[j];
3938 const ParamKey tri_vkeys[3] = {vkeys[v0], vkeys[v1], vkeys[
v2]};
3939 const float *tri_co[3] = {co[v0], co[v1], co[
v2]};
3940 float *tri_uv[3] = {
uv[v0],
uv[v1],
uv[
v2]};
3942 const float *tri_weight =
nullptr;
3943 float tri_weight_tmp[3];
3946 tri_weight_tmp[0] = weight[v0];
3947 tri_weight_tmp[1] = weight[v1];
3948 tri_weight_tmp[2] = weight[
v2];
3949 tri_weight = tri_weight_tmp;
3952 const bool tri_pin[3] = {pin[v0], pin[v1], pin[
v2]};
3956 handle, key, 3, tri_vkeys, tri_co, tri_uv, tri_weight, tri_pin, tri_select);
3968 const float *weight,
3981 for (
int i = 0; i < nverts; i++) {
3985 for (
int i = nverts - 1; i >= 0;) {
3990 const int pm = int(permute.
size());
3992 int i0 = permute[i];
3993 int i1 = permute[(i + 1) % pm];
3994 int i2 = permute[(i + 2) % pm];
4004 int iprev = permute[(i + pm - 1) % pm];
4005 p_face_add_construct(phandle, key, vkeys, co,
uv, weight, iprev, i0, i1, pin,
select);
4008 if (permute.
size() == 3) {
4013 if (permute.
size() != nverts) {
4014 const int pm = int(permute.
size());
4022 for (
int i = 0; i < pm; i++) {
4024 vkeys_sub[i] = vkeys[j];
4028 weight_sub[i] = weight[j];
4030 pin_sub[i] = pin && pin[j];
4039 weight ? &weight_sub.
first() :
nullptr,
4041 &select_sub.
first());
4052 p_face_add_construct(phandle, key, vkeys, co,
uv, weight, 0, 1, 2, pin,
select);
4068 bool topology_from_uvs,
4069 int *r_count_failed)
4085 for (i = j = 0; i < phandle->
ncharts; i++) {
4091 if (!topology_from_uvs && chart->
nboundaries == 0) {
4093 if (r_count_failed) {
4094 *r_count_failed += 1;
4099 phandle->
charts[j++] = chart;
4118 const bool use_original_bounds)
4123 for (
int i = 0; i < phandle->
ncharts; i++) {
4135 for (
int i = 0; i < phandle->
ncharts; i++) {
4157 if (count_changed !=
nullptr) {
4158 *count_changed += 1;
4162 if (count_failed !=
nullptr) {
4173 for (
int i = 0; i < phandle->
ncharts; i++) {
4176 p_chart_complexify(phandle->
charts[i]);
4189 phandle->
blend = 0.0f;
4191 for (
int i = 0; i < phandle->
ncharts; i++) {
4210 phandle->
blend = blend;
4216 for (
int i = 0; i < phandle->
ncharts; i++) {
4237 for (
int i = 0; i < handle->
ncharts; i++) {
4251 PVert *
v2 = f->edge->next->next->vert;
4255 pack_island_vector.
append(pack_island);
4261 PackIsland *pack_island = pack_island_vector[i];
4262 const float island_scale = pack_island->
can_scale_(params) ?
scale : 1.0f;
4272 pack_island_vector[i] =
nullptr;
4282 float trans[2], minv[2], maxv[2], new_size[2];
4286 bool all_verts_selected =
true;
4289 all_verts_selected =
false;
4293 if (!all_verts_selected) {
4304 const float size = std::max(orig_size.x, orig_size.y);
4318 float tot_area_3d = 0.0f;
4319 float tot_area_uv = 0.0f;
4320 float minv[2], maxv[2], trans[2];
4326 for (i = 0; i < phandle->
ncharts; i++) {
4329 if (ignore_pinned && chart->
has_pins) {
4337 if (scale_uv || shear) {
4342 for (
int j = 0; j < max_iter; j++) {
4346 double scale_cou = 0;
4347 double scale_cov = 0;
4348 double scale_cross = 0;
4349 double weight_sum = 0;
4351 float m[2][2], s[2][2];
4355 s[0][0] = va->
uv[0] - vc->
uv[0];
4356 s[0][1] = va->
uv[1] - vc->
uv[1];
4357 s[1][0] = vb->
uv[0] - vc->
uv[0];
4358 s[1][1] = vb->
uv[1] - vc->
uv[1];
4364 float cou[3], cov[3];
4365 for (
int k = 0; k < 3; k++) {
4366 cou[k] = m[0][0] * (va->
co[k] - vc->
co[k]) + m[0][1] * (vb->
co[k] - vc->
co[k]);
4367 cov[k] = m[1][0] * (va->
co[k] - vc->
co[k]) + m[1][1] * (vb->
co[k] - vc->
co[k]);
4370 scale_cou +=
len_v3(cou) * weight;
4371 scale_cov +=
len_v3(cov) * weight;
4380 scale_cross +=
dot_v3v3(cou, cov) * weight;
4382 weight_sum += weight;
4384 if (scale_cou * scale_cov < 1e-10f) {
4387 const float scale_factor_u = scale_uv ?
sqrtf(scale_cou / scale_cov) : 1.0f;
4391 t[0][0] = scale_factor_u;
4392 t[1][0] =
clamp_f(
float(scale_cross / weight_sum), -0.5f, 0.5f);
4394 t[1][1] = 1.0f / scale_factor_u;
4400 const float err =
fabsf(t[0][0] - 1.0f) +
fabsf(t[1][0]) +
fabsf(t[0][1]) +
4401 fabsf(t[1][1] - 1.0f);
4403 const float tolerance = 1e-6f;
4404 if (err < tolerance) {
4419 tot_area_3d += chart->
area_3d;
4420 tot_area_uv += chart->
area_uv;
4423 if (tot_area_3d == 0.0f || tot_area_uv == 0.0f) {
4428 const float tot_fac = tot_area_3d / tot_area_uv;
4430 for (i = 0; i < phandle->
ncharts; i++) {
4433 if (ignore_pinned && chart->
has_pins) {
4457 for (
int i = 0; i < phandle->
ncharts; i++) {
4469 for (
int i = 0; i < phandle->
ncharts; i++) {
4483 PVert *oldv, *keepv;
4497 PEdge *collapse_e = edge ? edge : pair;
4503 PEdge *collapse_e = edge ? edge : pair;
4509 const float threshold_squared = threshold * threshold;
4519 PVert *newv, *keepv;
4528 std::swap(edge, pair);
4533 newv->
uv[0] = keepv->
uv[0];
4534 newv->
uv[1] = keepv->
uv[1];
4540 const float corr_co1[3],
4541 const float corr_co2[3],
4542 const float min_area,
4543 const float min_angle_cos)
4562 if (
e->next->next == corr_e->
pair) {
4563 PVert *other_v =
e->next->next->vert;
4567 const PVert *other_v1 =
e->next->vert;
4568 const PVert *other_v2 =
e->next->next->vert;
4572 if (area < min_area) {
4578 if (
e->next->next == corr_e->
pair) {
4579 PVert *other_v =
e->next->next->vert;
4580 p_triangle_cos(corr_co1, corr_co2, other_v->
co, f_cos, f_cos + 1, f_cos + 2);
4583 const PVert *other_v1 =
e->next->vert;
4584 const PVert *other_v2 =
e->next->next->vert;
4588 for (
int i = 0; i < 3; i++) {
4589 if (f_cos[i] > min_angle_cos) {
4600 const float corr_co[3],
4602 float min_angle_cos)
4615 const PVert *other_v1 =
e->next->vert;
4616 const PVert *other_v2 =
e->next->next->vert;
4620 if (area < min_area) {
4627 for (
int i = 0; i < 3; i++) {
4628 if (f_cos[i] > min_angle_cos) {
4640 static const constexpr float eps = 1.0e-5;
4641 static const constexpr float n1[3] = {0.0f, 0.0f, 1.0f};
4642 static const constexpr float n2[3] = {0.0f, 1.0f, 0.0f};
4644 float edge_len =
len_v3(edge_dir);
4645 if (edge_len <
eps) {
4649 float edge_dir_norm[3];
4651 mul_v3_fl(edge_dir_norm, 1.0f / edge_len);
4653 float normal_dir[3];
4655 float normal_len =
len_v3(normal_dir);
4657 if (normal_len <
eps) {
4659 normal_len =
len_v3(normal_dir);
4661 if (normal_len <
eps) {
4666 mul_v3_fl(normal_dir, 1.0f / normal_len);
4668 float tangent_dir[3];
4671 R[0][0] = edge_dir_norm[0];
4672 R[1][0] = edge_dir_norm[1];
4673 R[2][0] = edge_dir_norm[2];
4675 R[0][1] = normal_dir[0];
4676 R[1][1] = normal_dir[1];
4677 R[2][1] = normal_dir[2];
4679 R[0][2] = tangent_dir[0];
4680 R[1][2] = tangent_dir[1];
4681 R[2][2] = tangent_dir[2];
4699 float min_angle_cos)
4701 static const float3 ref_edges[] = {
4717 static const int ref_edge_count =
ARRAY_SIZE(ref_edges);
4718 static const int LEN_MULTIPLIER_COUNT = 3;
4719 bool corr_co_found =
false;
4721 float corr_len = 2.0f * std::sqrt((min_area +
CORR_ZERO_AREA_EPS) / 3.0f / std::sqrt(3.0f));
4723 for (
int m = 0; m < LEN_MULTIPLIER_COUNT; m++) {
4724 for (
int re = 0; re < ref_edge_count; re++) {
4731 float corr_co[3][3];
4734 for (
int i = 0; i < 3; i++) {
4738 float corr_len_multiplied = corr_len * (m + 1);
4741 mul_v3_fl(corr_dir, corr_len_multiplied);
4749 for (
int i = 0; i < 3; i++) {
4751 e, corr_co[i], corr_co[(i + 1) % 3], min_area, min_angle_cos))
4760 for (
int i = 0; i < 3; i++) {
4765 corr_co_found =
true;
4769 if (corr_co_found) {
4774 if (!corr_co_found) {
4784 static const float eps = 1.0e-6;
4786 float min_angle_cos = std::cos(min_angle);
4796 PEdge *max_edge =
nullptr;
4797 float max_edge_len = -std::numeric_limits<float>::infinity();
4799 PEdge *min_edge =
nullptr;
4800 float min_edge_len = std::numeric_limits<float>::infinity();
4802 PEdge *middle_edge =
nullptr;
4808 if (
len > max_edge_len) {
4812 middle_edge = max_edge->
next == min_edge ? min_edge->
next : max_edge->
next;
4815 if (
len < min_edge_len) {
4819 middle_edge = min_edge->
next == max_edge ? max_edge->
next : min_edge->
next;
4823 }
while (
e != f->edge);
4829 bool small_uniside_tri = (face_area <= min_area) && (min_edge == max_edge);
4831 if ((max_edge_len <
eps) || small_uniside_tri) {
4836 if (min_edge == max_edge) {
4850 float max_face_cos =
4851 middle_edge->
next == max_edge ?
4855 float angle_corr_len = max_face_cos > min_angle_cos ?
4859 if ((face_area > min_area) && (angle_corr_len == 0.0f)) {
4865 corr_len = std::max(corr_len, angle_corr_len);
4871 static const constexpr int DIR_COUNT = 16;
4872 static const constexpr int LEN_MULTIPLIER_COUNT = 2;
4874 bool corr_co_found =
false;
4876 for (
int m = 0; m < LEN_MULTIPLIER_COUNT; m++) {
4877 for (
int d = 0; d < DIR_COUNT; d++) {
4881 const float corr_len_multiplied = corr_len * (m + 1);
4884 mul_v3_fl(corr_dir, corr_len_multiplied);
4890 corr_co_found =
true;
4895 if (corr_co_found) {
4900 if (!corr_co_found) {
4916 const float min_angle_cos)
4921 for (
int i = 0; i < 3; i++) {
4922 if (t_cos[i] > min_angle_cos) {
4933 const float min_area,
4934 const float min_angle)
5023static void slim_transfer_edges(
PChart *chart, slim::MatrixTransferChart *mt_chart)
5026 std::vector<double> &EL = mt_chart->
el_vectors;
5034 static const float DOUBLED_VERT_THRESHOLD = 1.0e-5;
5037 E[eid] = be->vert->slim_id;
5042 if (edge_len < DOUBLED_VERT_THRESHOLD) {
5050 }
while (be != outer);
5052 for (
PEdge *
e = chart->edges;
e;
e =
e->nextlink) {
5055 E[eid] =
e->vert->slim_id;
5060 if (edge_len < DOUBLED_VERT_THRESHOLD) {
5072static void slim_transfer_vertices(
const PChart *chart,
5073 slim::MatrixTransferChart *mt_chart,
5074 slim::MatrixTransfer *mt)
5077 std::vector<double> &v_mat = mt_chart->
v_matrices;
5078 std::vector<double> &uv_mat = mt_chart->
uv_matrices;
5079 std::vector<int> &p_mat = mt_chart->
p_matrices;
5080 std::vector<double> &pp_mat = mt_chart->
pp_matrices;
5081 std::vector<float> &w_vec = mt_chart->
w_vectors;
5087 for (
PVert *
v = chart->verts;
v;
v =
v->nextlink) {
5088 if (!
v->on_boundary_flag) {
5090 w_vec[vid] =
v->weight;
5097 v_mat[
v->slim_id] =
v->
co[0];
5098 v_mat[r +
v->slim_id] =
v->
co[1];
5099 v_mat[2 * r +
v->slim_id] =
v->
co[2];
5101 uv_mat[
v->slim_id] =
v->uv[0];
5102 uv_mat[r +
v->slim_id] =
v->uv[1];
5107 p_mat[p_vid] =
v->slim_id;
5108 pp_mat[2 * p_vid] = double(
v->uv[0]);
5109 pp_mat[2 * p_vid + 1] = double(
v->uv[1]);
5118static void slim_transfer_boundary_vertices(
PChart *chart,
5119 slim::MatrixTransferChart *mt_chart,
5120 const slim::MatrixTransfer *mt)
5122 std::vector<int> &b_vec = mt_chart->
b_vectors;
5123 std::vector<float> &w_vec = mt_chart->
w_vectors;
5126 for (
PVert *
v = chart->verts;
v;
v =
v->nextlink) {
5127 v->on_boundary_flag =
false;
5139 w_vec[vid] = be->vert->weight;
5143 be->vert->slim_id = vid;
5144 be->vert->on_boundary_flag =
true;
5150 }
while (be != outer);
5156static void slim_transfer_faces(
const PChart *chart, slim::MatrixTransferChart *mt_chart)
5168 F[fid] =
e->vert->slim_id;
5169 F[r + fid] = e1->vert->slim_id;
5170 F[2 * r + fid] = e2->vert->slim_id;
5178static void slim_convert_blender(
ParamHandle *phandle,
5179 slim::MatrixTransfer *mt,
5180 const bool use_original_bounds)
5182 static const float SLIM_CORR_MIN_AREA = 1.0e-8;
5183 static const float SLIM_CORR_MIN_ANGLE =
DEG2RADF(1.0f);
5185 mt->
charts.resize(phandle->ncharts);
5187 for (
int i = 0; i < phandle->ncharts; i++) {
5188 PChart *chart = phandle->charts[i];
5189 if (use_original_bounds) {
5192 slim::MatrixTransferChart *mt_chart = &mt->
charts[i];
5201 slim_allocate_matrices(chart, mt_chart);
5204 slim_transfer_boundary_vertices(chart, mt_chart, mt);
5205 slim_transfer_vertices(chart, mt_chart, mt);
5206 slim_transfer_edges(chart, mt_chart);
5207 slim_transfer_faces(chart, mt_chart);
5223static void slim_transfer_data_to_slim(
ParamHandle *phandle,
5225 const bool use_original_bounds)
5227 slim::MatrixTransfer *mt = slim_matrix_transfer(slim_options);
5229 slim_convert_blender(phandle, mt, use_original_bounds);
5230 phandle->slim_mt = mt;
5237 slim::MatrixTransfer *mt,
5245 for (
int i = 0; i < phandle->ncharts; i++) {
5246 PChart *chart = phandle->charts[i];
5247 slim::MatrixTransferChart *mt_chart = &mt->
charts[i];
5250 if (count_changed) {
5255 for (
v = chart->verts;
v;
v =
v->nextlink) {
5271 for (
v = chart->verts;
v;
v =
v->nextlink) {
5283static void slim_free_matrix_transfer(
ParamHandle *phandle)
5285 delete phandle->slim_mt;
5286 phandle->slim_mt =
nullptr;
5289static void slim_get_pinned_vertex_data(
ParamHandle *phandle,
5291 slim::MatrixTransferChart &mt_chart,
5292 slim::PinnedVertexData &pinned_vertex_data)
5296 std::vector<int> &selected_pins = pinned_vertex_data.
selected_pins;
5298 pinned_vertex_indices.clear();
5299 pinned_vertex_positions_2D.clear();
5300 selected_pins.clear();
5312 selected_pins.push_back(be->vert->slim_id);
5315 pinned_vertex_indices.push_back(be->vert->slim_id);
5316 pinned_vertex_positions_2D.push_back(be->vert->uv[0]);
5317 pinned_vertex_positions_2D.push_back(be->vert->uv[1]);
5320 }
while (be != outer);
5323 for (
v = chart->verts;
v;
v =
v->nextlink) {
5324 if (!
v->on_boundary_flag && (
v->flag &
PVERT_PIN)) {
5329 selected_pins.push_back(
v->slim_id);
5331 pinned_vertex_indices.push_back(
v->slim_id);
5332 pinned_vertex_positions_2D.push_back(
v->uv[0]);
5333 pinned_vertex_positions_2D.push_back(
v->uv[1]);
5350 bool use_original_bounds,
5355 slim_transfer_data_to_slim(phandle, slim_options, use_original_bounds);
5360 slim_flush_uvs(phandle, mt, count_changed, count_failed);
5361 slim_free_matrix_transfer(phandle);
5363 UNUSED_VARS(phandle, slim_options, use_original_bounds, count_changed, count_failed);
5370 slim_transfer_data_to_slim(phandle, slim_options,
false);
5373 for (
int i = 0; i < phandle->
ncharts; i++) {
5379 for (
int i = 0; i < phandle->
ncharts; i++) {
5383 bool select =
false, deselect =
false;
5398 if (!
select || !deselect) {
5417 for (
int i = 0; i < phandle->
ncharts; i++) {
5418 mt->
charts[i].parametrize_single_iteration();
5419 mt->
charts[i].transfer_uvs_blended(blend);
5423 slim_flush_uvs(phandle, mt,
nullptr,
nullptr);
5435 for (
int i = 0; i < phandle->
ncharts; i++) {
5439 if (!mt_chart.
data) {
5449 const bool live =
true;
5450 slim_flush_uvs(phandle, mt,
nullptr,
nullptr, live);
5461 for (
int i = 0; i < phandle->
ncharts; i++) {
5466 slim_free_matrix_transfer(phandle);
5475 return phandle->
slim_mt !=
nullptr;
#define BLI_MEMARENA_STD_BUFSIZE
#define BLI_POLYFILL_ALLOC_NGON_RESERVE
#define INIT_MINMAX2(min, max)
#define UNUSED_FUNCTION(x)
#define POINTER_FROM_INT(i)
#define SHIFT3(type, a, b, c)
#define MEM_SIZE_OPTIMAL(size)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
MutableSpan< T > as_mutable_span()
void reinitialize(const int64_t new_size)
constexpr int64_t size() const
constexpr void copy_from(Span< T > values) const
void append(const T &value)
void remove(const int64_t index)
IndexRange index_range() const
void append_unchecked(const T &value)
void reserve(const int64_t min_capacity)
bool can_scale_(const UVPackIsland_Params ¶ms) const
void build_transformation(float scale, double angle, float r_matrix[2][2]) const
void add_triangle(float2 uv0, float2 uv1, float2 uv2)
PChart * construction_chart
MemArena * polyfill_arena
slim::MatrixTransfer * slim_mt
eUVPackIsland_PinMethod pin_method
float udim_base_offset[2]
float3x3 scale(float3x3 mat, float2 scale)
LinearSolver * EIG_linear_solver_new(int num_rows, int num_columns, int num_right_hand_sides)
void EIG_linear_solver_variable_set(LinearSolver *solver, int rhs, int index, double value)
void EIG_linear_solver_right_hand_side_add(LinearSolver *solver, int rhs, int index, double value)
LinearSolver * EIG_linear_least_squares_solver_new(int num_rows, int num_columns, int num_right_hand_sides)
void EIG_linear_solver_delete(LinearSolver *solver)
double EIG_linear_solver_variable_get(LinearSolver *solver, int rhs, int index)
void EIG_linear_solver_matrix_add(LinearSolver *solver, int row, int col, double value)
bool EIG_linear_solver_solve(LinearSolver *solver)
void EIG_linear_solver_variable_lock(LinearSolver *solver, int index)
ccl_device_inline float beta(const float x, const float y)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
ccl_device_inline void sincos(const float3 x, ccl_private float3 *sine, ccl_private float3 *cosine)
int size(const AssetLibraryReference *library_reference)
static void p_chart_rotate_minimum_area(PChart *chart)
bool uv_parametrizer_is_slim(const ParamHandle *phandle)
static PVert * p_vert_add(ParamHandle *handle, PHashKey key, const float co[3], const float weight, PEdge *e)
static PFace * p_face_add_construct(ParamHandle *handle, ParamKey key, const ParamKey *vkeys, const float **co, float **uv, const float *weight, int i1, int i2, int i3, const bool *pin, const bool *select)
void uv_parametrizer_construct_end(ParamHandle *phandle, bool fill_holes, bool topology_from_uvs, int *r_count_failed=nullptr)
static bool p_validate_corrected_coords(const PEdge *corr_e, const float corr_co[3], float min_area, float min_angle_cos)
static void p_chart_fill_boundaries(ParamHandle *handle, PChart *chart, const PEdge *outer)
static PFace * p_face_add_fill(ParamHandle *handle, PChart *chart, PVert *v1, PVert *v2, PVert *v3)
void uv_parametrizer_edge_set_seam(ParamHandle *phandle, const ParamKey *vkeys)
static void p_vert_load_pin_select_uvs(ParamHandle *handle, PVert *v)
static bool p_chart_lscm_solve(ParamHandle *handle, PChart *chart)
static void p_face_angles(PFace *f, double *r_a1, double *r_a2, double *r_a3)
static bool p_intersect_line_2d_dir(const float v1[2], const float dir1[2], const float v2[2], const float dir2[2], float r_isect[2])
void uv_parametrizer_average(ParamHandle *handle, bool ignore_pinned, bool scale_uv, bool shear)
static float p_chart_uv_area(PChart *chart)
void uv_parametrizer_flush(ParamHandle *handle)
static PHash * phash_new(PHashLink **list, int sizehint)
static bool UNUSED_FUNCTION_NO_SLIM p_chart_correct_degenerate_triangles(PChart *chart, const float min_area, const float min_angle)
void uv_parametrizer_lscm_begin(ParamHandle *handle, bool live, bool abf, bool use_original_bounds)
static void p_face_backup_uvs(PFace *f)
static void p_abf_adjust_alpha(PAbfSystem *sys, const int id, const float dlambda1, const float pre)
static void p_chart_rotate_fit_aabb(PChart *chart)
static void p_flush_uvs(ParamHandle *handle, PChart *chart)
void uv_parametrizer_slim_live_begin(ParamHandle *phandle, const ParamSlimOptions *slim_options)
static void p_collapse_cost_vertex(PVert *vert, float *r_mincost, PEdge **r_mine, const std::function< float(PEdge *, PEdge *)> &collapse_cost_fn, const std::function< float(PEdge *, PEdge *)> &collapse_allowed_fn)
static float p_rectangle_area(float *p1, float *dir, float *p2, float *p3, float *p4)
void uv_parametrizer_slim_stretch_iteration(ParamHandle *phandle, float blend)
static float p_collapse_doubles_cost(PEdge *edge, PEdge *pair)
static bool p_collapse_allowed_topologic(PEdge *edge, PEdge *pair)
static void phash_safe_delete(PHash **pph)
static bool p_chart_symmetry_pins(PChart *chart, PEdge *outer, PVert **pin1, PVert **pin2)
static bool p_chart_convex_hull(PChart *chart, PVert ***r_verts, int *r_nverts, int *r_right)
static float p_vec_cos(const float v1[3], const float v2[3], const float v3[3])
void uv_parametrizer_slim_live_solve_iteration(ParamHandle *phandle)
static void p_chart_stretch_minimize(PChart *chart, RNG *rng)
static PEdge * p_edge_lookup(ParamHandle *handle, const PHashKey *vkeys)
static float p_face_stretch(PFace *f)
ParamKey uv_find_pin_index(ParamHandle *handle, const int bmvertindex, const float uv[2])
static void p_split_vert(ParamHandle *handle, PChart *chart, PEdge *e)
static PEdge * p_wheel_edge_prev(PEdge *e)
static void p_collapsing_verts(PEdge *edge, PEdge *pair, PVert **r_newv, PVert **r_keepv)
static constexpr int P_NGON_STACK_NUM
static void p_stretch_pin_boundary(PChart *chart)
static float p_chart_minimum_area_angle(PChart *chart)
static bool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart)
static int phash_size(PHash *ph)
static bool p_chart_correct_degenerate_triangle_point(PFace *f, float min_area, float min_angle_cos)
static float p_edge_length(PEdge *e)
void uv_prepare_pin_index(ParamHandle *handle, const int bmvertindex, const float uv[2])
static void p_face_restore_uvs(PFace *f)
static PEdge * p_wheel_edge_next(PEdge *e)
void uv_parametrizer_slim_live_end(ParamHandle *phandle)
static void p_chart_lscm_end(PChart *chart)
static void UNUSED_FUNCTION p_chart_collapse_doubles(PChart *chart, const float threshold)
static void p_abf_setup_system(PAbfSystem *sys)
static const float CORR_ZERO_AREA_EPS
static void p_abf_compute_sines(PAbfSystem *sys)
static int p_compare_geometric_uv(const void *a, const void *b)
static void p_chart_pin_positions(PChart *chart, PVert **pin1, PVert **pin2)
static float p_edge_length_squared(PEdge *e)
void uv_parametrizer_stretch_blend(ParamHandle *handle, float blend)
static void p_chart_uv_bbox(PChart *chart, float minv[2], float maxv[2])
static bool p_edge_matrix(float R[3][3], const float edge_dir[3])
static bool p_edge_connect_pair(ParamHandle *handle, PEdge *e, bool topology_from_uvs, PEdge ***stack)
void mul_v2_m2_add_v2v2(float r[2], const float mat[2][2], const float a[2], const float b[2])
static void p_chart_post_collapse_flush(PChart *chart, PEdge *collapsed)
static void p_collapse_edge(PEdge *edge, PEdge *pair)
static bool p_vert_interior(PVert *v)
static GeoUVPinIndex * new_geo_uv_pinindex(ParamHandle *handle, const float uv[2])
static float p_abf_compute_grad_alpha(PAbfSystem *sys, PFace *f, PEdge *e)
static float p_face_uv_area_signed(PFace *f)
static bool p_collapse_doubles_allowed(PEdge *edge, PEdge *pair, float threshold_squared)
static void p_chart_uv_to_array(PChart *chart, MutableSpan< float2 > points)
static void UNUSED_FUNCTION p_face_cos(PFace *f, float *r_cos1, float *r_cos2, float *r_cos3)
static void p_vert_fix_edge_pointer(PVert *v)
static void p_chart_uv_translate(PChart *chart, const float trans[2])
static bool p_edge_implicit_seam(PEdge *e, PEdge *ep)
static void p_chart_uv_scale(PChart *chart, const float scale)
void uv_parametrizer_lscm_end(ParamHandle *handle)
static bool p_edge_has_pair(ParamHandle *handle, PEdge *e, bool topology_from_uvs, PEdge **r_pair)
static float p_area_signed(const float v1[2], const float v2[2], const float v3[2])
void uv_parametrizer_aspect_ratio(ParamHandle *handle, float aspect_y)
static void p_chart_uv_transform(PChart *chart, const float mat[2][2])
static float p_abf_compute_gradient(PAbfSystem *sys, PChart *chart)
void uv_parametrizer_stretch_begin(ParamHandle *handle)
static PEdge * p_boundary_edge_next(PEdge *e)
static PHashLink * phash_lookup(PHash *ph, PHashKey key)
static void p_chart_uv_rotate(PChart *chart, float angle)
static void p_triangle_angles(const float v1[3], const float v2[3], const float v3[3], double *r_a1, double *r_a2, double *r_a3)
void uv_parametrizer_flush_restore(ParamHandle *handle)
static bool p_chart_abf_solve(PChart *chart)
static bool p_chart_correct_degenerate_triangles2(PChart *chart, float min_area, float min_angle)
static PVert * p_vert_copy(ParamHandle *handle, PVert *v)
void uv_parametrizer_pack(ParamHandle *handle, const UVPackIsland_Params ¶ms)
static bool p_validate_corrected_coords_point(const PEdge *corr_e, const float corr_co1[3], const float corr_co2[3], const float min_area, const float min_angle_cos)
static PFace * p_face_add(ParamHandle *handle)
static void p_triangle_cos(const float v1[3], const float v2[3], const float v3[3], float *r_cos1, float *r_cos2, float *r_cos3)
static float p_stretch_compute_vertex(PVert *v)
static PChart ** p_split_charts(ParamHandle *handle, PChart *chart, int ncharts)
static void p_add_ngon(ParamHandle *handle, const ParamKey key, const int nverts, const ParamKey *vkeys, const float **co, float **uv, const float *weight, const bool *pin, const bool *select)
static float p_abf_compute_sin_product(PAbfSystem *sys, PVert *v, int aid)
static void p_chart_fill_boundary(ParamHandle *handle, PChart *chart, MutableSpan< PEdge * > border_edges, const float **co)
static void p_chart_extrema_verts(PChart *chart, PVert **pin1, PVert **pin2)
float pack_islands(Span< PackIsland * > islands, const UVPackIsland_Params ¶ms)
void uv_parametrizer_lscm_solve(ParamHandle *handle, int *count_changed, int *count_failed)
static void fix_large_angle(const float v_fix[3], const float v1[3], const float v2[3], double *r_fix, double *r_a1, double *r_a2)
static void p_chart_lscm_begin(PChart *chart, bool live, bool abf, const bool use_original_bounds)
@ PHANDLE_STATE_ALLOCATED
@ PHANDLE_STATE_CONSTRUCTED
static void p_chart_simplify_compute(PChart *chart, std::function< float(PEdge *, PEdge *)> collapse_cost_fn, std::function< float(PEdge *, PEdge *)> collapse_allowed_fn)
void uv_parametrizer_stretch_iter(ParamHandle *handle)
static void uv_parametrizer_scale_x(ParamHandle *phandle, const float scale_x)
void uv_parametrizer_slim_solve(ParamHandle *phandle, const ParamSlimOptions *slim_options, bool use_original_bounds, int *count_changed, int *count_failed)
static int p_face_exists(ParamHandle *handle, const ParamKey *pvkeys, int i1, int i2, int i3)
static void p_face_flip(PFace *f)
static void phash_insert(PHash *ph, PHashLink *link)
static float p_face_area(PFace *f)
void uv_parametrizer_original_bounds(ParamHandle *phandle)
static PVert * p_vert_lookup(ParamHandle *handle, PHashKey key, const float co[3], const float weight, PEdge *e)
static void p_chart_flush_collapsed_uvs(PChart *chart)
static void p_chart_orig_bounds_init(PChart *chart)
void uv_parametrizer_stretch_end(ParamHandle *handle)
static PEdge * p_boundary_edge_prev(PEdge *e)
static PHashLink * phash_next(PHash *ph, PHashKey key, PHashLink *link)
static void p_polygon_calc_tris(ParamHandle *handle, const float **co, uint(**r_tris)[3], uint nverts)
static float p_edge_uv_length(PEdge *e)
static void p_chart_boundaries(PChart *chart, PEdge **r_outer)
static int p_connect_pairs(ParamHandle *handle, bool topology_from_uvs)
static void p_chart_lscm_transform_single_pin(PChart *chart)
static bool p_validate_triangle_angles(const PVert *vert1, const PVert *vert2, const PVert *vert3, const float min_angle_cos)
void uv_parametrizer_face_add(ParamHandle *handle, const ParamKey key, const int nverts, const ParamKey *vkeys, const float **co, float **uv, const float *weight, const bool *pin, const bool *select)
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])
void void bool BLI_heap_is_empty(const Heap *heap) ATTR_NONNULL(1)
Heap * BLI_heap_new_ex(unsigned int reserve_num) ATTR_WARN_UNUSED_RESULT
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
GHash * BLI_ghash_int_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
HeapNode * BLI_heap_top(const Heap *heap) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
float angle_v2v2v2(const float a[2], const float b[2], const float c[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
void void BLI_heap_remove(Heap *heap, HeapNode *node) ATTR_NONNULL(1
float2 BLI_convexhull_aabb_fit_points_2d_as_sincos(Span< float2 > points)
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v2_v2(float r[2], const float a[2])
float angle_v3v3v3(const float a[3], const float b[3], const float c[3]) ATTR_WARN_UNUSED_RESULT
void mul_v2_m3v3(float r[2], const float M[3][3], const float a[3])
void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp) ATTR_NONNULL(1)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
void BLI_polyfill_calc_arena(const float(*coords)[2], unsigned int coords_num, int coords_sign, unsigned int(*r_tris)[3], struct MemArena *arena)
ATTR_WARN_UNUSED_RESULT const BMVert * v
struct RNG * BLI_rng_new(unsigned int seed)
void * BLI_heap_pop_min(Heap *heap) ATTR_NONNULL(1)
MINLINE void mul_v3_fl(float r[3], float f)
void BLI_ghash_insert(GHash *gh, void *key, void *val)
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE bool equals_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
VecBase< float, 2 > float2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2])
void BLI_memarena_clear(MemArena *ma) ATTR_NONNULL(1)
HeapNode * BLI_heap_insert(Heap *heap, float value, void *ptr) ATTR_NONNULL(1)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
MINLINE double max_dd(double a, double b)
void mul_m2_v2(const float mat[2][2], float vec[2])
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3(float r[3])
MINLINE bool equals_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
_W64 unsigned int uintptr_t
float BLI_rng_get_float(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_memarena_alloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
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])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3])
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
float area_tri_v3(const float v1[3], const float v2[3], const float v3[3])
void mid_v2_v2v2(float r[2], const float a[2], const float b[2])
Heap * BLI_heap_new() ATTR_WARN_UNUSED_RESULT
float volume_tri_tetrahedron_signed_v3(const float v1[3], const float v2[3], const float v3[3])
VecBase< float, 3 > float3
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
bool invert_m2_m2(float inverse[2][2], const float mat[2][2])
MINLINE float safe_divide(float a, float b)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void * BLI_memarena_calloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
float cos_v3v3v3(const float p1[3], const float p2[3], const float p3[3]) ATTR_WARN_UNUSED_RESULT
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void BLI_polyfill_beautify(const float(*coords)[2], unsigned int coords_num, unsigned int(*tris)[3], struct MemArena *arena, struct Heap *eheap)
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
void axis_dominant_v3_to_m3_negate(float r_mat[3][3], const float normal[3])
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
MINLINE float clamp_f(float value, float min, float max)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
Array< float > lambdaLength
Array< float > lambdaTriangle
Array< float > lambdaPlanar
PChartOrigBounds * orig_bounds
union blender::geometry::PEdge::PEdgeUnion u
union blender::geometry::PFace::PFaceUnion u
union blender::geometry::PVert::PVertUnion u
std::vector< float > w_vectors
std::vector< double > el_vectors
std::vector< int > p_matrices
std::vector< double > v_matrices
int boundary_vertices_num
std::vector< double > uv_matrices
std::vector< int > e_matrices
std::vector< double > pp_matrices
std::vector< int > b_vectors
std::vector< int > f_matrices
void setup_slim_data(MatrixTransferChart &chart) const
std::vector< MatrixTransferChart > charts
PinnedVertexData pinned_vertex_data
void parametrize_live(MatrixTransferChart &chart, const PinnedVertexData &pinned_vertex_data)
std::vector< int > selected_pins
std::vector< int > pinned_vertex_indices
std::vector< double > pinned_vertex_positions_2D
#define UNUSED_FUNCTION_NO_SLIM
#define PHASH_hash(ph, item)
#define PHASH_edge(v1, v2)
#define PEDGE_VERTEX_FLAGS
#define param_warning(message)