浏览代码

basic boilerplate for component pack i/o

this commit sets up properties, operators, and menus for
the upcoming component pack improvements
it does not do much in the way of functionality, because that
requires bigger changes to make the I/O system more robust.
Joseph Brandenburg 2 月之前
父节点
当前提交
c6abca57b9
共有 4 个文件被更改,包括 56 次插入2 次删除
  1. 2 1
      .gitignore
  2. 2 0
      menu_classes.py
  3. 44 0
      ops_nodegroup.py
  4. 8 1
      preferences.py

+ 2 - 1
.gitignore

@@ -5,4 +5,5 @@ index.html
 index.json
 mantis.zip
 mantis.*.zip
-widgets/*
+widgets/*
+components/*

+ 2 - 0
menu_classes.py

@@ -14,6 +14,7 @@ def node_context_menu_draw(self, context):
     layout.operator("mantis.nodes_cleanup", text='Sort Selected Nodes')
     layout.operator("mantis.connect_nodes_to_input")
     layout.operator("mantis.select_nodes_of_type")
+    layout.operator("mantis.import_from_component_library")
     # layout.menu('NODE_MT_context_menu_mantis')
 
 class MantisActiveTreePanel(Panel):
@@ -49,3 +50,4 @@ class MantisActiveTreePanel(Panel):
         layout.operator("mantis.invalidate_node_tree")
         layout.operator("mantis.execute_node_tree")
         layout.operator("mantis.force_display_update", text='Force Display Update')
+        layout.operator("mantis.import_from_component_library")

+ 44 - 0
ops_nodegroup.py

@@ -977,6 +977,48 @@ class ConvertBezierCurveToNURBS(Operator):
             curve.data.splines.remove(bez_spline)
         return {"FINISHED"}
 
+def get_component_library_items(self, context):
+    import json
+    from .preferences import get_bl_addon_object
+    bl_mantis_addon = get_bl_addon_object()
+    return_value = [('NONE', 'None', 'None', 'ERROR', 0)]
+    component_name_and_path={}
+    if bl_mantis_addon:
+        widgets_path = bl_mantis_addon.preferences.ComponentsLibraryFolder
+        import os
+        for path_root, dirs, files, in os.walk(widgets_path):
+            for file in files:
+                if file.endswith('.rig'):
+                    filepath = os.path.join(path_root, file)
+                    with open(filepath, 'r', encoding='utf-8') as f:
+                        json_data = json.load(f)
+                        for tree_name in json_data.keys():
+                            component_name_and_path[tree_name] = os.path.join(path_root, file)
+    if component_name_and_path.keys():
+        return_value=[]
+        for i, (name, path) in enumerate(component_name_and_path.items()):
+            return_value.append( ((path+"|"+name).upper(), name, path + ': ' + name, 'NODE_TREE', i) )
+    return return_value
+
+class ImportFromComponentLibrary(Operator):
+    """Import a Mantis Component from your Component Library."""
+    bl_idname = "mantis.import_from_component_library"
+    bl_label = "Import From Component Library"
+    bl_options = {'REGISTER', 'UNDO'}
+    default_value  : bpy.props.EnumProperty(
+            items=get_component_library_items,
+            name="Component",
+            description="Which Component to Import",
+            default = 0,
+        )
+
+    @classmethod
+    def poll(cls, context):
+        return True # probably not best to do a True for this LOL
+
+    def execute(self, context):
+        return {"FINISHED"}
+    
 
 # this has to be down here for some reason. what a pain
 classes = [
@@ -1010,6 +1052,8 @@ classes = [
         CollectionRemoveOutput,
         # rigging utilities
         ConvertBezierCurveToNURBS,
+        # component library
+        ImportFromComponentLibrary,
         ]
 if (bpy.app.version >= (4, 4, 0)):
     classes.append(B4_4_0_Workaround_NodeTree_Interface_Update)

+ 8 - 1
preferences.py

@@ -69,8 +69,15 @@ class MantisPreferences(bpy.types.AddonPreferences):
         set=widget_library_idiot_test,
         subtype = 'FILE_PATH',
         default = os.path.join(dir_path, 'widgets'),)
+    ComponentsLibraryFolder:bpy.props.StringProperty(
+        name = "Widget Library Folder",
+        subtype = 'FILE_PATH',
+        default = os.path.join(dir_path, 'widgets'),)
+    ImportComponents:bpy.props.BoolProperty(default=False)
     
     def draw(self, context):
         layout = self.layout
         layout.label(text="Mantis Preferences")
-        layout.prop(self, "WidgetsLibraryFolder", icon='FILE_FOLDER')
+        layout.prop(self, "WidgetsLibraryFolder", icon='FILE_FOLDER')
+        layout.prop(self, "ComponentsLibraryFolder", icon='FILE_FOLDER')
+        layout.prop(self, "ImportComponents")