2019-06-08 23:42:50 +00:00
|
|
|
import bpy
|
|
|
|
import bmesh
|
|
|
|
import operator
|
|
|
|
import math
|
|
|
|
from mathutils import Vector
|
|
|
|
from collections import defaultdict
|
|
|
|
from math import pi
|
|
|
|
|
|
|
|
from . import utilities_uv
|
|
|
|
|
|
|
|
class op(bpy.types.Operator):
|
2019-12-18 20:53:16 +00:00
|
|
|
bl_idname = "uv.textools_island_rotate_90"
|
|
|
|
bl_label = "Rotate 90 degrees"
|
|
|
|
bl_description = "Rotate the selected UV island 90 degrees left or right"
|
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
|
|
|
|
|
|
|
angle : bpy.props.FloatProperty(name="Angle")
|
2019-06-08 23:42:50 +00:00
|
|
|
|
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
#Only in UV editor mode
|
|
|
|
if bpy.context.area.type != 'IMAGE_EDITOR':
|
|
|
|
return False
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
if not bpy.context.active_object:
|
|
|
|
return False
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
if bpy.context.active_object.type != 'MESH':
|
|
|
|
return False
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
#Only in Edit mode
|
|
|
|
if bpy.context.active_object.mode != 'EDIT':
|
|
|
|
return False
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
#Requires UV map
|
|
|
|
if not bpy.context.object.data.uv_layers:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Not in Synced mode
|
|
|
|
if bpy.context.scene.tool_settings.use_uv_select_sync:
|
|
|
|
return False
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
return True
|
2019-06-08 23:42:50 +00:00
|
|
|
|
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
def execute(self, context):
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
main(context, self.angle)
|
|
|
|
return {'FINISHED'}
|
2019-06-08 23:42:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main(context, angle):
|
2019-12-18 20:53:16 +00:00
|
|
|
|
|
|
|
#Store selection
|
|
|
|
utilities_uv.selection_store()
|
|
|
|
|
|
|
|
bm = bmesh.from_edit_mesh(bpy.context.active_object.data)
|
|
|
|
uv_layers = bm.loops.layers.uv.verify()
|
|
|
|
|
|
|
|
bpy.ops.uv.select_linked()
|
|
|
|
|
|
|
|
#Bounds
|
|
|
|
bounds_initial = utilities_uv.getSelectionBBox()
|
|
|
|
bpy.ops.transform.rotate(value=angle, orient_axis='Z', constraint_axis=(False, False, False), use_proportional_edit=False)
|
|
|
|
|
|
|
|
#Align rotation to top left|right
|
|
|
|
bounds_post = utilities_uv.getSelectionBBox()
|
|
|
|
dy = bounds_post['max'].y - bounds_initial['max'].y
|
|
|
|
dx = 0
|
|
|
|
if angle > 0:
|
|
|
|
dx = bounds_post['max'].x - bounds_initial['max'].x
|
|
|
|
else:
|
|
|
|
dx = bounds_post['min'].x - bounds_initial['min'].x
|
|
|
|
bpy.ops.transform.translate(value=(-dx, -dy, 0), constraint_axis=(False, False, False), use_proportional_edit=False)
|
|
|
|
|
|
|
|
|
|
|
|
#Restore selection
|
|
|
|
utilities_uv.selection_restore()
|
2019-06-08 23:42:50 +00:00
|
|
|
|
|
|
|
bpy.utils.register_class(op)
|