cg: update pipeline to lcs property 2 WIP
This commit is contained in:
parent
6c7e8c46d6
commit
bce317a554
6 changed files with 120 additions and 102 deletions
|
@ -19,10 +19,10 @@ from utils.cmd_proc import cmd_proc
|
|||
from blender.import_cad.build_blender_scene import json_to_blend
|
||||
from blender.processing.restruct_hierarchy import (hierarchy_assembly,
|
||||
hierarchy_separated_parts,
|
||||
hierarchy_single_part)
|
||||
from blender.processing.highpoly_setup import setup_meshes
|
||||
hierarchy_mono_part)
|
||||
from blender.processing.render_assets import setup_meshes
|
||||
from blender.processing.midpoly_setup import hightpoly_collections_to_midpoly
|
||||
from blender.processing.lowpoly_setup import parts_to_shells
|
||||
from blender.processing.visual_assets import parts_to_shells
|
||||
from blender.processing.uv_setup import uv_unwrap
|
||||
from blender.texturing.bake_submitter import bw_bake
|
||||
from blender.texturing.composing import compose_baked_textures
|
||||
|
@ -45,21 +45,22 @@ freecad_bin = 'freecadcmd'
|
|||
blender_bin = 'blender'
|
||||
|
||||
# TODO WEBAPP
|
||||
cg_config = {
|
||||
'lcs_col_name': 'LCS',
|
||||
cg_config = {}
|
||||
"""
|
||||
'parts_col_name': 'Parts',
|
||||
'midpoly_col_name': 'Midpoly',
|
||||
'lowpoly_col_name': 'Lowpoly',
|
||||
'visual_col_name': 'Lowpoly',
|
||||
'lcs_inlet': 'in',
|
||||
'lcs_outlet': 'out',
|
||||
'lcs_root': 'root',
|
||||
'hightpoly': 'hp',
|
||||
'render': 'hp',
|
||||
'midpoly': 'mp',
|
||||
'lowpoly': 'lp',
|
||||
'visual': 'lp',
|
||||
'render': 'render',
|
||||
}
|
||||
"""
|
||||
|
||||
defined_pipeline_list = ['cad', 'highpoly', 'midpoly', 'lowpoly', 'baking', 'export']
|
||||
defined_pipeline_list = ['cad', 'render', 'visual', 'collision', 'baking', 'export']
|
||||
|
||||
|
||||
def cg_pipeline(**kwargs):
|
||||
|
@ -95,7 +96,7 @@ def cg_pipeline(**kwargs):
|
|||
'--',
|
||||
**kwargs
|
||||
).split('FreeCAD ')[0]
|
||||
), **cg_config
|
||||
)
|
||||
)
|
||||
|
||||
# Save original cad setup as blender scene
|
||||
|
@ -107,53 +108,54 @@ def cg_pipeline(**kwargs):
|
|||
bpy.ops.wm.save_as_mainfile(filepath=blend_file)
|
||||
return blend_file
|
||||
|
||||
# 2) prepare highpoly (depend of cad_objects['objs_lcs'] and parts_sequence)
|
||||
# 2) prepare render (depend of cad_objects['objs_lcs'] and parts_sequence)
|
||||
# ______________________________
|
||||
if parts_sequence_path and os.path.isfile(parts_sequence_path):
|
||||
with open(parts_sequence_path, 'r', encoding='utf-8') as sequence_file:
|
||||
parts_sequence = json.load(sequence_file)
|
||||
else:
|
||||
parts_sequence = None
|
||||
lcs_inlet_objects = [
|
||||
inlet for inlet in cad_objects['objs_lcs']
|
||||
if inlet.endswith(cg_config['lcs_inlet'])]
|
||||
lcs_inlets = [
|
||||
lcs_name for lcs_name in cad_objects['objs_lcs']
|
||||
if (bpy.data.objects[lcs_name].get('Robossembler_SocketFlow') == 'inlet'
|
||||
and bpy.data.objects[lcs_name].get('Robossembler_DefaultOrigin'))]
|
||||
|
||||
# input cases
|
||||
# 1 case
|
||||
if parts_sequence and len(lcs_inlet_objects) > 1:
|
||||
if parts_sequence and len(lcs_inlets) > 1:
|
||||
logger.info('Parts assembling sequence and LCS points found! '
|
||||
'Launch "hierarchy_assembly" restructuring pipeline.')
|
||||
part_names = hierarchy_assembly(
|
||||
cad_objects['objs_lcs'], parts_sequence, **cg_config)
|
||||
cad_objects['objs_lcs'], parts_sequence)
|
||||
# 2 case
|
||||
elif parts_sequence and len(lcs_inlet_objects) < 2:
|
||||
elif parts_sequence and len(lcs_inlets) < 2:
|
||||
return logger.error('Assembly do not have enough LCS points!')
|
||||
# 3 case
|
||||
elif not parts_sequence and lcs_inlet_objects:
|
||||
elif not parts_sequence and lcs_inlets:
|
||||
logger.info('Parts assembling sequence not found! '
|
||||
'Launch "hierarchy_separated_parts" restructuring pipeline.')
|
||||
part_names = hierarchy_separated_parts(
|
||||
cad_objects['objs_lcs'], **cg_config)
|
||||
cad_objects['objs_lcs'])
|
||||
# 4 case
|
||||
elif not parts_sequence and not lcs_inlet_objects:
|
||||
elif not parts_sequence and not lcs_inlets:
|
||||
logger.info('Parts assembling sequence and LCS points not found! '
|
||||
'Launch "hierarchy_single_part" restructuring pipeline.')
|
||||
part_names = hierarchy_single_part(**cg_config)
|
||||
'Launch "hierarchy_mono_part" restructuring pipeline.')
|
||||
part_names = hierarchy_mono_part()
|
||||
|
||||
if not part_names:
|
||||
return logger.error('Can not generate parts!')
|
||||
|
||||
# setup highpolys with materials only
|
||||
# setup renders with materials only
|
||||
if cad_objects['objs_foreground']:
|
||||
setup_meshes(cad_objects['objs_foreground'],
|
||||
sharpness=True, shading=True)
|
||||
# setup all highpolys
|
||||
# setup all renders
|
||||
else:
|
||||
setup_meshes(cad_objects['objs_background'],
|
||||
sharpness=True, shading=True)
|
||||
|
||||
# Save highpoly setup as blender scene
|
||||
if kwargs['pipeline_type'] == 'highpoly':
|
||||
# Save render setup as blender scene
|
||||
if kwargs['pipeline_type'] == 'render':
|
||||
blend_file = os.path.join(
|
||||
blend_path,
|
||||
'{}_{}.blend'.format(assembly_name, kwargs['pipeline_type'])
|
||||
|
@ -181,19 +183,19 @@ def cg_pipeline(**kwargs):
|
|||
logger.info('%s midpoly objects ready!', len(midpoly_obj_names))
|
||||
return blend_file
|
||||
|
||||
# 4) prepare lowpoly
|
||||
# 4) prepare visual
|
||||
# ______________________________
|
||||
lowpoly_obj_names = parts_to_shells(part_names, **cg_config)
|
||||
uv_unwrap(lowpoly_obj_names)
|
||||
visual_obj_names = parts_to_shells(part_names, **cg_config)
|
||||
uv_unwrap(visual_obj_names)
|
||||
|
||||
# Save lowpoly setup as blender scene
|
||||
if kwargs['pipeline_type'] == 'lowpoly':
|
||||
# Save visual setup as blender scene
|
||||
if kwargs['pipeline_type'] == 'visual':
|
||||
blend_file = os.path.join(
|
||||
blend_path,
|
||||
'{}_{}.blend'.format(assembly_name, kwargs['pipeline_type'])
|
||||
).replace('\\', '/')
|
||||
bpy.ops.wm.save_as_mainfile(filepath=blend_file)
|
||||
logger.info('%s lowpoly objects ready!', len(lowpoly_obj_names))
|
||||
logger.info('%s visual objects ready!', len(visual_obj_names))
|
||||
return blend_file
|
||||
|
||||
# 5) bake textures
|
||||
|
@ -202,7 +204,7 @@ def cg_pipeline(**kwargs):
|
|||
logger.info('Baking pipeline has been canceled!')
|
||||
else:
|
||||
textures_path = os.path.join(blend_path, 'textures').replace('\\', '/')
|
||||
bake_paths = bw_bake(lowpoly_obj_names,
|
||||
bake_paths = bw_bake(visual_obj_names,
|
||||
textures_path,
|
||||
kwargs['textures_resolution'],
|
||||
**cg_config)
|
||||
|
@ -218,7 +220,7 @@ def cg_pipeline(**kwargs):
|
|||
for bake_path in bake_paths:
|
||||
shutil.rmtree(bake_path)
|
||||
bpy.ops.wm.open_mainfile(filepath=blend_file)
|
||||
assign_pbr_material(lowpoly_obj_names, textures_path)
|
||||
assign_pbr_material(visual_obj_names, textures_path)
|
||||
bpy.ops.file.make_paths_relative()
|
||||
|
||||
# Save baking setup as blender scene
|
||||
|
@ -228,7 +230,7 @@ def cg_pipeline(**kwargs):
|
|||
'{}_{}.blend'.format(assembly_name, kwargs['pipeline_type'])
|
||||
).replace('\\', '/')
|
||||
bpy.ops.wm.save_as_mainfile(filepath=blend_file)
|
||||
logger.info('%s lowpoly objects baked!', len(lowpoly_obj_names))
|
||||
logger.info('%s visual objects baked!', len(visual_obj_names))
|
||||
return blend_file
|
||||
|
||||
# 6 export object meshes
|
||||
|
@ -244,7 +246,7 @@ def cg_pipeline(**kwargs):
|
|||
|
||||
for part_name in part_names:
|
||||
export_fbx(
|
||||
obj_name=f'{part_name}_{cg_config["lowpoly"]}',
|
||||
obj_name=f'{part_name}_{cg_config["visual"]}',
|
||||
path=os.path.join(export_path, part_name, 'meshes').replace('\\', '/'))
|
||||
export_ply(
|
||||
obj_name=f'{part_name}_{cg_config["midpoly"]}',
|
||||
|
@ -253,7 +255,7 @@ def cg_pipeline(**kwargs):
|
|||
obj_name=f'{part_name}_{cg_config["midpoly"]}',
|
||||
path=os.path.join(export_path, part_name, 'meshes').replace('\\', '/'))
|
||||
export_stl(
|
||||
obj_name=f'{part_name}_{cg_config["lowpoly"]}',
|
||||
obj_name=f'{part_name}_{cg_config["visual"]}',
|
||||
path=os.path.join(export_path, part_name, 'meshes').replace('\\', '/'))
|
||||
|
||||
logger.info('%s parts exported!', len(part_names))
|
||||
|
@ -317,7 +319,7 @@ if __name__ == '__main__':
|
|||
parser.add_argument(
|
||||
'--pipeline_type',
|
||||
type=str,
|
||||
help='Set pipeline type: "cad", "highpoly", "midpoly", "lowpoly", "baking", "export"',
|
||||
help='Set pipeline type: "cad", "render","visual", "collision", "baking", "export"',
|
||||
default='export',
|
||||
required=False
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue