[Blender] Baking optimization
This commit is contained in:
parent
90945c0430
commit
25c9cbfbe9
6 changed files with 182 additions and 13 deletions
|
@ -14,10 +14,12 @@ from itertools import zip_longest
|
|||
|
||||
from blender.utils.remove_collections import remove_collections
|
||||
from blender.utils.cleanup_orphan_data import cleanup_orphan_data
|
||||
from blender.utils.collection_tools import copy_collections_recursive
|
||||
from utils.cmd_proc import cmd_proc
|
||||
from blender.import_cad.build_blender_scene import json_to_blend
|
||||
from blender.processing.restruct_hierarchy_by_lcs import restruct_hierarchy
|
||||
from blender.processing.highpoly_setup 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.uv_setup import uv_unwrap
|
||||
from blender.export.dae import export_dae
|
||||
|
@ -59,6 +61,7 @@ outlet = '_out'
|
|||
root = '_root'
|
||||
# CG ASSETS SUFFIXES CONVENTION
|
||||
hightpoly = '_hp'
|
||||
midpoly = 'mp'
|
||||
lowpoly = '_lp'
|
||||
render = '_render'
|
||||
|
||||
|
@ -68,6 +71,7 @@ def cg_pipeline(**kwargs):
|
|||
|
||||
blend_path = kwargs.pop('blend_path', None)
|
||||
mesh_export_path = kwargs.pop('mesh_export_path', None)
|
||||
config = kwargs.pop('config', None)
|
||||
|
||||
# prepare blend file
|
||||
remove_collections()
|
||||
|
@ -88,7 +92,7 @@ def cg_pipeline(**kwargs):
|
|||
if imported_objects['objs_lcs']:
|
||||
restruct_hierarchy(imported_objects['objs_lcs'])
|
||||
|
||||
# save blender scene
|
||||
# save import in blender scene
|
||||
if blend_path is not None:
|
||||
if not os.path.isdir(os.path.dirname(blend_path)):
|
||||
os.makedirs(os.path.dirname(blend_path))
|
||||
|
@ -105,11 +109,18 @@ def cg_pipeline(**kwargs):
|
|||
for lcs_name in imported_objects['objs_lcs']
|
||||
if lcs_name.endswith(inlet)]
|
||||
|
||||
# prepare lowpoly
|
||||
lowpoly_objs = parts_to_shells(part_names)
|
||||
uv_unwrap(lowpoly_objs)
|
||||
# prepare midpoly
|
||||
copy_collections_recursive(
|
||||
bpy.data.collections[parts_col_name], suffix=midpoly
|
||||
)
|
||||
hightpoly_collections_to_midpoly(part_names)
|
||||
|
||||
# save blender scene
|
||||
|
||||
# prepare lowpoly
|
||||
lowpoly_obj_names = parts_to_shells(part_names)
|
||||
uv_unwrap(lowpoly_obj_names)
|
||||
|
||||
# save lowpoly in blender scene
|
||||
if blend_path is not None:
|
||||
if not os.path.isdir(os.path.dirname(blend_path)):
|
||||
os.makedirs(os.path.dirname(blend_path))
|
||||
|
@ -118,29 +129,30 @@ def cg_pipeline(**kwargs):
|
|||
# export object meshes and urdf
|
||||
to_urdf = collections.defaultdict(list)
|
||||
|
||||
if lowpoly_objs:
|
||||
export_objs = lowpoly_objs
|
||||
if lowpoly_obj_names:
|
||||
export_obj_names = lowpoly_obj_names
|
||||
else:
|
||||
export_objs = sum([imported_objects['objs_foreground'],
|
||||
export_obj_names = sum([imported_objects['objs_foreground'],
|
||||
imported_objects['objs_background']], [])
|
||||
|
||||
link = {}
|
||||
for export_obj in export_objs:
|
||||
for export_obj_name in export_obj_names:
|
||||
link_prop = {}
|
||||
if mesh_export_path is not None:
|
||||
link_prop['visual'] = export_dae(
|
||||
obj_name=export_obj, path=mesh_export_path, subdir='visual')
|
||||
obj_name=export_obj_name, path=mesh_export_path, subdir='visual')
|
||||
link_prop['collision'] = export_stl(
|
||||
obj_name=export_obj, path=mesh_export_path, subdir='collision')
|
||||
obj_name=export_obj_name, path=mesh_export_path, subdir='collision')
|
||||
|
||||
link[export_obj] = link_prop
|
||||
link[export_obj_name] = link_prop
|
||||
|
||||
to_urdf['links'].append(link)
|
||||
|
||||
config = {'sequences': [['cube1', 'cube2', 'cube3', 'cube4'], ['cube2', 'cube1', 'cube4', 'cube3']]}
|
||||
#config = {'sequences': [['cube1', 'cube2', 'cube3', 'cube4'], ['cube2', 'cube1', 'cube4', 'cube3']]}
|
||||
if config:
|
||||
for sequence in config['sequences']:
|
||||
joint = {}
|
||||
# TODO collect pairs 0_1, 1_2, 2_3, 3_4, ...
|
||||
for pair in zip_longest(sequence[0::2], sequence[1::2]):
|
||||
joint_prop = {}
|
||||
if pair[1]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue