From f35d719e1ac5a1b460b36dddac2341620a67ec7b Mon Sep 17 00:00:00 2001 From: franMarz <58062362+franMarz@users.noreply.github.com> Date: Tue, 24 Nov 2020 21:21:38 +0100 Subject: [PATCH] Align world and edge updated again Further versioning around transform.rotate silly convention changes. Now, these align tools should work equally on versions 2.90 and 2.91. --- op_island_align_edge.py | 8 ++++---- op_island_align_world.py | 16 +++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/op_island_align_edge.py b/op_island_align_edge.py index 1e6c7ad..8c75a60 100644 --- a/op_island_align_edge.py +++ b/op_island_align_edge.py @@ -127,11 +127,11 @@ def align_island(uv_vert0, uv_vert1, faces): diff = uv_vert1 - uv_vert0 current_angle = math.atan2(diff.x, diff.y) - angle_to_rotate = round(current_angle / (math.pi/2)) * (math.pi/2) - current_angle + angle_to_rotate = - round(current_angle / (math.pi/2)) * (math.pi/2) + current_angle - # For some reason bpy.ops.transform.rotate rotates in the opposite - # direction in Blender 2.83 than in other versions. - if float(bpy.app.version_string[0:4]) == 2.83: + # For some reason, bpy.ops.transform.rotate behaves differently based on the version of Blender. + bversion = float(bpy.app.version_string[0:4]) + if bversion == 2.80 or bversion == 2.81 or bversion == 2.82 or bversion == 2.90: angle_to_rotate = -angle_to_rotate bpy.ops.uv.select_linked() diff --git a/op_island_align_world.py b/op_island_align_world.py index d98744f..ea5f9d4 100644 --- a/op_island_align_world.py +++ b/op_island_align_world.py @@ -199,9 +199,10 @@ def align_island(obj, bm, uv_layers, faces, x=0, y=1, flip_x=False, flip_y=False avg_angle /= n_edges - # For some reason, bpy.ops.transform.rotate rotates in the opposite direction in Blender 2.83 compared to other versions. - if float(bpy.app.version_string[0:4]) == 2.83: - avg_angle = -avg_angle + # bpy.ops.transform.rotate behaves differently based on the version of Blender on the UV Editor. Not expected to be fixed for every version of master + bversion = float(bpy.app.version_string[0:4]) + if bversion == 2.80 or bversion == 2.81 or bversion == 2.82 or bversion == 2.90: + avg_angle = -avg_angle print("Edges {}x".format(n_edges)) print("Turn {:.1f}".format(avg_angle * 180/math.pi)) @@ -212,7 +213,7 @@ def align_island(obj, bm, uv_layers, faces, x=0, y=1, flip_x=False, flip_y=False loop[uv_layers].select = True bpy.context.tool_settings.transform_pivot_point = 'MEDIAN_POINT' - bpy.ops.transform.rotate(value=-avg_angle, orient_axis='Z', constraint_axis=(False, False, False), orient_type='GLOBAL', mirror=False, use_proportional_edit=False) + bpy.ops.transform.rotate(value=avg_angle, orient_axis='Z', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, False, False), mirror=False, use_proportional_edit=False) def align_island_simple(obj, bm, uv_layers, faces, x=0, y=1, flip_x=False, flip_y=False): @@ -262,8 +263,9 @@ def align_island_simple(obj, bm, uv_layers, faces, x=0, y=1, flip_x=False, flip_ a_delta = math.atan2(math.sin(a0-a1), math.cos(a0-a1)) - # For some reason, bpy.ops.transform.rotate rotates in the opposite direction in Blender 2.83 compared to other versions. - if float(bpy.app.version_string[0:4]) == 2.83: + # bpy.ops.transform.rotate behaves differently based on the version of Blender on the UV Editor. Not expected to be fixed for every version of master + bversion = float(bpy.app.version_string[0:4]) + if bversion == 2.80 or bversion == 2.81 or bversion == 2.82 or bversion == 2.90: a_delta = -a_delta print("Turn {:.1f}".format(a_delta * 180/math.pi)) @@ -274,7 +276,7 @@ def align_island_simple(obj, bm, uv_layers, faces, x=0, y=1, flip_x=False, flip_ loop[uv_layers].select = True bpy.context.tool_settings.transform_pivot_point = 'MEDIAN_POINT' - bpy.ops.transform.rotate(value=-a_delta, orient_axis='Z', constraint_axis=(False, False, False), orient_type='GLOBAL', mirror=False, use_proportional_edit=False) + bpy.ops.transform.rotate(value=a_delta, orient_axis='Z', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, False, False), mirror=False, use_proportional_edit=False) bpy.utils.register_class(op)