forked from franMarz/TexTools-Blender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
op_smoothing_uv_islands.py
67 lines (49 loc) · 1.79 KB
/
op_smoothing_uv_islands.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
import math
from mathutils import Vector
from collections import defaultdict
from . import utilities_uv
from . import utilities_ui
class op(bpy.types.Operator):
bl_idname = "uv.textools_smoothing_uv_islands"
bl_label = "Apply smooth normals and hard edges for UV Island borders."
bl_description = "Set mesh smoothing by uv islands"
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
#Requires UV map
if not bpy.context.object.data.uv_layers:
return False
return True
def execute(self, context):
smooth_uv_islands(self, context)
return {'FINISHED'}
def smooth_uv_islands(self, context):
if bpy.context.active_object.mode != 'EDIT':
bpy.ops.object.mode_set(mode='EDIT')
bm = bmesh.from_edit_mesh(bpy.context.active_object.data);
uv_layers = bm.loops.layers.uv.verify();
# Smooth everything
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.faces_shade_smooth()
bpy.ops.mesh.mark_sharp(clear=True)
# Select Edges
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
bpy.ops.uv.textools_select_islands_outline()
bpy.ops.mesh.mark_sharp()
bpy.ops.mesh.select_all(action='DESELECT')
# Apply Edge split modifier
bpy.context.object.data.use_auto_smooth = True
bpy.context.object.data.auto_smooth_angle = math.pi
# bpy.ops.object.modifier_add(type='EDGE_SPLIT')
# bpy.context.object.modifiers["EdgeSplit"].use_edge_angle = False
bpy.ops.object.mode_set(mode='OBJECT')
bpy.utils.register_class(op)