From 7f13c0056f8b2fcd10c7f3d42da91fed18a5d51d Mon Sep 17 00:00:00 2001 From: brothermechanic Date: Wed, 12 Apr 2023 09:19:17 +0000 Subject: [PATCH] =?UTF-8?q?[Freecad]=20=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80?= =?UTF-8?q?=D1=84=D0=B5=D0=B9=D1=81=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D0=B2=D0=BE=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B0=20(property)=20=D0=BA=20=D1=84=D1=80=D0=B5=D0=B9?= =?UTF-8?q?=D0=BC=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D1=83"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../import_fcstd/import_coordinate_point.py | 7 ++++++- cg/freecad/Frames/InitGui.py | 3 +-- cg/freecad/Frames/Tools.py | 14 ++++++++----- cg/pipeline/freecad_to_asset.py | 21 ++++++++++++++----- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/cg/blender/import_fcstd/import_coordinate_point.py b/cg/blender/import_fcstd/import_coordinate_point.py index f78119d..a880e38 100644 --- a/cg/blender/import_fcstd/import_coordinate_point.py +++ b/cg/blender/import_fcstd/import_coordinate_point.py @@ -28,19 +28,24 @@ def empty_importer(path_json): data = json.load(f) pivot_name = data['label'] + pivot_parent_name = data['parent_label'] pivot_pose = data['placement'] loc = tuple(pivot_pose['position'].values()) fori = tuple(pivot_pose['orientation'].values()) bori = (fori[3],)+fori[:3] bpy.ops.object.empty_add( - type='ARROWS', radius=0.01, align='WORLD', + type='ARROWS', radius=0.1, align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0)) pivot_obj = bpy.context.active_object # or bpy.context.object pivot_obj.name = pivot_name pivot_obj.rotation_mode = 'QUATERNION' pivot_obj.location = loc pivot_obj.rotation_quaternion = bori + pivot_obj.rotation_mode = 'XYZ' + + if pivot_parent_name: + pivot_obj.parent = bpy.data.objects[pivot_parent_name] f.close() logger.info('Point %s imported without errors', pivot_name) diff --git a/cg/freecad/Frames/InitGui.py b/cg/freecad/Frames/InitGui.py index bd7b0d9..536ec0a 100644 --- a/cg/freecad/Frames/InitGui.py +++ b/cg/freecad/Frames/InitGui.py @@ -37,13 +37,12 @@ class Frames(Workbench): import Frames self.framecommands = [ "FrameCommand", - "ASM4StructureParsing", "SelectedPartFrameCommand", "AllPartFramesCommand", "FeatureFrameCommand" ] self.toolcommands = [ - "ExportPartInfoAndFeaturesDialogueCommand", + "ExportPlacementAndPropertiesCommand", "ExportGazeboModels", "InsertGraspPose" ] diff --git a/cg/freecad/Frames/Tools.py b/cg/freecad/Frames/Tools.py index 5c8d9c3..484706d 100644 --- a/cg/freecad/Frames/Tools.py +++ b/cg/freecad/Frames/Tools.py @@ -174,10 +174,14 @@ def spawnClassCommand(classname, function, resources): def getLocalPartProps(obj): old_placement = obj.Placement + obj_parent_label = '' + if obj.getParentGeoFeatureGroup(): + obj_parent_label = obj.getParentGeoFeatureGroup().Label # obj.Placement = FreeCAD.Placement() """ Part properties """ partprops = { "label": obj.Label, + "parent_label": obj_parent_label, "placement": placement2pose(old_placement), # "boundingbox": boundingBox2list(obj.Shape.BoundBox), # "volume": obj.Shape.Volume*1e-9, @@ -465,7 +469,7 @@ def exportFeatureFramesDialogue(): FreeCAD.Console.PrintMessage("Feature frames of " + str(unique_selected[0].Label) + " exported to " + str(ofile) + "\n") -def exportPartInfoAndFeaturesDialogue(): +def exportPlacementAndProperties(): """Spawns a dialogue window for exporting both.""" import Frames s = FreeCADGui.Selection.getSelection() @@ -534,11 +538,11 @@ uidir = os.path.join(FreeCAD.getUserAppDataDir(), "Mod", __workbenchname__, "UI") icondir = os.path.join(uidir, "icons") -spawnClassCommand("ExportPartInfoAndFeaturesDialogueCommand", - exportPartInfoAndFeaturesDialogue, +spawnClassCommand("ExportPlacementAndPropertiesCommand", + exportPlacementAndProperties, {"Pixmap": str(os.path.join(icondir, "parttojson.svg")), - "MenuText": "Export info and featureframes", - "ToolTip": "Export part properties (placement, C.O.M) and feature frames"}) + "MenuText": "Export placement and properties", + "ToolTip": "Export object placement and properties and feature frames"}) spawnClassCommand("ExportGazeboModels", exportGazeboModels, diff --git a/cg/pipeline/freecad_to_asset.py b/cg/pipeline/freecad_to_asset.py index ffddd79..138a0eb 100644 --- a/cg/pipeline/freecad_to_asset.py +++ b/cg/pipeline/freecad_to_asset.py @@ -4,7 +4,7 @@ DESCRIPTION. Convert and setup FreeCAD solid objects to 3d assets mesh files. Support Blender compiled as a Python Module only! """ -__version__ = "0.2" +__version__ = "0.3" import logging import os @@ -33,21 +33,32 @@ def freecad_asset_pipeline(fcstd_path, blend_path=None, sdf_path=None): """ Setup FreeCAD scene to CG asset """ + # prepare blend file remove_collections() cleanup_orphan_data() + + # import objects obj_importer(fcstd_path, tessellation) - if json_path is not None: - for point in os.listdir(json_path): - if point.endswith('.json'): - empty_importer(point) + # import lcs + if json_path is None: + json_path = os.path.dirname(fcstd_path) + for f in os.listdir(os.path.dirname(fcstd_path)): + if f.endswith('.json'): + json_file = os.path.join(json_path, f) + empty_importer(json_file) + # sdf setup WIP if sdf_path is not None: sdf_mesh_selector(sdf_path) + # retopo asset_setup() + # save 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)) bpy.ops.wm.save_as_mainfile(filepath=blend_path) # export all objects