64 lines
2.7 KiB
Python
64 lines
2.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
DESCRIPTION.
|
|
Basic mesh processing for asset pipeline.
|
|
Early WIP!
|
|
"""
|
|
__version__ = "0.1"
|
|
|
|
import logging
|
|
import sys
|
|
import bpy
|
|
import math
|
|
from utils.apply_transforms import apply_transforms
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
def asset_setup(transforms=True, sharpness=True, shading=True):
|
|
""" asset setup pipeline """
|
|
for ob in bpy.context.scene.objects:
|
|
#deselect all but just one object and make it active
|
|
bpy.ops.object.select_all(action='DESELECT')
|
|
ob.select_set(state=True)
|
|
bpy.context.view_layer.objects.active = ob
|
|
|
|
if transforms:
|
|
# apply scale
|
|
apply_transforms(ob, location=False, rotation=False, scale=True)
|
|
# remove doubles
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
bpy.ops.mesh.select_all(action='SELECT')
|
|
bpy.ops.mesh.remove_doubles(threshold = 0.0001)
|
|
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(30) )
|
|
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='WEIGHTED_NORMAL', name='weightednormal')
|
|
bpy.context.view_layer.objects.active.modifiers["weightednormal"].keep_sharp = 1
|
|
bpy.context.object.modifiers["weightednormal"].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
|