Skip to content

Commit

Permalink
Add TransformUVs operator
Browse files Browse the repository at this point in the history
  • Loading branch information
passivestar committed Apr 19, 2022
1 parent da7bd72 commit 35cb183
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
44 changes: 42 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

bl_info = {
'name': 'QuickMenu',
'version': (2, 1, 0),
'version': (2, 2, 0),
'author': 'passivestar',
'blender': (3, 1, 2),
'location': 'Press the bound hotkey in 3D View',
Expand Down Expand Up @@ -1283,6 +1283,46 @@ def execute(self, context):
context.area.ui_type = previous_area
return {'FINISHED'}

class TransformUVsOperator(bpy.types.Operator):
"""Transform UV"""
bl_idname, bl_label, bl_options = 'qm.transform_uvs', 'Transform UVs', {'REGISTER', 'UNDO'}

offset_x: FloatProperty(name='Offset X', default=0, step=0.1)
offset_y: FloatProperty(name='Offset Y', default=0, step=0.1)
rotation: FloatProperty(name='Rotation', default=0, soft_min=-360, soft_max=360)
scale_x: FloatProperty(name='Scale X', default=1, step=0.1, soft_min=0)
scale_y: FloatProperty(name='Scale Y', default=1, step=0.1, soft_min=0)

@classmethod
def poll(cls, context):
return is_in_editmode()

def execute(self, context):
me = bpy.context.edit_object.data
bm = bmesh.from_edit_mesh(me)
uv_layer = bm.loops.layers.uv.verify()
uvs = []
for face in bm.faces:
if face.select:
center = face.calc_center_median()
for loop in face.loops:
uvs.append(loop[uv_layer])
center = reduce(lambda a, b: a + b, [uv.uv for uv in uvs]) / len(uvs)

for uv in uvs:
if self.offset_x or self.offset_y:
uv.uv += Vector( (self.offset_x, self.offset_y) )
if self.rotation:
rotation_matrix = Matrix.Rotation(math.radians(self.rotation), 2)
offset_uv = uv.uv - center
offset_uv.rotate(rotation_matrix)
uv.uv = center + offset_uv
if self.scale_x != 1 or self.scale_y != 1:
uv.uv = center + Vector(uv.uv - center) * Vector((self.scale_x, self.scale_y))

bmesh.update_edit_mesh(me)
return {'FINISHED'}

class SetVertexColorOperator(bpy.types.Operator):
"""Set Vertex Color"""
bl_idname, bl_label, bl_options = 'qm.set_vertex_color', 'Set Vertex Color', {'REGISTER', 'UNDO'}
Expand Down Expand Up @@ -1861,7 +1901,7 @@ class QuickMenuProperties(bpy.types.PropertyGroup):
BevelOperator, SolidifyOperator, TriangulateOperator, ArrayOperator,
SimpleDeformOperator, ClearModifiersOperator, DeleteBackFacingOperator,
SeparateByLoosePartsOperator, StraightenUVsOperator, UVProjectModifierOperator, MarkSeamOperator,
MarkSeamsSharpOperator, MarkSeamsFromIslandsOperator, SetVertexColorOperator, SelectByVertexColorOperator, BakeIDMapOperator, EditAlbedoMapOperator,
MarkSeamsSharpOperator, MarkSeamsFromIslandsOperator, TransformUVsOperator, SetVertexColorOperator, SelectByVertexColorOperator, BakeIDMapOperator, EditAlbedoMapOperator,
BooleanOperator, WeldEdgesIntoFacesOperator, ParentToNewEmptyOperator, ClearDriversOperator, SetUseSelfDriversOperator,
PlaneIntersectOperator, KnifeIntersectOperator, IntersectOperator, TransformOrientationOperator, TransformPivotOperator,
SetSnapOperator, ModeOperator, ToolOperator, SaveAndReloadOperator, ReimportTexturesOperator, RepackAllDataOperator, ExportOperator, ViewOperator,
Expand Down
22 changes: 20 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,26 @@
"operator": "qm.mark_seams_sharp"
},
{
"path": "(W) UV-Textures/(W) Mark Seams From Islands",
"operator": "qm.mark_seams_from_islands"
"path": "(W) UV-Textures/(W) Transform UVs",
"operator": "qm.transform_uvs",
"params": {
"offset_x": 0,
"offset_y": 0,
"rotation": 0,
"scale_x": 1,
"scale_y": 1
}
},
{
"path": "(W) UV-Textures/(E) Rotate UVs 90",
"operator": "qm.transform_uvs",
"params": {
"offset_x": 0,
"offset_y": 0,
"rotation": 90,
"scale_x": 1,
"scale_y": 1
}
},
{
"path": "(W) UV-Textures/[Separator]"
Expand Down

0 comments on commit 35cb183

Please sign in to comment.