Browse Source

Fix: Color Pallete node in IO

Joseph Brandenburg 2 months ago
parent
commit
5e0e149938
2 changed files with 22 additions and 11 deletions
  1. 21 8
      i_o.py
  2. 1 3
      utilities.py

+ 21 - 8
i_o.py

@@ -568,7 +568,7 @@ def export_to_json(trees, base_tree=None, path="", write_file=True, only_selecte
             from_socket_name, to_socket_name = link.from_socket.name, link.to_socket.name
 
             # get the indices of the sockets to be absolutely sure
-            for from_outoput_index, outp in enumerate(link.from_node.outputs):
+            for from_output_index, outp in enumerate(link.from_node.outputs):
                 # for some reason, 'is' does not return True no matter what...
                 # so we are gonn compare the memory address directly, this is stupid
                 if (outp.as_pointer() == link.from_socket.as_pointer()): break
@@ -662,7 +662,7 @@ def export_to_json(trees, base_tree=None, path="", write_file=True, only_selecte
 
                     from_node_name=in_node.get("name")
                     from_socket_id=in_sock["identifier"]
-                    from_outoput_index=in_sock["index"]
+                    from_output_index=in_sock["index"]
                     from_socket_name=in_node.get("name")
                 # parentheses matter here...
                 elif (only_selected and not (link.from_node.select and link.to_node.select)):
@@ -673,7 +673,7 @@ def export_to_json(trees, base_tree=None, path="", write_file=True, only_selecte
                            from_socket_id,
                            to_node_name,
                            to_socket_id,
-                           from_outoput_index,
+                           from_output_index,
                            to_input_index,
                            from_socket_name,
                            to_socket_name) ) # it's a tuple
@@ -1044,17 +1044,29 @@ def do_import(data, context, search_multi_files=False, filepath='', skip_existin
 #        from mantis.utilities import prRed, prWhite, prOrange, prGreen
         for name, propslist in nodes.items():
             bl_idname = propslist["bl_idname"]
+            do_socket_setup = True
             if bl_idname in NODES_REMOVED:
                 prWhite(f"INFO: Ignoring import of node {name} of type {bl_idname}; it has been removed.")
                 continue
             n = tree.nodes.new(bl_idname)
             if bl_idname in ["DeformerMorphTargetDeform"]:
                 n.inputs.remove(n.inputs[-1]) # get rid of the wildcard
-            if bl_idname in ['UtilityDeclareCollections']:
+            elif bl_idname in ['UtilityDeclareCollections']:
                 n.collection_declarations = propslist['collection_declarations']
                 n.update_interface()
-                continue
-            if n.bl_idname in [ "SchemaArrayInput",
+                do_socket_setup = False
+            elif bl_idname in ['InputColorSetPallete']:
+                # because the user can add and remove sockets, we need to match the names.
+                # since the user's sockets could be 000, 001, 003, 004 or something like
+                socket_names = list(propslist['outputs'].keys())
+                for i in range(len(propslist['outputs'])):
+                    socket = n.outputs.new("ColorSetSocket", socket_names[i] )
+                    color_values = propslist['outputs'][socket.name]['default_value']
+                    socket.active_color = color_values[:3]
+                    socket.normal_color = color_values[3:6]
+                    socket.selected_color = color_values[6:9]
+                do_socket_setup = False
+            elif bl_idname in [ "SchemaArrayInput",
                                 "SchemaArrayInputGet",
                                 "SchemaArrayInputAll",
                                 "SchemaArrayOutput",
@@ -1094,8 +1106,9 @@ def do_import(data, context, search_multi_files=False, filepath='', skip_existin
                 finally:
                     n.is_updating=False
             # set up sockets
-            setup_sockets(n, propslist, in_out="inputs")
-            setup_sockets(n, propslist, in_out="outputs")
+            if do_socket_setup:
+                setup_sockets(n, propslist, in_out="inputs")
+                setup_sockets(n, propslist, in_out="outputs")
             for p, v in propslist.items():
                 if p in ["node_tree",
                          "sockets",

+ 1 - 3
utilities.py

@@ -143,8 +143,6 @@ def get_socket_maps(node, force=False):
                         other_socket.bl_idname == 'NodeSocketUndefined':
                             continue # this one is bad
                     keep_sockets.append(other_socket)
-                # if len(keep_sockets) == 0:
-                #     keep_sockets = None
                 map[sock.identifier]= keep_sockets
             elif hasattr(sock, "default_value"):
                 if sock.get("default_value") is not None:
@@ -690,7 +688,7 @@ def link_node_containers(tree_path_names, link, local_nc, from_suffix='', to_suf
             raise e
     else:
         prRed(nc_from, nc_to, (*tree_path_names, from_name+from_suffix), (*tree_path_names, to_name+to_suffix))
-        raise RuntimeError(wrapRed("Link not connected: %s -> %s in tree %s" % (from_name, to_name, tree_path_names[-1])))
+        raise RuntimeError(wrapRed(f"Link not connected: {nc_from} -> {nc_to} in tree" ))
     
 def get_all_dependencies(nc):
     from .base_definitions import GraphError