浏览代码

Fix: creating some interface types cause error

This bug only occurred in the wildcards I implemented (schema, groups)
But I don't feel confident that the Blender-provided Group In/Out
nodes will continue to behave, they should eventually be replaced by a Mantis node.
Joseph Brandenburg 2 月之前
父节点
当前提交
6c8ba52099
共有 2 个文件被更改,包括 49 次插入0 次删除
  1. 48 0
      socket_definitions.py
  2. 1 0
      utilities.py

+ 48 - 0
socket_definitions.py

@@ -25,9 +25,19 @@ if bpy_version == (4,5,0): # THere is a bug that requires the socket type to inh
     from bpy.types import NodeSocketGeometry # so we will just inherit from NodeSocketGeometry
     class MantisSocket(NodeSocketGeometry, NodeSocket): # even though that is kinda silly
         is_valid_interface_type=False
+        @property
+        def interface_type(self):
+            return NodeSocketGeometry.bl_idname
 else:
     class MantisSocket(NodeSocket):
         is_valid_interface_type=False
+        @property
+        def interface_type(self):
+            # this is stupid but it is the fastest way to implement this
+            # TODO: refactor this, it should be a class property
+            return map_color_to_socket_type(self.color)
+
+
     
 
 from .utilities import (prRed, prGreen, prPurple, prWhite,
@@ -106,6 +116,44 @@ cGeometry          = (0.000000, 0.672443, 0.366253, 1.000000)
 
 # OR make all of it a reference to the type of data within?
 
+def map_color_to_socket_type(socket_color):
+    # let's get the socket type by color for e.g. wildcard sockets.
+    # for some reason I can't use match-case here. dumb.
+    if socket_color == cFloat:
+        return "FloatSocket"
+    if socket_color == cColor:
+        return "ColorSetSocket"
+    if socket_color == cVector:
+        return "VectorSocket"
+    if socket_color == cInt:
+        return "IntSocket"
+    if socket_color == cDriver:
+        return "DriverSocket"
+    if socket_color == cDriverVariable:
+        return "DriverVariableSocket"
+    if socket_color == cFCurve:
+        return "FCurveSocket"
+    if socket_color == cKeyframe:
+        return "KeyframeSocket"
+    if socket_color == cEnable:
+        return "BooleanSocket"
+    if socket_color == cBoneCollection:
+        return "KeyframeSocket"
+    if socket_color == cDeformer:
+        return "DeformerSocket"
+    if socket_color == cShapeKey:
+        return "MorphTargetSocket"
+    if socket_color == cMatrix:
+        return "MatrixSocket"
+    if socket_color == cxForm:
+        return "xFormSocket"
+    if socket_color == cBool:
+        return "BooleanSocket"
+    if socket_color == cBool3:
+        return "BooleanThreeTupleSocket"
+    return "StringSocket"
+
+
 # Hybrid approach: Make same-data, similar purpose have similar colors.
 from typing import List
 def TellClasses() -> List[MantisSocket]:

+ 1 - 0
utilities.py

@@ -196,6 +196,7 @@ def do_relink(node, s, map, in_out='INPUT', parent_name = ''):
                         socket = find_reroute_start_socket(sub_val)
                     else:
                         socket = find_reroute_start_socket(sub_val, track="FORWARD")
+                sock_type = socket.interface_type
                 name = unique_socket_name(node, socket, tree)
                 if parent_name:
                     interface_socket = update_interface(tree.interface, name, interface_in_out, sock_type, parent_name)