diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2012-12-27 06:52:45 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2012-12-27 06:52:45 +0400 |
commit | 540cbbc1d0bc4fcb84e35dcd3991f7ef9e9a10a1 (patch) | |
tree | 1924e5e37f906ed1d9f356d012cd5c4575c8a8d0 /source/blender/editors/uvedit/uvedit_smart_stitch.c | |
parent | 84361f602a98d2ac35c6cc81eb897d593977e743 (diff) |
Fix: rotation of uv islands during stitch did not take uv aspect ratio
of image into account, distorting the islands. Now properly scale the
components before rotating the island.
Diffstat (limited to 'source/blender/editors/uvedit/uvedit_smart_stitch.c')
-rw-r--r-- | source/blender/editors/uvedit/uvedit_smart_stitch.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c index bd50857c8b8..bc2d0e493f4 100644 --- a/source/blender/editors/uvedit/uvedit_smart_stitch.c +++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c @@ -136,6 +136,7 @@ typedef struct UvEdge { /* stitch state object */ typedef struct StitchState { + float aspect; /* use limit flag */ char use_limit; /* limit to operator, same as original operator */ @@ -285,10 +286,12 @@ static int getNumOfIslandUvs(UvElementMap *elementMap, int island) } } -static void stitch_uv_rotate(float rotation, float medianPoint[2], float uv[2]) +static void stitch_uv_rotate(float rotation, float medianPoint[2], float uv[2], float aspect) { float uv_rotation_result[2]; + uv[1] /= aspect; + uv[0] -= medianPoint[0]; uv[1] -= medianPoint[1]; @@ -297,6 +300,8 @@ static void stitch_uv_rotate(float rotation, float medianPoint[2], float uv[2]) uv[0] = uv_rotation_result[0] + medianPoint[0]; uv[1] = uv_rotation_result[1] + medianPoint[1]; + + uv[1] *= aspect; } /* check if two uvelements are stitchable. This should only operate on -different- separate UvElements */ @@ -413,9 +418,11 @@ static void stitch_calculate_island_snapping(StitchState *state, PreviewPosition island_stitch_data[i].rotation /= island_stitch_data[i].num_rot_elements; island_stitch_data[i].medianPoint[0] /= island_stitch_data[i].numOfElements; island_stitch_data[i].medianPoint[1] /= island_stitch_data[i].numOfElements; + island_stitch_data[i].medianPoint[1] /= state->aspect; } island_stitch_data[i].translation[0] /= island_stitch_data[i].numOfElements; island_stitch_data[i].translation[1] /= island_stitch_data[i].numOfElements; + numOfIslandUVs = getNumOfIslandUvs(state->element_map, i); element = &state->element_map->buf[state->element_map->islandIndices[i]]; for (j = 0; j < numOfIslandUVs; j++, element++) { @@ -429,7 +436,7 @@ static void stitch_calculate_island_snapping(StitchState *state, PreviewPosition if (final) { - stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, luv->uv); + stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, luv->uv, state->aspect); add_v2_v2(luv->uv, island_stitch_data[i].translation); } @@ -438,7 +445,7 @@ static void stitch_calculate_island_snapping(StitchState *state, PreviewPosition int face_preview_pos = preview_position[BM_elem_index_get(element->l->f)].data_position; stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, - preview->preview_polys + face_preview_pos + 2 * element->tfindex); + preview->preview_polys + face_preview_pos + 2 * element->tfindex, state->aspect); add_v2_v2(preview->preview_polys + face_preview_pos + 2 * element->tfindex, island_stitch_data[i].translation); @@ -1541,7 +1548,7 @@ static int stitch_init(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; ARegion *ar = CTX_wm_region(C); - + float aspx, aspy; Object *obedit = CTX_data_edit_object(C); if (!ar) @@ -1595,6 +1602,9 @@ static int stitch_init(bContext *C, wmOperator *op) return 0; } + uvedit_get_aspect(scene, obedit, em, &aspx, &aspy); + state->aspect = aspx/aspy; + /* Entirely possible if redoing last operator that static island is bigger than total number of islands. * This ensures we get no hang in the island checking code in stitch_stitch_process_data. */ state->static_island %= state->element_map->totalIslands; |