1
1

Cleanup: Simplify uv packing engine

Migrating to use uv_phi[] for placement.
This commit is contained in:
2023-04-13 09:56:41 +12:00
parent 5ba30e07f2
commit d48939f103

View File

@@ -216,10 +216,9 @@ UVPackIsland_Params::UVPackIsland_Params()
/* Compact representation for AABB packers. */
class UVAABBIsland {
public:
uv_phi phi;
float2 uv_diagonal;
float2 uv_placement;
int64_t index;
float angle;
float aspect_y;
};
@@ -267,8 +266,8 @@ static void pack_islands_alpaca_turbo(const Span<UVAABBIsland *> islands,
}
/* Place the island. */
island->uv_placement.x = u0 + dsm_u * 0.5f;
island->uv_placement.y = v0 + dsm_v * 0.5f;
island->phi.translation.x = u0 + dsm_u * 0.5f;
island->phi.translation.y = v0 + dsm_v * 0.5f;
if (zigzag) {
/* Move upwards. */
v0 += dsm_v;
@@ -367,17 +366,15 @@ static void pack_islands_alpaca_rotate(const Span<UVAABBIsland *> islands,
if (min_dsm < hole_diagonal.x && max_dsm < hole_diagonal.y) {
/* Place island in the hole. */
island->uv_placement.x = hole[0];
island->uv_placement.y = hole[1];
if (hole_rotate == (min_dsm == island->uv_diagonal.x)) {
island->angle = DEG2RADF(90.0f);
island->uv_placement.x += island->uv_diagonal.y * 0.5f / island->aspect_y;
island->uv_placement.y += island->uv_diagonal.x * 0.5f * island->aspect_y;
island->phi.rotation = DEG2RADF(90.0f);
island->phi.translation.x = hole[0] + island->uv_diagonal.y * 0.5f / island->aspect_y;
island->phi.translation.y = hole[1] + island->uv_diagonal.x * 0.5f * island->aspect_y;
}
else {
island->angle = 0.0f;
island->uv_placement.x += island->uv_diagonal.x * 0.5f;
island->uv_placement.y += island->uv_diagonal.y * 0.5f;
island->phi.rotation = 0.0f;
island->phi.translation.x = hole[0] + island->uv_diagonal.x * 0.5f;
island->phi.translation.y = hole[1] + island->uv_diagonal.y * 0.5f;
}
/* Update space left in the hole. */
@@ -412,17 +409,15 @@ static void pack_islands_alpaca_rotate(const Span<UVAABBIsland *> islands,
}
/* Place the island. */
island->uv_placement.x = u0;
island->uv_placement.y = v0;
if (zigzag == (min_dsm == uvdiag_x)) {
island->angle = DEG2RADF(90.0f);
island->uv_placement.x += island->uv_diagonal.y * 0.5f / island->aspect_y;
island->uv_placement.y += island->uv_diagonal.x * 0.5f * island->aspect_y;
island->phi.rotation = DEG2RADF(90.0f);
island->phi.translation.x = u0 + island->uv_diagonal.y * 0.5f / island->aspect_y;
island->phi.translation.y = v0 + island->uv_diagonal.x * 0.5f * island->aspect_y;
}
else {
island->angle = 0.0f;
island->uv_placement.x += island->uv_diagonal.x * 0.5f;
island->uv_placement.y += island->uv_diagonal.y * 0.5f;
island->phi.rotation = 0.0f;
island->phi.translation.x = u0 + island->uv_diagonal.x * 0.5f;
island->phi.translation.y = v0 + island->uv_diagonal.y * 0.5f;
}
/* Move according to the "Alpaca rules", with rotation. */
@@ -986,12 +981,7 @@ static float pack_islands_scale_margin(const Span<PackIsland *> islands,
/* Write back Alpaca UVs. */
for (int64_t i = max_box_pack; i < aabbs.size(); i++) {
UVAABBIsland *aabb = aabbs[i];
PackIsland *pack_island = islands[aabb->index];
pack_island->angle = aabb->angle;
float matrix_inverse[2][2];
pack_island->build_inverse_transformation(scale, pack_island->angle, matrix_inverse);
mul_v2_m2v2(pack_island->pre_translate, matrix_inverse, aabb->uv_placement);
pack_island->pre_translate -= pack_island->pivot_;
islands[aabb->index]->place_(scale, aabb->phi);
}
/* Memory management. */