Prechádzať zdrojové kódy

Fix: Groups get wrong socket types

Joseph Brandenburg 1 mesiac pred
rodič
commit
1746d2c559
2 zmenil súbory, kde vykonal 24 pridanie a 16 odobranie
  1. 1 1
      i_o.py
  2. 23 15
      socket_definitions.py

+ 1 - 1
i_o.py

@@ -999,7 +999,7 @@ def do_import(data, context, search_multi_files=False, filepath='', skip_existin
                 if s_props["socket_type"] == "LayerMaskSocket":
                     continue
                 if (socket_type := s_props["socket_type"]) == "NodeSocketColor":
-                    socket_type = "VectorSocket"
+                    socket_type = "ColorSetSocket"
                 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!

+ 23 - 15
socket_definitions.py

@@ -118,38 +118,46 @@ cGeometry          = (0.000000, 0.672443, 0.366253, 1.000000)
 
 # OR make all of it a reference to the type of data within?
 
+def color_equivalent(color_a, color_b):
+    # because Blender's floating point numbers are not quite equal. pain.
+    from .base_definitions import FLOAT_EPSILON
+    for channel_a, channel_b in zip(color_a, color_b):
+        if abs(channel_a-channel_b) > FLOAT_EPSILON:
+            return False
+    return True
+
 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:
+    if color_equivalent(socket_color, cFloat):
         return "FloatSocket"
-    if socket_color == cColor:
+    if color_equivalent(socket_color, cColor):
         return "ColorSetSocket"
-    if socket_color == cVector:
+    if color_equivalent(socket_color, cVector):
         return "VectorSocket"
-    if socket_color == cInt:
+    if color_equivalent(socket_color, cInt):
         return "IntSocket"
-    if socket_color == cDriver:
+    if color_equivalent(socket_color, cDriver):
         return "DriverSocket"
-    if socket_color == cDriverVariable:
+    if color_equivalent(socket_color, cDriverVariable):
         return "DriverVariableSocket"
-    if socket_color == cFCurve:
+    if color_equivalent(socket_color, cFCurve):
         return "FCurveSocket"
-    if socket_color == cKeyframe:
+    if color_equivalent(socket_color, cKeyframe):
         return "KeyframeSocket"
-    if socket_color == cEnable:
+    if color_equivalent(socket_color, cEnable):
         return "BooleanSocket"
-    if socket_color == cDeformer:
+    if color_equivalent(socket_color, cDeformer):
         return "DeformerSocket"
-    if socket_color == cShapeKey:
+    if color_equivalent(socket_color, cShapeKey):
         return "MorphTargetSocket"
-    if socket_color == cMatrix:
+    if color_equivalent(socket_color, cMatrix):
         return "MatrixSocket"
-    if socket_color == cxForm:
+    if color_equivalent(socket_color, cxForm):
         return "xFormSocket"
-    if socket_color == cBool:
+    if color_equivalent(socket_color, cBool):
         return "BooleanSocket"
-    if socket_color == cBool3:
+    if color_equivalent(socket_color, cBool3):
         return "BooleanThreeTupleSocket"
     return "StringSocket"