Browse Source

v 0.12.6 Workaround Interface Bug in B4.5.0LTS

this commit adds a workaround for the interface bug
which is tracked here:
https://projects.blender.org/blender/blender/issues/142630
Joseph Brandenburg 3 tháng trước cách đây
mục cha
commit
e76aca0969
5 tập tin đã thay đổi với 62 bổ sung8 xóa
  1. 1 1
      __init__.py
  2. 7 2
      base_definitions.py
  3. 1 1
      blender_manifest.toml
  4. 27 2
      i_o.py
  5. 26 2
      utilities.py

+ 1 - 1
__init__.py

@@ -18,7 +18,7 @@ from .utilities import prRed
 
 MANTIS_VERSION_MAJOR=0
 MANTIS_VERSION_MINOR=12
-MANTIS_VERSION_SUB=5
+MANTIS_VERSION_SUB=6
 
 classLists = [module.TellClasses() for module in [
  link_nodes_ui,

+ 7 - 2
base_definitions.py

@@ -95,8 +95,11 @@ class MantisTree(NodeTree):
     # prev_execution_id:StringProperty(default='')
     mantis_version:IntVectorProperty(default=[0,9,2])
     # this prevents the node group from executing on the next depsgraph update
-    # because I don't always have control over when the dg update happens.
+    # because I don't always have control over when the dg upadte happens.
     prevent_next_exec:BoolProperty(default=False)
+
+    #added to work around a bug in 4.5.0 LTS
+    interface_helper : StringProperty(default='')
     
     parsed_tree={}
 
@@ -183,8 +186,10 @@ class SchemaTree(NodeTree):
     is_exporting:BoolProperty(default=False)
 
     mantis_version:IntVectorProperty(default=[0,9,2])
+    # see the note in MantisTree
+    interface_helper : StringProperty(default='')
 
-    if (bpy.app.version < (4, 4, 0)):  # in 4.4 this leads to a crash
+    if (bpy.app.version != (4, 4, 0)):  # in 4.4 this leads to a crash
         @classmethod
         def valid_socket_type(cls : NodeTree, socket_idname: str):
             return valid_interface_types(cls, socket_idname)

+ 1 - 1
blender_manifest.toml

@@ -3,7 +3,7 @@ schema_version = "1.0.0"
 # Example of manifest file for a Blender extension
 # Change the values according to your extension
 id = "mantis"
-version = "0.12.5"
+version = "0.12.6"
 name = "Mantis"
 tagline = "Mantis is a rigging nodes toolkit"
 maintainer = "Nodespaghetti <josephbburg@protonmail.com>"

+ 27 - 2
i_o.py

@@ -477,7 +477,32 @@ def do_import(data, context):
                     continue
                 if (socket_type := s_props["socket_type"]) == "NodeSocketColor":
                     socket_type = "VectorSocket"
-                sock = tree.interface.new_socket(s_props["name"], in_out=s_props["in_out"], socket_type=socket_type)
+                if bpy.app.version != (4,5,0):
+                    sock = tree.interface.new_socket(s_props["name"], in_out=s_props["in_out"], socket_type=socket_type)
+                else: # blender 4.5.0 LTS, have to workaround a bug!
+                    prRed("There is a bug in Blender 4.5.0 regarding node-group interface sockets. Working around it.")
+                    sock = tree.interface.new_socket(s_props["name"], in_out=s_props["in_out"], socket_type='NodeSocketGeometry')
+                    import json
+                    interface_helper = {} # initialize it if it is empty
+                    if tree.interface_helper: # may be empty, check here
+                        interface_helper = json.loads(tree.interface_helper)
+                    category =  s_props.get("parent", '')
+                    if category: # annoying
+                        category = category.name
+                    error_message= 'There is a bug in Blender 4.5.0 LTS, that is why these sockets are blue.'\
+                                   ' This will be fixed in future Blender versions.'
+                    interface_helper[sock.identifier] = {
+                            'name'             : sock.name,
+                            'identifier'       : sock.identifier,
+                            'in_out'           : sock.in_out,
+                            'socket_type'      : socket_type,
+                            'bl_socket_idname' : socket_type,
+                            'mantis_socket_category' : category,
+                            'description' : error_message,
+                        }
+                    sock.description = error_message # this tells the user why the socket looks weird.
+                    tree.interface_helper = json.dumps(interface_helper)
+
                 tree_sock_id_map[s_name] = sock.identifier
                 if not (socket_position := s_props.get('position')):
                     socket_position=default_position; default_position+=1
@@ -562,7 +587,7 @@ def do_import(data, context):
                         continue
                 try:
                     if s_val["is_output"]: # for some reason it thinks the index is a string?
-                        if n.bl_idname == "MantisSchemaGroup":
+                        if n.bl_idname in "MantisSchemaGroup":
                             n.is_updating = True
                             try:
                                 socket = n.outputs.new(s_val["bl_idname"], s_val["name"], identifier=s_id)

+ 26 - 2
utilities.py

@@ -215,14 +215,38 @@ def update_interface(interface, name, in_out, sock_type, parent_name):
     else:
         raise RuntimeError(wrapRed("Cannot add interface item to tree without specifying type."))
 
+
+def socket_add_workaround_for_4_5_0_LTS(item, socket_collection, multi):
+    import json
+    tree = item.id_data
+    interface_helper = json.loads(tree.interface_helper)
+    socket_info = interface_helper.get(item.identifier)
+    if not socket_info: raise RuntimeError(f"There has been an error adding the socket {item.name}")
+    s = socket_collection.new(
+        type=socket_info['bl_socket_idname'],
+        name=socket_info['name'],
+        identifier=item.identifier,
+        use_multi_input=multi, )
+    return s
+
+# D.node_groups['Rigging Nodes'].interface.new_socket('beans', description='the b word', socket_type='NodeSocketGeometry')
 #UGLY BAD REFACTOR
 def relink_socket_map_add_socket(node, socket_collection, item, in_out=None,):
+    from bpy.app import version as bpy_version
     if not in_out: in_out=item.in_out
     if node.bl_idname in ['MantisSchemaGroup'] and item.parent and item.parent.name == 'Array':
         multi = True if in_out == 'INPUT' else False
-        s = socket_collection.new(type=item.bl_socket_idname, name=item.name, identifier=item.identifier,  use_multi_input=multi)
+        # have to work around a bug in 4.5.0 that prevents me from declaring custom socket types
+        # I have arbitrarily chosen to use the NodeSocketGeometry type to signal that this one is affected.
+        if bpy_version == (4, 5, 0) and item.bl_socket_idname == 'NodeSocketGeometry':
+            s = socket_add_workaround_for_4_5_0_LTS(item, socket_collection, multi)
+        else:
+            s = socket_collection.new(type=item.bl_socket_idname, name=item.name, identifier=item.identifier,  use_multi_input=multi)
     else:
-        s = socket_collection.new(type=item.bl_socket_idname, name=item.name, identifier=item.identifier)
+        if bpy_version == (4, 5, 0) and item.bl_socket_idname == 'NodeSocketGeometry':
+            s = socket_add_workaround_for_4_5_0_LTS(item, socket_collection, multi=False,)
+        else:
+            s = socket_collection.new(type=item.bl_socket_idname, name=item.name, identifier=item.identifier)
     if item.parent.name == 'Array': s.display_shape = 'SQUARE_DOT'
     elif item.parent.name == 'Constant': s.display_shape='CIRCLE_DOT'
     return s