import bpy
import bmesh
def mark_edges_Znormal(arg_objectname="Default",
arg_seam=False, arg_sharp=False, arg_crease=False, arg_bevel=False) -> bool:
"""Z軸の法線方向が上向きの面と下向きの面の境界の辺にシーム/シャープ/クリース/ベベルを設定する
Keyword Arguments:
arg_objectname {str} -- [description] (default: {"Default"})
arg_seam {bool} -- シームの設定有無 (default: {False})
arg_sharp {bool} -- シャープの設定有無 (default: {False})
arg_crease {bool} -- クリースの設定有無 (default: {False})
arg_bevel {bool} -- ベベルの設定有無 (default: {False})
Returns:
bool -- 実行正否
"""
selectob = bpy.data.objects.get(arg_objectname)
if selectob == None:
return False
if selectob.type != 'MESH':
return False
for ob in bpy.context.scene.objects:
ob.select_set(False)
selectob.select_set(True)
bpy.context.view_layer.objects.active = selectob
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
meshdata = bmesh.from_edit_mesh(selectob.data)
meshdata.select_mode = {'FACE'}
bpy.ops.mesh.select_all(action='DESELECT')
meshdata.select_flush_mode()
meshdata.verts.ensure_lookup_table()
for face in meshdata.faces:
if face.normal[2] > 0.0:
face.select_set(True)
else:
face.select_set(False)
meshdata = bmesh.from_edit_mesh(selectob.data)
meshdata.select_mode = {'EDGE'}
meshdata.select_flush_mode()
meshdata.verts.ensure_lookup_table()
for edge in meshdata.edges:
faces = edge.link_faces
if len(faces) == 2:
selectcount = 0
for face in faces:
if face.select == True:
selectcount += 1
if selectcount == 1:
edge.select_set(True)
else:
edge.select_set(False)
else:
edge.select_set(False)
meshdata.select_flush_mode()
selectob.data.update()
if arg_seam == True:
bpy.ops.mesh.mark_seam(clear=False)
if arg_sharp == True:
bpy.ops.mesh.mark_sharp()
if arg_crease == True:
bpy.ops.transform.edge_crease(value=1.0)
if arg_bevel == True:
bpy.ops.transform.edge_bevelweight(value=1.0)
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
return True
def apply_split_sharpedge(arg_objectname="Default") -> bool:
"""対象オブジェクトにブーリアンモディファイアの差分を適用する
Keyword Arguments:
arg_objectname {str} -- 対象オブジェクト名 (default: {"Default"})
Returns:
bool -- 実行正否
"""
selectob = bpy.data.objects.get(arg_objectname)
if selectob == None:
return False
if selectob.type != 'MESH':
return False
bpy.context.view_layer.objects.active = selectob
bpy.ops.object.modifier_add(type='EDGE_SPLIT')
split_modifier = selectob.modifiers[-1]
split_modifier.use_edge_angle = False
split_modifier.use_edge_sharp = True
bpy.ops.object.modifier_apply(apply_as='DATA',modifier=split_modifier.name)
return True
for mesh in bpy.data.objects:
if mesh.type == 'MESH':
mark_edges_Znormal(arg_objectname=mesh.name, arg_sharp=True)
apply_split_sharpedge(arg_objectname=mesh.name)