[Bf-blender-cvs] [d0010d48c7f] master: Cleanup: add ED_uvedit_get_aspect_y utility function
Campbell Barton
noreply at git.blender.org
Fri Jan 20 04:04:57 CET 2023
Commit: d0010d48c7f4edff2fdc0591d71c832c9d546964
Author: Campbell Barton
Date: Fri Jan 20 13:12:28 2023 +1100
Branches: master
https://developer.blender.org/rBd0010d48c7f4edff2fdc0591d71c832c9d546964
Cleanup: add ED_uvedit_get_aspect_y utility function
This avoids having to perform the aspect division inline.
===================================================================
M source/blender/editors/include/ED_uvedit.h
M source/blender/editors/uvedit/uvedit_islands.cc
M source/blender/editors/uvedit/uvedit_path.c
M source/blender/editors/uvedit/uvedit_smart_stitch.c
M source/blender/editors/uvedit/uvedit_unwrap_ops.c
===================================================================
diff --git a/source/blender/editors/include/ED_uvedit.h b/source/blender/editors/include/ED_uvedit.h
index 7aa745abdf6..349975e1181 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -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,
diff --git a/source/blender/editors/uvedit/uvedit_islands.cc b/source/blender/editors/uvedit/uvedit_islands.cc
index ed0e4933965..ad4527affb8 100644
--- a/source/blender/editors/uvedit/uvedit_islands.cc
+++ b/source/blender/editors/uvedit/uvedit_islands.cc
@@ -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;
diff --git a/source/blender/editors/uvedit/uvedit_path.c b/source/blender/editors/uvedit/uvedit_path.c
index 1e50ddba3a3..e8ba3b0cffd 100644
--- a/source/blender/editors/uvedit/uvedit_path.c
+++ b/source/blender/editors/uvedit/uvedit_path.c
@@ -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;
diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c
index e6d895bd826..7a05ffafbcb 100644
--- a/source/blender/editors/uvedit/uvedit_smart_stitch.c
+++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c
@@ -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;
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 1ab398c185c..e5b3d8998c0 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -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;
More information about the Bf-blender-cvs
mailing list