[Freecad] Реализован интерфейс добавления свойства (property) к фрейм объекту"

This commit is contained in:
brothermechanic 2023-04-12 09:19:17 +00:00 committed by Igor Brylyov
parent b744fe30a0
commit 7f13c0056f
4 changed files with 32 additions and 13 deletions

View file

@ -28,19 +28,24 @@ def empty_importer(path_json):
data = json.load(f) data = json.load(f)
pivot_name = data['label'] pivot_name = data['label']
pivot_parent_name = data['parent_label']
pivot_pose = data['placement'] pivot_pose = data['placement']
loc = tuple(pivot_pose['position'].values()) loc = tuple(pivot_pose['position'].values())
fori = tuple(pivot_pose['orientation'].values()) fori = tuple(pivot_pose['orientation'].values())
bori = (fori[3],)+fori[:3] bori = (fori[3],)+fori[:3]
bpy.ops.object.empty_add( 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)) location=(0, 0, 0), rotation=(0, 0, 0))
pivot_obj = bpy.context.active_object # or bpy.context.object pivot_obj = bpy.context.active_object # or bpy.context.object
pivot_obj.name = pivot_name pivot_obj.name = pivot_name
pivot_obj.rotation_mode = 'QUATERNION' pivot_obj.rotation_mode = 'QUATERNION'
pivot_obj.location = loc pivot_obj.location = loc
pivot_obj.rotation_quaternion = bori 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() f.close()
logger.info('Point %s imported without errors', pivot_name) logger.info('Point %s imported without errors', pivot_name)

View file

@ -37,13 +37,12 @@ class Frames(Workbench):
import Frames import Frames
self.framecommands = [ self.framecommands = [
"FrameCommand", "FrameCommand",
"ASM4StructureParsing",
"SelectedPartFrameCommand", "SelectedPartFrameCommand",
"AllPartFramesCommand", "AllPartFramesCommand",
"FeatureFrameCommand" "FeatureFrameCommand"
] ]
self.toolcommands = [ self.toolcommands = [
"ExportPartInfoAndFeaturesDialogueCommand", "ExportPlacementAndPropertiesCommand",
"ExportGazeboModels", "ExportGazeboModels",
"InsertGraspPose" "InsertGraspPose"
] ]

View file

@ -174,10 +174,14 @@ def spawnClassCommand(classname, function, resources):
def getLocalPartProps(obj): def getLocalPartProps(obj):
old_placement = obj.Placement old_placement = obj.Placement
obj_parent_label = ''
if obj.getParentGeoFeatureGroup():
obj_parent_label = obj.getParentGeoFeatureGroup().Label
# obj.Placement = FreeCAD.Placement() # obj.Placement = FreeCAD.Placement()
""" Part properties """ """ Part properties """
partprops = { partprops = {
"label": obj.Label, "label": obj.Label,
"parent_label": obj_parent_label,
"placement": placement2pose(old_placement), "placement": placement2pose(old_placement),
# "boundingbox": boundingBox2list(obj.Shape.BoundBox), # "boundingbox": boundingBox2list(obj.Shape.BoundBox),
# "volume": obj.Shape.Volume*1e-9, # "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") 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.""" """Spawns a dialogue window for exporting both."""
import Frames import Frames
s = FreeCADGui.Selection.getSelection() s = FreeCADGui.Selection.getSelection()
@ -534,11 +538,11 @@ uidir = os.path.join(FreeCAD.getUserAppDataDir(),
"Mod", __workbenchname__, "UI") "Mod", __workbenchname__, "UI")
icondir = os.path.join(uidir, "icons") icondir = os.path.join(uidir, "icons")
spawnClassCommand("ExportPartInfoAndFeaturesDialogueCommand", spawnClassCommand("ExportPlacementAndPropertiesCommand",
exportPartInfoAndFeaturesDialogue, exportPlacementAndProperties,
{"Pixmap": str(os.path.join(icondir, "parttojson.svg")), {"Pixmap": str(os.path.join(icondir, "parttojson.svg")),
"MenuText": "Export info and featureframes", "MenuText": "Export placement and properties",
"ToolTip": "Export part properties (placement, C.O.M) and feature frames"}) "ToolTip": "Export object placement and properties and feature frames"})
spawnClassCommand("ExportGazeboModels", spawnClassCommand("ExportGazeboModels",
exportGazeboModels, exportGazeboModels,

View file

@ -4,7 +4,7 @@ DESCRIPTION.
Convert and setup FreeCAD solid objects to 3d assets mesh files. Convert and setup FreeCAD solid objects to 3d assets mesh files.
Support Blender compiled as a Python Module only! Support Blender compiled as a Python Module only!
""" """
__version__ = "0.2" __version__ = "0.3"
import logging import logging
import os import os
@ -33,21 +33,32 @@ def freecad_asset_pipeline(fcstd_path,
blend_path=None, blend_path=None,
sdf_path=None): sdf_path=None):
""" Setup FreeCAD scene to CG asset """ """ Setup FreeCAD scene to CG asset """
# prepare blend file
remove_collections() remove_collections()
cleanup_orphan_data() cleanup_orphan_data()
# import objects
obj_importer(fcstd_path, tessellation) obj_importer(fcstd_path, tessellation)
if json_path is not None: # import lcs
for point in os.listdir(json_path): if json_path is None:
if point.endswith('.json'): json_path = os.path.dirname(fcstd_path)
empty_importer(point) 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: if sdf_path is not None:
sdf_mesh_selector(sdf_path) sdf_mesh_selector(sdf_path)
# retopo
asset_setup() asset_setup()
# save blender scene
if blend_path is not None: 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) bpy.ops.wm.save_as_mainfile(filepath=blend_path)
# export all objects # export all objects