562 const Span<std::unique_ptr<UVAABBIsland>> islands,
563 const float target_aspect_y,
568 float next_u1 = exclude.
xmax;
569 float next_v1 = exclude.
ymax;
570 bool zigzag = next_u1 / target_aspect_y < next_v1;
574 float2 hole_diagonal(0.0f);
575 bool hole_rotate =
false;
577 float u0 = zigzag ? next_u1 : 0.0f;
578 float v0 = zigzag ? 0.0f : next_v1;
581 for (
int64_t index = exclude_index; index < islands.size(); index++) {
585 float min_dsm = std::min(uvdiag_x, island.
uv_diagonal.y);
586 float max_dsm = std::max(uvdiag_x, island.
uv_diagonal.y);
588 if (min_dsm < hole_diagonal.x && max_dsm < hole_diagonal.y) {
590 if (hole_rotate == (min_dsm == island.
uv_diagonal.x)) {
597 phi.translation.x = hole[0] + island.
uv_diagonal.x * 0.5f;
598 phi.translation.y = hole[1] + island.
uv_diagonal.y * 0.5f;
605 p[2] = hole[0] + (hole_rotate ? max_dsm : min_dsm) / island.
aspect_y;
606 p[3] = hole[1] + (hole_rotate ? min_dsm : max_dsm);
607 p[4] = hole[0] + (hole_rotate ? hole_diagonal.y : hole_diagonal.x);
608 p[5] = hole[1] + (hole_rotate ? hole_diagonal.x : hole_diagonal.y);
617 bool restart =
false;
619 restart = (next_v1 < v0 + min_dsm);
622 restart = (next_u1 < u0 + min_dsm / island.
aspect_y);
627 zigzag = next_u1 / target_aspect_y < next_v1;
628 u0 = zigzag ? next_u1 : 0.0f;
629 v0 = zigzag ? 0.0f : next_v1;
633 if (zigzag == (min_dsm == uvdiag_x)) {
640 phi.translation.x = u0 + island.
uv_diagonal.x * 0.5f;
641 phi.translation.y = v0 + island.
uv_diagonal.y * 0.5f;
649 next_v1 =
max_ff(next_v1, v0);
654 next_v1 =
max_ff(next_v1, v0 + max_dsm);
655 next_u1 =
max_ff(next_u1, u0);
660 *r_extent = {0.0f, next_u1, 0.0f, next_v1};
757 if (
params.target_aspect_y != 1.0f) {
764 float large_uv = 0.0f;
765 for (
const int64_t i : aabbs.index_range()) {
766 large_uv =
max_ff(large_uv, aabbs[
i]->uv_diagonal.x);
767 large_uv =
max_ff(large_uv, aabbs[
i]->uv_diagonal.y);
770 int64_t island_count_patch = aabbs.size();
772 const float opt_11[] = {
774 2.6238700165660708840676f,
775 2.4365065643739085565755f,
776 0.70130710554829878145f,
777 1.9596047386700836678841f,
778 1.6885655318806973568257f,
779 0.70130710554829878145f,
780 1.9364970731945949644626f,
781 3.1724566890997589752033f,
782 0.70130710554829878145f,
783 1.2722458068219282267819f,
784 2.4245322476118422727609f,
785 0.70130710554829878145f,
786 3.1724918301381124230431f,
787 1.536261617698265524723f,
788 0.70130710554829878145f,
789 3.3770999999999999907629f,
790 3.3770999999999999907629f,
795 2.5325444557069398676674f,
799 3.3770999999999999907629f,
809 3.8770999999999999907629f,
811 "Walter Trump, 1979",
819 const float opt_18[] = {
821 2.4700161985907582717914f,
822 2.4335783708246112588824f,
823 0.42403103949074028022892f,
824 1.3528594569415370862941f,
825 2.3892972847076845432923f,
826 0.42403103949074028022892f,
827 2.0585783708246108147932f,
828 1.5221405430584633577951f,
829 0.42403103949074028022892f,
830 1.7642972847076845432923f,
831 3.3007351124738324443797f,
832 0.42403103949074028022892f,
833 3.3228756555322949139963f,
836 3.3228756555322949139963f,
837 3.3228756555322949139963f,
842 2.3228756555322949139963f,
843 4.3228756555322949139963f,
846 3.3228756555322949139963f,
851 3.3228756555322949139963f,
854 3.3228756555322949139963f,
855 4.3228756555322949139963f,
857 4.3228756555322949139963f,
860 4.3228756555322949139963f,
861 3.3228756555322949139963f,
867 4.3228756555322949139963f,
869 4.3228756555322949139963f,
872 4.3228756555322949139963f,
873 4.3228756555322949139963f,
877 4.8228756555322949139963f,
879 "Pertti Hamalainen, 1979",
887 const float opt_19[] = {
889 2.1785113019775792508881f,
890 1.9428090415820631342569f,
891 0.78539816339744827899949f,
892 1.4714045207910317891731f,
893 2.6499158227686105959719f,
894 0.78539816339744827899949f,
895 2.9428090415820640224354f,
896 2.7071067811865479058042f,
897 0.78539816339744827899949f,
898 2.2357022603955165607204f,
899 3.4142135623730953675192f,
900 0.78539816339744827899949f,
901 1.4428090415820635783462f,
902 1.2642977396044836613243f,
903 0.78539816339744827899949f,
904 3.3856180831641271566923f,
907 0.73570226039551600560884f,
908 1.9714045207910311230393f,
909 0.78539816339744827899949f,
910 3.6213203435596432733234f,
911 3.4428090415820635783462f,
912 0.78539816339744827899949f,
913 2.9142135623730958116084f,
914 4.1499158227686105959719f,
915 0.78539816339744827899949f,
916 2.3856180831641271566923f,
920 3.3856180831641271566923f,
923 4.3856180831641271566923f,
925 4.3856180831641271566923f,
928 3.3856180831641271566923f,
931 4.3856180831641271566923f,
938 4.3856180831641271566923f,
940 4.3856180831641271566923f,
943 4.3856180831641271566923f,
944 4.3856180831641271566923f,
948 4.8856180831641271566923f,
950 "Robert Wainwright, 1979",
958 const float opt_26[] = {
960 2.3106601717798209705279f,
961 2.8106601717798214146171f,
962 0.78539816339744827899949f,
963 1.6035533905932735088129f,
964 2.1035533905932739529021f,
965 0.78539816339744827899949f,
966 3.0177669529663684322429f,
967 2.1035533905932739529021f,
968 0.78539816339744827899949f,
969 2.3106601717798209705279f,
970 1.3964466094067264911871f,
971 0.78539816339744827899949f,
972 1.6035533905932735088129f,
973 3.5177669529663688763321f,
974 0.78539816339744827899949f,
975 0.89644660940672593607559f,
976 2.8106601717798214146171f,
977 0.78539816339744827899949f,
978 3.0177669529663684322429f,
979 3.5177669529663688763321f,
980 0.78539816339744827899949f,
981 3.7248737341529158939579f,
982 2.8106601717798214146171f,
983 0.78539816339744827899949f,
984 2.3106601717798209705279f,
985 4.2248737341529167821363f,
986 0.78539816339744827899949f,
993 3.1213203435596419410558f,
996 4.1213203435596419410558f,
1000 4.1213203435596419410558f,
1005 4.1213203435596419410558f,
1006 4.1213203435596419410558f,
1008 4.1213203435596419410558f,
1012 5.1213203435596419410558f,
1014 3.1213203435596419410558f,
1015 5.1213203435596419410558f,
1017 5.1213203435596419410558f,
1020 5.1213203435596419410558f,
1024 5.1213203435596419410558f,
1026 4.1213203435596419410558f,
1027 5.1213203435596419410558f,
1029 5.1213203435596419410558f,
1030 4.1213203435596419410558f,
1032 5.1213203435596419410558f,
1035 5.1213203435596419410558f,
1036 5.1213203435596419410558f,
1040 5.6213203435596419410558f,
1042 "Erich Friedman, 1997",
1050 if (island_count_patch == 37) {
1051 island_count_patch = 38;
1053 if (island_count_patch == 50) {
1054 island_count_patch = 52;
1056 if (island_count_patch == 51) {
1057 island_count_patch = 52;
1059 if (island_count_patch == 65) {
1060 island_count_patch = 67;
1062 if (island_count_patch == 66) {
1063 island_count_patch = 67;
1067 for (
int a = 1; a < 20; a++) {
1068 int n = a * a + a + 3 +
floorf((a - 1) *
sqrtf(2.0f));
1069 if (island_count_patch == n) {
1070 float max_uv_gobel = large_uv * (a + 1 +
sqrtf(0.5f));
1071 rctf extent = {0.0f, max_uv_gobel, 0.0f, max_uv_gobel};
1825 float island_scale = scale;
1827 island_scale = 1.0f;
1829 std::unique_ptr<UVAABBIsland> aabb = std::make_unique<UVAABBIsland>();
1831 aabb->uv_diagonal.x = pack_island->
half_diagonal_.x * 2 * island_scale + 2 * margin;
1832 aabb->uv_diagonal.y = pack_island->
half_diagonal_.y * 2 * island_scale + 2 * margin;
1833 aabb->aspect_y = pack_island->
aspect_y;
1834 aabbs[
i] = std::move(aabb);
1839 if (all_can_rotate) {
1843 [&](
const std::unique_ptr<UVAABBIsland> &a,
const std::unique_ptr<UVAABBIsland> &
b) {
1844 const bool can_translate_a = islands[a->index]->can_translate_(params);
1845 const bool can_translate_b = islands[b->index]->can_translate_(params);
1846 if (can_translate_a != can_translate_b) {
1847 return can_translate_b;
1852 float a_u = a->uv_diagonal.x * a->aspect_y;
1853 float a_v = a->uv_diagonal.y;
1854 float b_u =
b->uv_diagonal.x *
b->aspect_y;
1855 float b_v =
b->uv_diagonal.y;
1857 std::swap(a_u, a_v);
1860 std::swap(b_u, b_v);
1862 float diff_u = a_u - b_u;
1863 float diff_v = a_v - b_v;
1864 diff_v += diff_u * 0.05f;
1865 if (diff_v == 0.0f) {
1866 return diff_u > 0.0f;
1868 return diff_v > 0.0f;
1875 [&](
const std::unique_ptr<UVAABBIsland> &a,
const std::unique_ptr<UVAABBIsland> &
b) {
1876 const bool can_translate_a = islands[a->index]->can_translate_(params);
1877 const bool can_translate_b = islands[b->index]->can_translate_(params);
1878 if (can_translate_a != can_translate_b) {
1879 return can_translate_b;
1883 return b->uv_diagonal.x *
b->uv_diagonal.y < a->uv_diagonal.x * a->uv_diagonal.y;
1888 rctf locked_bounds = {0.0f};
1889 int64_t locked_island_count = 0;
1890 for (
int64_t i = 0;
i < islands.size();
i++) {
1891 PackIsland *pack_island = islands[aabbs[
i]->index];
1892 if (pack_island->can_translate_(
params)) {
1895 float2 bottom_left = pack_island->pivot_ - pack_island->half_diagonal_;
1896 float2 top_right = pack_island->pivot_ + pack_island->half_diagonal_;
1898 locked_bounds.
xmin = bottom_left.
x;
1899 locked_bounds.
xmax = top_right.
x;
1900 locked_bounds.
ymin = bottom_left.
y;
1901 locked_bounds.
ymax = top_right.
y;
1908 UVPhi &
phi = r_phis[aabbs[
i]->index];
1909 phi.translation = pack_island->pivot_;
1911 phi.rotation = 0.0f;
1913 locked_island_count =
i + 1;
1919 int64_t alpaca_cutoff_fast = 81;
1921 if (margin > 0.0f) {
1922 alpaca_cutoff = alpaca_cutoff_fast;
1926 alpaca_cutoff = std::max(alpaca_cutoff, locked_island_count);
1929 std::min(alpaca_cutoff, islands.size()));
1930 rctf extent = {0.0f, 1e30f, 0.0f, 1e30f};
1940 rctf fast_extent = extent;
1943 if (locked_island_count == 0) {
1948 if (locked_island_count == 0) {
1954 slow_aabbs, islands, scale, margin,
params, r_phis, &extent);
1956 slow_aabbs = aabbs.as_span().
take_front(max_xatlas);
1964 if (all_can_rotate && aabbs.size() > slow_aabbs.
size()) {
1970 slow_aabbs = slow_aabbs.
take_front(locked_island_count);
1971 extent = locked_bounds;
1975 rctf final_extent = {0.0f, 1e30f, 0.0f, 1e30f};