[CG Pipeline] Refactor

This commit is contained in:
brothermechanic 2023-11-13 13:07:33 +00:00 committed by Igor Brylyov
parent 6538f70d54
commit b3612d8655
23 changed files with 634 additions and 645 deletions

View file

@ -18,6 +18,7 @@ __version__ = '0.1'
import logging
import bpy
import math
from blender.utils.generative_modifiers import shell_remesher
from blender.utils.object_converter import mesh_to_mesh
@ -25,44 +26,31 @@ from blender.utils.object_relations import parenting
from blender.utils.mesh_tools import select_peaks, select_stratched_edges
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
# COLLECTIONS NAMIG CONVENTION
parts_col_name = 'Parts'
lcs_col_name = 'LCS'
hierarchy_col_name = 'Hierarchy'
lowpoly_col_name = 'Lowpoly'
# LCS POINT'S SUFFIXES CONVENTION
inlet = '_in'
outlet = '_out'
root = '_root'
# CG ASSETS SUFFIXES CONVENTION
hightpoly = '_hp'
lowpoly = '_lp'
render = '_render'
def parts_to_shells(hightpoly_part_names):
def parts_to_shells(part_names, lcs_pipeline, **cg_config):
''' Create lowpoly shells from parts collections. '''
logger.info('Lowpoly shells creation launched...')
lowpoly_col = bpy.data.collections.new(lowpoly_col_name)
lowpoly_col = bpy.data.collections.new(cg_config['lowpoly_col_name'])
bpy.context.scene.collection.children.link(lowpoly_col)
for part_name in hightpoly_part_names:
for part_name in part_names:
# generate lowpoly objects from part collections
lowpoly_name = ('{}{}'.format(part_name, lowpoly))
lowpoly_name = '{}_{}'.format(part_name, cg_config['lowpoly'])
lowpoly_mesh = bpy.data.meshes.new(lowpoly_name)
lowpoly_obj = bpy.data.objects.new(lowpoly_name, lowpoly_mesh)
bpy.context.view_layer.update()
part_inlet = bpy.data.objects.get('{}{}'.format(part_name, inlet))
lowpoly_obj.matrix_world = part_inlet.matrix_world.copy()
parenting(part_inlet, lowpoly_obj)
lowpoly_col.objects.link(lowpoly_obj)
if lcs_pipeline:
lcs_inlet = bpy.data.objects[part_name].parent
lowpoly_obj.matrix_world = lcs_inlet.matrix_world.copy()
parenting(lcs_inlet, lowpoly_obj)
part_col = bpy.data.collections[
'{}_{}'.format(part_name, cg_config['hightpoly'])]
else:
part_col = bpy.data.collections[cg_config['parts_col_name']]
shell_remesher(lowpoly_obj, 'remesh_nodes', 'robossembler')
part_col = bpy.data.collections[('{}{}'.format(part_name, hightpoly))]
lowpoly_obj.modifiers['remesh_nodes']['Input_0'] = part_col
remesh_voxel = lowpoly_obj.modifiers.new('remesh_voxel', type='REMESH')
@ -78,7 +66,10 @@ def parts_to_shells(hightpoly_part_names):
decimate.ratio = 0.1
# apply all modifiers to mesh
parenting(part_inlet, mesh_to_mesh(lowpoly_obj))
if lcs_pipeline:
parenting(lcs_inlet, mesh_to_mesh(lowpoly_obj))
else:
mesh_to_mesh(lowpoly_obj)
# fix non_manifold shape
for lowpoly_obj in lowpoly_col.objects:
@ -134,6 +125,12 @@ def parts_to_shells(hightpoly_part_names):
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.mesh.select_mode(type='FACE')
bpy.ops.object.mode_set(mode='OBJECT')
# shading
bpy.ops.object.shade_smooth(use_auto_smooth=True)
lowpoly_obj.data.auto_smooth_angle = math.radians(10)
lowpoly_obj.modifiers.new(type='WEIGHTED_NORMAL', name='WeightedNormal')
lowpoly_obj.modifiers['WeightedNormal'].keep_sharp = True
bpy.ops.object.modifier_apply(modifier="WeightedNormal")
logger.info('Generation of %s lowpoly shells is finished!', len(lowpoly_col.objects))