Cleanup: add ED_uvedit_get_aspect_y utility function
This avoids having to perform the aspect division inline.
This commit is contained in:
parent
a0706d6cf0
commit
d0010d48c7
|
@ -273,6 +273,13 @@ struct BMLoop **ED_uvedit_selected_verts(const struct Scene *scene,
|
|||
int *r_verts_len);
|
||||
|
||||
void ED_uvedit_get_aspect(struct Object *obedit, float *r_aspx, float *r_aspy);
|
||||
|
||||
/**
|
||||
* Return the X / Y aspect (wider aspects are over 1, taller are below 1).
|
||||
* Apply this aspect by multiplying with the Y axis (X aspect is always 1 & unchanged).
|
||||
*/
|
||||
float ED_uvedit_get_aspect_y(struct Object *obedit);
|
||||
|
||||
void ED_uvedit_get_aspect_from_material(Object *ob,
|
||||
const int material_index,
|
||||
float *r_aspx,
|
||||
|
|
|
@ -675,14 +675,7 @@ void ED_uvedit_pack_islands_multi(const Scene *scene,
|
|||
continue;
|
||||
}
|
||||
|
||||
float aspect_y = 1.0f;
|
||||
if (params->correct_aspect) {
|
||||
float aspx, aspy;
|
||||
ED_uvedit_get_aspect(obedit, &aspx, &aspy);
|
||||
if (aspx != aspy) {
|
||||
aspect_y = aspx / aspy;
|
||||
}
|
||||
}
|
||||
const float aspect_y = params->correct_aspect ? ED_uvedit_get_aspect_y(obedit) : 1.0f;
|
||||
|
||||
bool only_selected_faces = params->only_selected_faces;
|
||||
bool only_selected_uvs = params->only_selected_uvs;
|
||||
|
|
|
@ -653,13 +653,7 @@ static int uv_shortest_path_pick_invoke(bContext *C, wmOperator *op, const wmEve
|
|||
|
||||
if (ele_src && ele_dst) {
|
||||
/* Always use the active object, not `obedit` as the active defines the UV display. */
|
||||
float aspect_y;
|
||||
{
|
||||
float aspx, aspy;
|
||||
ED_uvedit_get_aspect(CTX_data_edit_object(C), &aspx, &aspy);
|
||||
aspect_y = aspx / aspy;
|
||||
}
|
||||
|
||||
const float aspect_y = ED_uvedit_get_aspect_y(CTX_data_edit_object(C));
|
||||
uv_shortest_path_pick_ex(
|
||||
scene, depsgraph, obedit, &op_params, ele_src, ele_dst, aspect_y, offsets);
|
||||
|
||||
|
@ -744,12 +738,7 @@ static int uv_shortest_path_pick_exec(bContext *C, wmOperator *op)
|
|||
}
|
||||
|
||||
/* Always use the active object, not `obedit` as the active defines the UV display. */
|
||||
float aspect_y;
|
||||
{
|
||||
float aspx, aspy;
|
||||
ED_uvedit_get_aspect(CTX_data_edit_object(C), &aspx, &aspy);
|
||||
aspect_y = aspx / aspy;
|
||||
}
|
||||
const float aspect_y = ED_uvedit_get_aspect_y(CTX_data_edit_object(C));
|
||||
|
||||
struct PathSelectParams op_params;
|
||||
path_select_params_from_op(op, &op_params);
|
||||
|
@ -803,13 +792,7 @@ static int uv_shortest_path_select_exec(bContext *C, wmOperator *op)
|
|||
const char uv_selectmode = ED_uvedit_select_mode_get(scene);
|
||||
bool found_valid_elements = false;
|
||||
|
||||
float aspect_y;
|
||||
{
|
||||
Object *obedit = CTX_data_edit_object(C);
|
||||
float aspx, aspy;
|
||||
ED_uvedit_get_aspect(obedit, &aspx, &aspy);
|
||||
aspect_y = aspx / aspy;
|
||||
}
|
||||
const float aspect_y = ED_uvedit_get_aspect_y(CTX_data_edit_object(C));
|
||||
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
uint objects_len = 0;
|
||||
|
|
|
@ -130,6 +130,7 @@ typedef struct UvEdge {
|
|||
|
||||
/* stitch state object */
|
||||
typedef struct StitchState {
|
||||
/** The `aspect[0] / aspect[1]`. */
|
||||
float aspect;
|
||||
/* object for editmesh */
|
||||
Object *obedit;
|
||||
|
@ -1827,7 +1828,6 @@ static StitchState *stitch_init(bContext *C,
|
|||
StitchState *state;
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
float aspx, aspy;
|
||||
|
||||
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
||||
const BMUVOffsets offsets = BM_uv_map_get_offsets(em->bm);
|
||||
|
@ -1850,8 +1850,7 @@ static StitchState *stitch_init(bContext *C,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ED_uvedit_get_aspect(obedit, &aspx, &aspy);
|
||||
state->aspect = aspx / aspy;
|
||||
state->aspect = ED_uvedit_get_aspect_y(obedit);
|
||||
|
||||
int unique_uvs = state->element_map->total_unique_uvs;
|
||||
state->total_separate_uvs = unique_uvs;
|
||||
|
|
|
@ -281,6 +281,13 @@ void ED_uvedit_get_aspect(Object *ob, float *r_aspx, float *r_aspy)
|
|||
ED_uvedit_get_aspect_from_material(ob, efa->mat_nr, r_aspx, r_aspy);
|
||||
}
|
||||
|
||||
float ED_uvedit_get_aspect_y(Object *ob)
|
||||
{
|
||||
float aspect[2];
|
||||
ED_uvedit_get_aspect(ob, &aspect[0], &aspect[1]);
|
||||
return aspect[0] / aspect[1];
|
||||
}
|
||||
|
||||
static bool uvedit_is_face_affected(const Scene *scene,
|
||||
BMFace *efa,
|
||||
const UnwrapOptions *options,
|
||||
|
@ -1548,9 +1555,7 @@ static void shrink_loop_uv_by_aspect_ratio(BMFace *efa,
|
|||
static void correct_uv_aspect(Object *ob, BMEditMesh *em)
|
||||
{
|
||||
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_PROP_FLOAT2);
|
||||
float aspx, aspy;
|
||||
ED_uvedit_get_aspect(ob, &aspx, &aspy);
|
||||
const float aspect_y = aspx / aspy;
|
||||
const float aspect_y = ED_uvedit_get_aspect_y(ob);
|
||||
if (aspect_y == 1.0f) {
|
||||
/* Scaling by 1.0 has no effect. */
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue