# -*- coding: utf-8 -*- # Copyright (C) 2023 Ilia Kurochkin # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. ''' DESCRIPTION. Basic mesh processing for asset pipeline. ''' __version__ = '0.2' import logging import sys import bpy import math logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) def setup_meshes(bobjs, cleanup=False, sharpness=False, shading=False): ''' Setup raw meshes list after importing ''' logger.info('Hightpoly meshes setup launched...') for bobj in bobjs: if not bobj.type == 'MESH': continue bpy.ops.object.select_all(action='DESELECT') bobj.select_set(state=True) bpy.context.view_layer.objects.active = bobj if cleanup: # remove doubles bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_all(action='SELECT') bpy.ops.mesh.remove_doubles(threshold=0.00001) bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.mesh.select_mode(type='FACE') bpy.ops.mesh.select_interior_faces() bpy.ops.mesh.delete(type='FACE') bpy.ops.object.mode_set(mode='OBJECT') if sharpness: # set shaps and unwrap bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.mesh.select_mode(type='EDGE') bpy.ops.mesh.edges_select_sharp( sharpness=math.radians(12) ) bpy.ops.mesh.mark_sharp() bpy.ops.mesh.select_all(action='SELECT') bpy.ops.uv.smart_project() bpy.ops.object.mode_set(mode='OBJECT') if shading: # fix shading bpy.ops.object.shade_smooth() bpy.context.view_layer.objects.active.data.use_auto_smooth = 1 bpy.context.view_layer.objects.active.modifiers.new(type='DECIMATE', name='decimate') bpy.context.view_layer.objects.active.modifiers['decimate'].decimate_type = 'DISSOLVE' bpy.context.view_layer.objects.active.modifiers['decimate'].angle_limit = 0.00872665 bpy.context.object.modifiers['decimate'].show_expanded = 0 bpy.context.view_layer.objects.active.modifiers.new(type='TRIANGULATE', name='triangulate') bpy.context.object.modifiers['triangulate'].keep_custom_normals = 1 bpy.context.object.modifiers['triangulate'].show_expanded = 0 return logger.info('Hightpoly meshes setup finished!')