forked from franMarz/TexTools-Blender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
op_unwrap_faces_iron.py
76 lines (55 loc) · 1.84 KB
/
op_unwrap_faces_iron.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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):
"""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):
if not bpy.context.active_object:
return False
if bpy.context.active_object.type != 'MESH':
return False
#Only in Edit mode
if bpy.context.active_object.mode != 'EDIT':
return False
# 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
#Requires UV map
# if not bpy.context.object.data.uv_layers:
# return False
# if bpy.context.scene.tool_settings.uv_select_mode != 'FACE':
# return False
return True
def execute(self, context):
main(context)
return {'FINISHED'}
def main(context):
print("operatyor_faces_iron()")
#Store selection
utilities_uv.selection_store()
bm = bmesh.from_edit_mesh(bpy.context.active_object.data)
uv_layers = bm.loops.layers.uv.verify()
bpy.context.scene.tool_settings.uv_select_mode = 'FACE'
bpy.ops.mesh.mark_seam(clear=True)
selected_faces = [f for f in bm.faces if f.select]
# 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)
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)
bpy.utils.register_class(op)