You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Blender-TexTools/op_smoothing_uv_islands.py

67 lines
2.0 KiB
Python

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):
4 years ago
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
4 years ago
#Requires UV map
if not bpy.context.object.data.uv_layers:
return False
4 years ago
return True
def execute(self, context):
smooth_uv_islands(self, context)
return {'FINISHED'}
def smooth_uv_islands(self, context):
4 years ago
if bpy.context.active_object.mode != 'EDIT':
bpy.ops.object.mode_set(mode='EDIT')
4 years ago
bm = bmesh.from_edit_mesh(bpy.context.active_object.data);
uv_layers = bm.loops.layers.uv.verify();
4 years ago
# 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)
4 years ago
# 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
4 years ago
# bpy.ops.object.modifier_add(type='EDGE_SPLIT')
# bpy.context.object.modifiers["EdgeSplit"].use_edge_angle = False
4 years ago
bpy.ops.object.mode_set(mode='OBJECT')
bpy.utils.register_class(op)