forked from franMarz/TexTools-Blender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathop_uv_channel_add.py
67 lines (55 loc) · 1.72 KB
/
op_uv_channel_add.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
import bpy
import bmesh
import operator
from mathutils import Vector
from collections import defaultdict
from math import pi
from . import utilities_ui
class op(bpy.types.Operator):
bl_idname = "uv.textools_uv_channel_add"
bl_label = "Add UV Channel"
bl_description = "Add a new UV channel with smart UV projected UV's and padding."
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if bpy.context.active_object == None:
return False
if bpy.context.active_object.type != 'MESH':
return False
return True
@classmethod
def poll(cls, context):
if bpy.context.active_object == None:
return False
if bpy.context.active_object.type != 'MESH':
return False
if len(bpy.context.selected_objects) != 1:
return False
return True
def execute(self, context):
print("Add UV")
if len( bpy.context.object.data.uv_layers ) == 0:
# Create first UV channel
if bpy.context.active_object.mode != 'EDIT':
bpy.ops.object.mode_set(mode='EDIT')
# Smart project UV's
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.smart_project(
angle_limit=65,
island_margin=0.5,
user_area_weight=0,
use_aspect=True,
stretch_to_bounds=True
)
# Re-Apply padding as normalized values
bpy.ops.uv.select_all(action='SELECT')
bpy.ops.uv.pack_islands(margin=utilities_ui.get_padding())
else:
# Add new UV channel based on last
bpy.ops.mesh.uv_texture_add()
# Get current index
index = len(bpy.context.object.data.uv_layers)-1
bpy.context.object.data.uv_layers.active_index = index
bpy.context.scene.texToolsSettings.uv_channel = str(index)
return {'FINISHED'}
bpy.utils.register_class(op)