diff --git a/cg/blender/import_fcstd/import_cad_objects.py b/cg/blender/import_fcstd/import_cad_objects.py index 6088851..49845ff 100644 --- a/cg/blender/import_fcstd/import_cad_objects.py +++ b/cg/blender/import_fcstd/import_cad_objects.py @@ -61,16 +61,16 @@ render = '_render' def obj_importer(filename, - tesselation_method="Standard", + tesselation_method='Standard', linear_deflection=0.1, angular_deflection=30.0, - max_edge_length=1, + fem_size=5.0, update=False, scene_placement=True, skiphidden=True, scale=0.001, select=True, - nonsolid_property = 'Robossembler_NonSolid'): + nonsolid_property='Robossembler_NonSolid'): ''' Reads a FreeCAD .FCStd file and creates Blender objects ''' @@ -126,16 +126,20 @@ def obj_importer(filename, shape = obj.Shape.copy() shape.Placement = obj.Placement.inverse().multiply(shape.Placement) meshfromshape = doc.addObject('Mesh::Feature','Mesh') - if tesselation_method == "Mefisto": + if tesselation_method == 'Standard': meshfromshape.Mesh = MeshPart.meshFromShape( Shape=shape, LinearDeflection=linear_deflection, AngularDeflection=math.radians(angular_deflection), Relative=False) - else: + elif tesselation_method == 'FEM': meshfromshape.Mesh = MeshPart.meshFromShape( - Shape=shape, - MaxLength=mefisto_max_length) + Shape=shape, + MaxLength=fem_size) + else: + raise TypeError('Wrong tesselation method! ' + 'Standard and FEM methods are supported only!') + break t = meshfromshape.Mesh.Topology verts = [[v.x,v.y,v.z] for v in t[0]] faces = t[1] @@ -192,17 +196,18 @@ def obj_importer(filename, # losted root lcs inlet workaround lcs_objects = lcs_collection.objects - root_lcs = [lcs for lcs in lcs_objects if lcs.name.endswith(root)][0] - root_inlet_name = ('{}{}'.format(root_lcs.name.split(root)[0], inlet)) - if not bpy.data.objects.get(root_inlet_name): - root_inlet = bpy.data.objects.new(root_inlet_name, None) - root_inlet.empty_display_type = 'ARROWS' - root_inlet.empty_display_size = 0.1 - root_inlet.show_in_front = True - root_inlet.location = root_lcs.location - root_inlet.rotation_euler = root_lcs.rotation_euler - root_inlet.parent = root_lcs.parent - lcs_collection.objects.link(root_inlet) + if lcs_objects: + root_lcs = [lcs for lcs in lcs_objects if lcs.name.endswith(root)][0] + root_inlet_name = ('{}{}'.format(root_lcs.name.split(root)[0], inlet)) + if not bpy.data.objects.get(root_inlet_name): + root_inlet = bpy.data.objects.new(root_inlet_name, None) + root_inlet.empty_display_type = 'ARROWS' + root_inlet.empty_display_size = 0.1 + root_inlet.show_in_front = True + root_inlet.location = root_lcs.location + root_inlet.rotation_euler = root_lcs.rotation_euler + root_inlet.parent = root_lcs.parent + lcs_collection.objects.link(root_inlet) FreeCAD.closeDocument(docname) diff --git a/cg/pipeline/freecad_to_asset.py b/cg/pipeline/freecad_to_asset.py index 3734113..96829be 100644 --- a/cg/pipeline/freecad_to_asset.py +++ b/cg/pipeline/freecad_to_asset.py @@ -59,9 +59,12 @@ hightpoly = '_hp' lowpoly = '_lp' render = '_render' + def freecad_asset_pipeline(fcstd_path, + tesselation_method, linear_deflection, angular_deflection, + fem_size, mesh_export_path=None, json_path=None, blend_path=None, @@ -72,12 +75,12 @@ def freecad_asset_pipeline(fcstd_path, remove_collections() cleanup_orphan_data() - # import objects, tesselation method can be "Standard" by default with linear/angular deflection parameters and Mefisto with max edge length parameter + # import objects objs_for_render = obj_importer(fcstd_path, - tesselation_method, - linear_deflection, - angular_deflection, - max_edge_length) + tesselation_method, + linear_deflection, + angular_deflection, + fem_size) # restructuring hierarchy by lcs points lcs_objects = restruct_hierarchy() @@ -132,10 +135,14 @@ if __name__ == '__main__': description='Convert and setup FreeCAD solid objects to 3d assets mesh files.') parser.add_argument( '--fcstd_path', type=str, help='Path to source FreeCAD scene', required=True) + parser.add_argument( + '--tesselation_method', type=str, help='Select tesselation method: Standard or FEM.', default='Standard', required=False) parser.add_argument( '--linear_deflection', type=float, help='Max linear distance error', default=0.1, required=False) parser.add_argument( '--angular_deflection', type=float, help='Max angular distance error', default=20.0, required=False) + parser.add_argument( + '--fem_size', type=float, help='For FEM method only! Finite element size in mm', default=1.0, required=False) parser.add_argument( '--mesh_export_path', type=str, help='Path for export meshes', required=False) parser.add_argument( @@ -147,8 +154,10 @@ if __name__ == '__main__': args = parser.parse_args() freecad_asset_pipeline(args.fcstd_path, + args.tesselation_method, args.linear_deflection, args.angular_deflection, + args.fem_size, args.mesh_export_path, args.json_path, args.blend_path,