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
|
@ -14,6 +14,7 @@
|
|||
DESCRIPTION.
|
||||
Generte object from collection of objects.
|
||||
'''
|
||||
# DEPRECATED
|
||||
__version__ = '0.1'
|
||||
|
||||
import logging
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
# GNU General Public License for more details.
|
||||
'''
|
||||
DESCRIPTION.
|
||||
Basic mesh processing for asset pipeline.
|
||||
Mesh processing for original tesselated assets for render.
|
||||
'''
|
||||
__version__ = '0.2'
|
||||
__version__ = '0.3'
|
||||
|
||||
import logging
|
||||
import bpy
|
||||
|
@ -25,7 +25,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
def setup_meshes(obj_names, cleanup=False, sharpness=False, shading=False):
|
||||
''' Setup raw meshes list after importing '''
|
||||
logger.info('Hightpoly meshes setup launched...')
|
||||
logger.info('Render assets setup launched...')
|
||||
fixed_obj_names = []
|
||||
for obj_name in obj_names:
|
||||
if not bpy.data.objects.get(obj_name):
|
||||
|
@ -71,4 +71,4 @@ def setup_meshes(obj_names, cleanup=False, sharpness=False, shading=False):
|
|||
|
||||
fixed_obj_names.append(obj_name)
|
||||
|
||||
return logger.info('Setup of %s hightpoly meshes is finished!', len(fixed_obj_names))
|
||||
return logger.info('Setup of %s meshes is finished!', len(fixed_obj_names))
|
|
@ -28,17 +28,24 @@ from blender.utils.collection_tools import unlink_from_collections
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def hierarchy_assembly(lcs_names, parts_sequence, **cg_config):
|
||||
def hierarchy_assembly(lcs_names, parts_sequence):
|
||||
''' Hierarchy by LCS and Parts Assembling Sequence. '''
|
||||
# collect scene hierarchy start info
|
||||
main_locators = [obj for obj in bpy.data.objects if not obj.parent]
|
||||
lcs_inlet_objects = []
|
||||
lcs_outlet_objects = []
|
||||
for name in lcs_names:
|
||||
if name.endswith(cg_config['lcs_inlet']):
|
||||
lcs_inlet_objects.append(bpy.data.objects[name])
|
||||
for lcs_name in lcs_names:
|
||||
lcs_obj = bpy.data.objects[lcs_name]
|
||||
if (lcs_obj.get('Robossembler_SocketFlow') == 'inlet'
|
||||
and lcs_obj.get('Robossembler_DefaultOrigin')
|
||||
):
|
||||
lcs_inlet_objects.append(lcs_obj)
|
||||
else:
|
||||
lcs_outlet_objects.append(bpy.data.objects[name])
|
||||
lcs_outlet_objects.append(lcs_obj)
|
||||
|
||||
if not lcs_inlet_objects:
|
||||
raise Exception('No LCS Inlet objects found!')
|
||||
|
||||
# get main_locator
|
||||
main_locator = None
|
||||
for locator in main_locators:
|
||||
|
@ -55,18 +62,20 @@ def hierarchy_assembly(lcs_names, parts_sequence, **cg_config):
|
|||
if not bpy.data.objects.get(part):
|
||||
return logger.error('%s part object not found!', part)
|
||||
|
||||
first_part_obj = bpy.data.objects[parts_sequence[0]]
|
||||
|
||||
# create root lcs by parts sequence
|
||||
first_part_obj = bpy.data.objects[parts_sequence[0]]
|
||||
root_lcs = None
|
||||
for lcs_inlet in first_part_obj.children:
|
||||
# drop non lcs objs
|
||||
if lcs_inlet.name not in lcs_names:
|
||||
continue
|
||||
# drop non inlet objs
|
||||
if lcs_inlet.name.endswith(cg_config['lcs_outlet']):
|
||||
# drop non DefaultOrigins
|
||||
lcs_obj = bpy.data.objects[lcs_name]
|
||||
if not (lcs_obj.get('Robossembler_SocketFlow') == 'inlet'
|
||||
and lcs_obj.get('Robossembler_DefaultOrigin')
|
||||
):
|
||||
continue
|
||||
root_lcs_name = cg_config['lcs_root']
|
||||
root_lcs_name = 'root'
|
||||
root_lcs = bpy.data.objects.new(root_lcs_name, None)
|
||||
root_lcs.empty_display_type = 'ARROWS'
|
||||
root_lcs.empty_display_size = 0.15
|
||||
|
@ -74,19 +83,18 @@ def hierarchy_assembly(lcs_names, parts_sequence, **cg_config):
|
|||
root_lcs.location = lcs_inlet.location
|
||||
root_lcs.rotation_euler = lcs_inlet.rotation_euler
|
||||
root_lcs.parent = lcs_inlet.parent
|
||||
bpy.data.collections[cg_config['lcs_col_name']].objects.link(root_lcs)
|
||||
bpy.context.scene.collection.objects.link(root_lcs)
|
||||
logger.info('Root Inlet LCS object created!')
|
||||
|
||||
unparenting(root_lcs)
|
||||
round_transforms(root_lcs)
|
||||
parenting(root_lcs, main_locator)
|
||||
|
||||
# retree_by lcs
|
||||
for lcs_inlet_obj in lcs_inlet_objects:
|
||||
# lcs inlet
|
||||
# lcs inlet as main parent
|
||||
parent_locator = lcs_inlet_obj.parent
|
||||
if not parent_locator:
|
||||
return logger.error('LCS %s should have a parent', lcs_inlet_obj.name)
|
||||
raise Exception('LCS %s should have a parent!', lcs_inlet_obj.name)
|
||||
unparenting(lcs_inlet_obj)
|
||||
round_transforms(lcs_inlet_obj)
|
||||
if parent_locator:
|
||||
|
@ -94,11 +102,10 @@ def hierarchy_assembly(lcs_names, parts_sequence, **cg_config):
|
|||
unparenting(parent_locator)
|
||||
parenting(lcs_inlet_obj, parent_locator)
|
||||
parenting(root_lcs, lcs_inlet_obj)
|
||||
# lcs outlet
|
||||
lcs_outlet = '{}_{}'.format(
|
||||
lcs_inlet_obj.name.rpartition('_')[0], cg_config['lcs_outlet'])
|
||||
if bpy.data.objects.get(lcs_outlet):
|
||||
lcs_outlet_obj = bpy.data.objects[lcs_outlet]
|
||||
# lcs outlet parent to lcs inlet
|
||||
for lcs_outlet_obj in lcs_inlet_obj.children_recursive:
|
||||
if lcs_outlet_obj.name not in lcs_names:
|
||||
continue
|
||||
unparenting(lcs_outlet_obj)
|
||||
round_transforms(lcs_outlet_obj)
|
||||
parenting(lcs_inlet_obj, lcs_outlet_obj)
|
||||
|
@ -118,20 +125,21 @@ def hierarchy_assembly(lcs_names, parts_sequence, **cg_config):
|
|||
# collect part names
|
||||
part_name = None
|
||||
for locator in lcs_inlet_obj.children:
|
||||
if locator not in lcs_outlet_objects:
|
||||
part_name = locator.name
|
||||
part_names.append(part_name)
|
||||
# pack parts to collections
|
||||
part_col = bpy.data.collections.new('{}_{}'.format(
|
||||
part_name, cg_config['hightpoly']))
|
||||
bpy.data.collections[cg_config['parts_col_name']].children.link(part_col)
|
||||
for obj in lcs_inlet_obj.children_recursive:
|
||||
# outlet lcs objects are already in place, don't move it
|
||||
if obj in lcs_outlet_objects:
|
||||
if locator in lcs_outlet_objects:
|
||||
continue
|
||||
part_name = locator.name
|
||||
part_names.append(part_name)
|
||||
# pack parts to collections
|
||||
part_col = bpy.data.collections.new(f'{part_name}')
|
||||
bpy.data.collections['Render'].children.link(part_col)
|
||||
for obj in lcs_inlet_obj.children_recursive:
|
||||
unlink_from_collections(obj)
|
||||
part_col.objects.link(obj)
|
||||
unlink_from_collections(lcs_inlet_obj)
|
||||
part_col.objects.link(lcs_inlet_obj)
|
||||
|
||||
# TODO DEPRECATED
|
||||
"""
|
||||
# parts assembling
|
||||
for idx, part_name in enumerate(parts_sequence):
|
||||
# TODO clones for clones
|
||||
|
@ -160,63 +168,73 @@ def hierarchy_assembly(lcs_names, parts_sequence, **cg_config):
|
|||
constraint = lcs.constraints.new(type='COPY_TRANSFORMS')
|
||||
constraint.target = root_lcs
|
||||
constraint.enabled = False
|
||||
"""
|
||||
|
||||
logger.info('Restructuring assembly pipeline finished!')
|
||||
|
||||
return part_names
|
||||
|
||||
|
||||
def hierarchy_separated_parts(lcs_names, **cg_config):
|
||||
def hierarchy_separated_parts(lcs_names):
|
||||
''' Restructuring pipeline as separated parts. '''
|
||||
# collect scene hierarchy start info
|
||||
lcs_inlet_objects = []
|
||||
lcs_outlet_objects = []
|
||||
for name in lcs_names:
|
||||
if name.endswith(cg_config['lcs_inlet']):
|
||||
lcs_inlet_objects.append(bpy.data.objects[name])
|
||||
|
||||
for lcs_name in lcs_names:
|
||||
lcs_obj = bpy.data.objects[lcs_name]
|
||||
if (lcs_obj.get('Robossembler_SocketFlow') == 'inlet'
|
||||
and lcs_obj.get('Robossembler_DefaultOrigin')
|
||||
):
|
||||
lcs_inlet_objects.append(lcs_obj)
|
||||
else:
|
||||
lcs_outlet_objects.append(bpy.data.objects[name])
|
||||
lcs_outlet_objects.append(lcs_obj)
|
||||
|
||||
if not lcs_inlet_objects:
|
||||
raise Exception('No LCS Inlet objects found!')
|
||||
|
||||
# retree_by lcs
|
||||
part_names = []
|
||||
for lcs_inlet_obj in lcs_inlet_objects:
|
||||
# outlet lcs
|
||||
# lcs inlet as main parent
|
||||
parent_locator = lcs_inlet_obj.parent
|
||||
if not parent_locator:
|
||||
return logger.error('LCS %s should have a parent', lcs_inlet_obj.name)
|
||||
raise Exception('LCS %s should have a parent!', lcs_inlet_obj.name)
|
||||
unparenting(lcs_inlet_obj)
|
||||
round_transforms(lcs_inlet_obj)
|
||||
if parent_locator:
|
||||
if parent_locator.parent:
|
||||
unparenting(parent_locator)
|
||||
parenting(lcs_inlet_obj, parent_locator)
|
||||
# lcs outlet
|
||||
lcs_outlet = '{}_{}'.format(
|
||||
lcs_inlet_obj.name.rpartition('_')[0], cg_config['lcs_outlet'])
|
||||
if bpy.data.objects.get(lcs_outlet):
|
||||
lcs_outlet_obj = bpy.data.objects[lcs_outlet]
|
||||
# lcs outlet parent to lcs inlet
|
||||
for lcs_outlet_obj in lcs_inlet_obj.children_recursive:
|
||||
if lcs_outlet_obj.name not in lcs_names:
|
||||
continue
|
||||
unparenting(lcs_outlet_obj)
|
||||
round_transforms(lcs_outlet_obj)
|
||||
parenting(lcs_inlet_obj, lcs_outlet_obj)
|
||||
|
||||
# reset transforms for inlet_lcs
|
||||
lcs_inlet_obj.matrix_world = mathutils.Matrix()
|
||||
|
||||
# pack parts to collections
|
||||
part_name = None
|
||||
for locator in lcs_inlet_obj.children:
|
||||
if locator not in lcs_outlet_objects:
|
||||
part_name = locator.name
|
||||
part_names.append(part_name)
|
||||
part_col = bpy.data.collections.new('{}_{}'.format(
|
||||
part_name, cg_config['hightpoly']))
|
||||
bpy.data.collections[cg_config['parts_col_name']].children.link(part_col)
|
||||
part_col = bpy.data.collections.new(f'{part_name}')
|
||||
bpy.data.collections['Render'].children.link(part_col)
|
||||
for obj in lcs_inlet_obj.children_recursive:
|
||||
unlink_from_collections(obj)
|
||||
part_col.objects.link(obj)
|
||||
unlink_from_collections(lcs_inlet_obj)
|
||||
part_col.objects.link(lcs_inlet_obj)
|
||||
# remove unmarked objects
|
||||
marked_objs = sum(
|
||||
[lcs_inlet_obj.children_recursive for lcs_inlet_obj in lcs_inlet_objects],
|
||||
[])
|
||||
parts_col_objs = bpy.data.collections[cg_config['parts_col_name']].objects
|
||||
parts_col_objs = bpy.data.collections['Render'].objects
|
||||
unmarked_objs = list(set(parts_col_objs) - set(marked_objs))
|
||||
if unmarked_objs:
|
||||
removed_objs = list(map(bpy.data.objects.remove, unmarked_objs))
|
||||
|
@ -227,7 +245,7 @@ def hierarchy_separated_parts(lcs_names, **cg_config):
|
|||
return part_names
|
||||
|
||||
|
||||
def hierarchy_single_part(**cg_config):
|
||||
def hierarchy_mono_part():
|
||||
''' Restructuring pipeline as single part. '''
|
||||
# collect scene hierarchy start info
|
||||
main_locators = [obj for obj in bpy.data.objects if not obj.parent]
|
||||
|
@ -237,9 +255,8 @@ def hierarchy_single_part(**cg_config):
|
|||
for main_locator in main_locators:
|
||||
part_name = main_locator.name
|
||||
part_names.append(part_name)
|
||||
part_col = bpy.data.collections.new('{}_{}'.format(
|
||||
part_name, cg_config['hightpoly']))
|
||||
bpy.data.collections[cg_config['parts_col_name']].children.link(part_col)
|
||||
part_col = bpy.data.collections.new(f'{part_name}')
|
||||
bpy.data.collections['Render'].children.link(part_col)
|
||||
for obj in main_locator.children_recursive:
|
||||
unlink_from_collections(obj)
|
||||
part_col.objects.link(obj)
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
# GNU General Public License for more details.
|
||||
'''
|
||||
DESCRIPTION.
|
||||
Create lowpoly shells from parts collections.
|
||||
Retopology visual assets for simulation pipeline.
|
||||
'''
|
||||
__version__ = '0.1'
|
||||
__version__ = '0.3'
|
||||
|
||||
import logging
|
||||
import bpy
|
Loading…
Add table
Add a link
Reference in a new issue