2019-06-08 23:42:50 +00:00
|
|
|
import bpy
|
|
|
|
import os
|
|
|
|
import bmesh
|
|
|
|
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
|
|
|
"""UV Operator description"""
|
|
|
|
bl_idname = "uv.textools_unwrap_faces_iron"
|
|
|
|
bl_label = "Iron"
|
|
|
|
bl_description = "Unwrap selected faces into a single UV island"
|
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
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
|
|
|
# Need view Face mode
|
|
|
|
if tuple(bpy.context.scene.tool_settings.mesh_select_mode)[2] == False:
|
|
|
|
return False
|
|
|
|
#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
|
|
|
#Requires UV map
|
|
|
|
# if not bpy.context.object.data.uv_layers:
|
|
|
|
# return False
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
# if bpy.context.scene.tool_settings.uv_select_mode != 'FACE':
|
|
|
|
# return False
|
|
|
|
return True
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
def execute(self, context):
|
|
|
|
main(context)
|
|
|
|
return {'FINISHED'}
|
2019-06-08 23:42:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main(context):
|
2019-12-18 20:53:16 +00:00
|
|
|
print("operatyor_faces_iron()")
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
#Store selection
|
|
|
|
utilities_uv.selection_store()
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
bm = bmesh.from_edit_mesh(bpy.context.active_object.data)
|
|
|
|
uv_layers = bm.loops.layers.uv.verify()
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
bpy.context.scene.tool_settings.uv_select_mode = 'FACE'
|
|
|
|
bpy.ops.mesh.mark_seam(clear=True)
|
2019-06-08 23:42:50 +00:00
|
|
|
|
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
selected_faces = [f for f in bm.faces if f.select]
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
# Hard edges to seams
|
|
|
|
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
|
|
|
|
bpy.ops.mesh.region_to_loop()
|
|
|
|
bpy.ops.mesh.mark_seam(clear=False)
|
2019-06-08 23:42:50 +00:00
|
|
|
|
2019-12-18 20:53:16 +00:00
|
|
|
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
|
|
|
|
for face in selected_faces:
|
|
|
|
face.select = True
|
|
|
|
|
|
|
|
bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.0226216)
|
2019-06-08 23:42:50 +00:00
|
|
|
|
|
|
|
bpy.utils.register_class(op)
|