Tool for convert FreeCAD sub-assemblies to URDF-world according to config
This commit is contained in:
parent
03bc34539c
commit
184ac7df88
12 changed files with 327 additions and 119 deletions
|
@ -24,15 +24,16 @@ logger = logging.getLogger(__name__)
|
|||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
def setup_meshes(bobjs, cleanup=False, sharpness=False, shading=False):
|
||||
def setup_meshes(obj_names, cleanup=False, sharpness=False, shading=False):
|
||||
''' Setup raw meshes list after importing '''
|
||||
logger.info('Hightpoly meshes setup launched...')
|
||||
for bobj in bobjs:
|
||||
if not bobj.type == 'MESH':
|
||||
for obj_name in obj_names:
|
||||
obj = bpy.data.objects[obj_name]
|
||||
if not obj.type == 'MESH':
|
||||
continue
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
bobj.select_set(state=True)
|
||||
bpy.context.view_layer.objects.active = bobj
|
||||
obj.select_set(state=True)
|
||||
bpy.context.view_layer.objects.active = obj
|
||||
|
||||
if cleanup:
|
||||
# remove doubles
|
||||
|
@ -68,4 +69,4 @@ def setup_meshes(bobjs, cleanup=False, sharpness=False, shading=False):
|
|||
bpy.context.object.modifiers['triangulate'].keep_custom_normals = 1
|
||||
bpy.context.object.modifiers['triangulate'].show_expanded = 0
|
||||
|
||||
return logger.info('Hightpoly meshes setup finished!')
|
||||
return logger.info('Setup of %s hightpoly meshes is finished!', len(obj_names))
|
||||
|
|
|
@ -135,6 +135,6 @@ def parts_to_shells(hightpoly_part_names):
|
|||
bpy.ops.mesh.select_mode(type='FACE')
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
logger.info('Lowpoly shells created successfully!')
|
||||
logger.info('Generation of %s lowpoly shells is finished!', len(lowpoly_col.objects))
|
||||
|
||||
return lowpoly_col.objects
|
||||
return [obj.name for obj in lowpoly_col.objects]
|
||||
|
|
|
@ -131,28 +131,42 @@ def lcs_collections(root_lcs, lcs_objects):
|
|||
return root_lcs.children
|
||||
|
||||
|
||||
def restruct_hierarchy():
|
||||
def restruct_hierarchy(lcs_names):
|
||||
''' Execute restructurisation. '''
|
||||
|
||||
lcs_objects = bpy.data.collections[lcs_col_name].objects
|
||||
#lcs_objects = bpy.data.collections[lcs_col_name].objects
|
||||
lcs_objects = []
|
||||
root_lcs = None
|
||||
if lcs_names:
|
||||
for obj_name in lcs_names:
|
||||
if obj_name.endswith(root):
|
||||
root_lcs = bpy.data.objects[obj_name]
|
||||
lcs_objects.append(bpy.data.objects[obj_name])
|
||||
|
||||
main_locator = [obj for obj in bpy.data.objects if not obj.parent][0]
|
||||
root_lcs = [lcs for lcs in lcs_objects if lcs.name.endswith(root)][0]
|
||||
lcs_objects = [lcs for lcs in lcs_objects if lcs != root_lcs]
|
||||
root_locator = root_lcs.parent
|
||||
unparenting(root_lcs)
|
||||
round_transforms(root_lcs)
|
||||
unparenting(root_locator)
|
||||
parenting(root_lcs, root_locator)
|
||||
parenting(root_lcs, main_locator)
|
||||
main_locators = [obj for obj in bpy.data.objects if not obj.parent]
|
||||
if len(main_locators) > 1:
|
||||
logger.info('Scene has several main (root) locators! '
|
||||
'This may cause an error!')
|
||||
|
||||
retree_by_lcs(lcs_objects, root_lcs)
|
||||
lcs_constrainting(lcs_objects, root_lcs)
|
||||
if root_lcs:
|
||||
lcs_objects = [lcs for lcs in lcs_objects if lcs != root_lcs]
|
||||
root_locator = root_lcs.parent
|
||||
unparenting(root_lcs)
|
||||
round_transforms(root_lcs)
|
||||
unparenting(root_locator)
|
||||
parenting(root_lcs, root_locator)
|
||||
parenting(root_lcs, main_locators[0])
|
||||
|
||||
lcs_collections(root_lcs, lcs_objects)
|
||||
retree_by_lcs(lcs_objects, root_lcs)
|
||||
lcs_constrainting(lcs_objects, root_lcs)
|
||||
|
||||
# remove unused for now collection
|
||||
bpy.data.collections.remove(bpy.data.collections[hierarchy_col_name])
|
||||
lcs_collections(root_lcs, lcs_objects)
|
||||
|
||||
logger.info('Restructuring pipeline finished!')
|
||||
return lcs_objects
|
||||
# remove unused for now collection
|
||||
bpy.data.collections.remove(bpy.data.collections[hierarchy_col_name])
|
||||
|
||||
return logger.info('Restructuring pipeline finished!')
|
||||
else:
|
||||
return logger.info('Lost root LCS object!')
|
||||
else:
|
||||
return logger.info('Restructuring pipeline canceled!')
|
||||
|
|
|
@ -24,9 +24,10 @@ logger = logging.getLogger(__name__)
|
|||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
def uv_unwrap(objs, angle_limit=30):
|
||||
def uv_unwrap(obj_names, angle_limit=30):
|
||||
''' UV unwrapping and UV packing processing '''
|
||||
for obj in objs:
|
||||
for obj_name in obj_names:
|
||||
obj = bpy.data.objects[obj_name]
|
||||
obj.select_set(True)
|
||||
bpy.context.view_layer.objects.active = obj
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
@ -60,5 +61,5 @@ def uv_unwrap(objs, angle_limit=30):
|
|||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
obj.select_set(False)
|
||||
|
||||
logger.info('UV unwrapping and UV packing processing done successfully!')
|
||||
return objs
|
||||
return logger.info('UV setup of %s lowpoly meshes is finished!', len(obj_names))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue