|
@@ -1,93 +1,91 @@
|
|
|
from .utilities import prRed, prGreen, prPurple, prWhite, prOrange, \
|
|
from .utilities import prRed, prGreen, prPurple, prWhite, prOrange, \
|
|
|
wrapRed, wrapGreen, wrapPurple, wrapWhite, wrapOrange
|
|
wrapRed, wrapGreen, wrapPurple, wrapWhite, wrapOrange
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
-def grp_node_reroute_common(nc, nc_to, all_nc):
|
|
|
|
|
|
|
+def grp_node_reroute_common(mantis_node, to_mantis_node, all_mantis_nodes):
|
|
|
# we need to do this: go to the to-node
|
|
# we need to do this: go to the to-node
|
|
|
# then reroute the link in the to_node all the way to the beginning
|
|
# then reroute the link in the to_node all the way to the beginning
|
|
|
# so that the number of links in "real" nodes is unchanged
|
|
# so that the number of links in "real" nodes is unchanged
|
|
|
# then the links in the dummy nodes need to be deleted
|
|
# then the links in the dummy nodes need to be deleted
|
|
|
- for inp_name, inp in nc.inputs.items():
|
|
|
|
|
|
|
+ for inp_name, inp in mantis_node.inputs.items():
|
|
|
# assume each input socket only has one input for now
|
|
# assume each input socket only has one input for now
|
|
|
if inp.is_connected:
|
|
if inp.is_connected:
|
|
|
while (inp.links):
|
|
while (inp.links):
|
|
|
in_link = inp.links.pop()
|
|
in_link = inp.links.pop()
|
|
|
- from_nc = in_link.from_node
|
|
|
|
|
|
|
+ from_mantis_node = in_link.from_node
|
|
|
from_socket = in_link.from_socket
|
|
from_socket = in_link.from_socket
|
|
|
links = []
|
|
links = []
|
|
|
- from_links = from_nc.outputs[from_socket].links.copy()
|
|
|
|
|
|
|
+ from_links = from_mantis_node.outputs[from_socket].links.copy()
|
|
|
while(from_links):
|
|
while(from_links):
|
|
|
from_link = from_links.pop()
|
|
from_link = from_links.pop()
|
|
|
if from_link == in_link:
|
|
if from_link == in_link:
|
|
|
from_link.die()
|
|
from_link.die()
|
|
|
continue # DELETE the dummy node link
|
|
continue # DELETE the dummy node link
|
|
|
links.append(from_link)
|
|
links.append(from_link)
|
|
|
- from_nc.outputs[from_socket].links = links
|
|
|
|
|
- down = nc_to.outputs[inp_name]
|
|
|
|
|
|
|
+ from_mantis_node.outputs[from_socket].links = links
|
|
|
|
|
+ down = to_mantis_node.outputs[inp_name]
|
|
|
for downlink in down.links:
|
|
for downlink in down.links:
|
|
|
- downlink.from_node = from_nc
|
|
|
|
|
|
|
+ downlink.from_node = from_mantis_node
|
|
|
downlink.from_socket = from_socket
|
|
downlink.from_socket = from_socket
|
|
|
- from_nc.outputs[from_socket].links.append(downlink)
|
|
|
|
|
|
|
+ from_mantis_node.outputs[from_socket].links.append(downlink)
|
|
|
if hasattr(downlink.to_node, "reroute_links"):
|
|
if hasattr(downlink.to_node, "reroute_links"):
|
|
|
- downlink.to_node.reroute_links(downlink.to_node, all_nc)
|
|
|
|
|
|
|
+ downlink.to_node.reroute_links(downlink.to_node, all_mantis_nodes)
|
|
|
in_link.die()
|
|
in_link.die()
|
|
|
|
|
|
|
|
-def reroute_links_grp(nc, all_nc):
|
|
|
|
|
- if nc.inputs:
|
|
|
|
|
- if (nc_to := all_nc.get( ( *nc.signature, "NodeGroupInput") )):
|
|
|
|
|
- grp_node_reroute_common(nc, nc_to, all_nc)
|
|
|
|
|
|
|
+def reroute_links_grp(mantis_node, all_mantis_nodes):
|
|
|
|
|
+ if mantis_node.inputs:
|
|
|
|
|
+ if (to_mantis_node := all_mantis_nodes.get( ( *mantis_node.signature, "NodeGroupInput") )):
|
|
|
|
|
+ grp_node_reroute_common(mantis_node, to_mantis_node, all_mantis_nodes)
|
|
|
else:
|
|
else:
|
|
|
raise RuntimeError("internal error: failed to enter a node group ")
|
|
raise RuntimeError("internal error: failed to enter a node group ")
|
|
|
|
|
|
|
|
-def reroute_links_grpout(nc, all_nc):
|
|
|
|
|
- if (nc_to := all_nc.get( ( *nc.signature[:-1],) )):
|
|
|
|
|
- grp_node_reroute_common(nc, nc_to, all_nc)
|
|
|
|
|
|
|
+def reroute_links_grpout(mantis_node, all_mantis_nodes):
|
|
|
|
|
+ if (to_mantis_node := all_mantis_nodes.get( ( *mantis_node.signature[:-1],) )):
|
|
|
|
|
+ grp_node_reroute_common(mantis_node, to_mantis_node, all_mantis_nodes)
|
|
|
else:
|
|
else:
|
|
|
raise RuntimeError("error leaving a node group (maybe you are running the tree from inside a node group?)")
|
|
raise RuntimeError("error leaving a node group (maybe you are running the tree from inside a node group?)")
|
|
|
|
|
|
|
|
# FIXME I don't think these signatures are unique.
|
|
# FIXME I don't think these signatures are unique.
|
|
|
-def insert_lazy_parents(nc):
|
|
|
|
|
|
|
+def insert_lazy_parents(mantis_node):
|
|
|
from .link_nodes import LinkInherit
|
|
from .link_nodes import LinkInherit
|
|
|
from .base_definitions import NodeLink
|
|
from .base_definitions import NodeLink
|
|
|
- inherit_nc = None
|
|
|
|
|
- if nc.inputs["Relationship"].is_connected:
|
|
|
|
|
- link = nc.inputs["Relationship"].links[0]
|
|
|
|
|
- # print(nc)
|
|
|
|
|
- from_nc = link.from_node
|
|
|
|
|
- if from_nc.node_type in ["XFORM"] and link.from_socket in ["xForm Out"]:
|
|
|
|
|
- inherit_nc = LinkInherit(("MANTIS_AUTOGENERATED", *nc.signature[1:], "LAZY_INHERIT"), nc.base_tree)
|
|
|
|
|
- for from_link in from_nc.outputs["xForm Out"].links:
|
|
|
|
|
- if from_link.to_node == nc and from_link.to_socket == "Relationship":
|
|
|
|
|
|
|
+ inherit_mantis_node = None
|
|
|
|
|
+ if mantis_node.inputs["Relationship"].is_connected:
|
|
|
|
|
+ link = mantis_node.inputs["Relationship"].links[0]
|
|
|
|
|
+ # print(mantis_node)
|
|
|
|
|
+ from_mantis_node = link.from_node
|
|
|
|
|
+ if from_mantis_node.node_type in ["XFORM"] and link.from_socket in ["xForm Out"]:
|
|
|
|
|
+ inherit_mantis_node = LinkInherit(("MANTIS_AUTOGENERATED", *mantis_node.signature[1:], "LAZY_INHERIT"), mantis_node.base_tree)
|
|
|
|
|
+ for from_link in from_mantis_node.outputs["xForm Out"].links:
|
|
|
|
|
+ if from_link.to_node == mantis_node and from_link.to_socket == "Relationship":
|
|
|
break # this is it
|
|
break # this is it
|
|
|
- from_link.to_node = inherit_nc; from_link.to_socket="Parent"
|
|
|
|
|
|
|
+ from_link.to_node = inherit_mantis_node; from_link.to_socket="Parent"
|
|
|
from_link.to_node.inputs[from_link.to_socket].is_linked=True
|
|
from_link.to_node.inputs[from_link.to_socket].is_linked=True
|
|
|
|
|
|
|
|
links=[]
|
|
links=[]
|
|
|
- while (nc.inputs["Relationship"].links):
|
|
|
|
|
- to_link = nc.inputs["Relationship"].links.pop()
|
|
|
|
|
- if to_link.from_node == from_nc and to_link.from_socket == "xForm Out":
|
|
|
|
|
|
|
+ while (mantis_node.inputs["Relationship"].links):
|
|
|
|
|
+ to_link = mantis_node.inputs["Relationship"].links.pop()
|
|
|
|
|
+ if to_link.from_node == from_mantis_node and to_link.from_socket == "xForm Out":
|
|
|
continue # don't keep this one
|
|
continue # don't keep this one
|
|
|
links.append(to_link)
|
|
links.append(to_link)
|
|
|
to_link.from_node.outputs[from_link.from_socket].is_linked=True
|
|
to_link.from_node.outputs[from_link.from_socket].is_linked=True
|
|
|
|
|
|
|
|
- nc.inputs["Relationship"].links=links
|
|
|
|
|
- link=NodeLink(from_node=inherit_nc, from_socket="Inheritance", to_node=nc, to_socket="Relationship")
|
|
|
|
|
- inherit_nc.inputs["Parent"].links.append(from_link)
|
|
|
|
|
|
|
+ mantis_node.inputs["Relationship"].links=links
|
|
|
|
|
+ link=NodeLink(from_node=inherit_mantis_node, from_socket="Inheritance", to_node=mantis_node, to_socket="Relationship")
|
|
|
|
|
+ inherit_mantis_node.inputs["Parent"].links.append(from_link)
|
|
|
|
|
|
|
|
- inherit_nc.parameters = {
|
|
|
|
|
|
|
+ inherit_mantis_node.parameters = {
|
|
|
"Parent":None,
|
|
"Parent":None,
|
|
|
"Inherit Rotation":True,
|
|
"Inherit Rotation":True,
|
|
|
"Inherit Scale":'FULL',
|
|
"Inherit Scale":'FULL',
|
|
|
"Connected":False,
|
|
"Connected":False,
|
|
|
}
|
|
}
|
|
|
# because the from node may have already been done.
|
|
# because the from node may have already been done.
|
|
|
- init_connections(from_nc)
|
|
|
|
|
- init_dependencies(from_nc)
|
|
|
|
|
- init_connections(inherit_nc)
|
|
|
|
|
- init_dependencies(inherit_nc)
|
|
|
|
|
- return inherit_nc
|
|
|
|
|
|
|
+ init_connections(from_mantis_node)
|
|
|
|
|
+ init_dependencies(from_mantis_node)
|
|
|
|
|
+ init_connections(inherit_mantis_node)
|
|
|
|
|
+ init_dependencies(inherit_mantis_node)
|
|
|
|
|
+ return inherit_mantis_node
|
|
|
|
|
|
|
|
# *** # *** # *** # *** # *** # *** # *** # *** # *** # *** # *** # *** # *** # *** #
|
|
# *** # *** # *** # *** # *** # *** # *** # *** # *** # *** # *** # *** # *** # *** #
|
|
|
# DATA FROM NODES #
|
|
# DATA FROM NODES #
|
|
@@ -97,10 +95,10 @@ from .base_definitions import replace_types, NodeSocket
|
|
|
|
|
|
|
|
def autogen_node(base_tree, ui_socket, signature, mContext):
|
|
def autogen_node(base_tree, ui_socket, signature, mContext):
|
|
|
mantis_node=None
|
|
mantis_node=None
|
|
|
- from .utilities import gen_nc_input_for_data
|
|
|
|
|
- # nc_cls = gen_nc_input_for_data(ui_socket)
|
|
|
|
|
- # if (nc_cls):
|
|
|
|
|
- from .internal_containers import AutoGenNode
|
|
|
|
|
|
|
+ from .utilities import gen_mantis_node_input_for_data
|
|
|
|
|
+ # mantis_class = gen_mantis_node_input_for_data(ui_socket)
|
|
|
|
|
+ # if (mantis_class):
|
|
|
|
|
+ from .internal_nodes import AutoGenNode
|
|
|
mantis_node = AutoGenNode(signature, base_tree)
|
|
mantis_node = AutoGenNode(signature, base_tree)
|
|
|
mantis_node.mContext = mContext
|
|
mantis_node.mContext = mContext
|
|
|
mantis_node.outputs.init_sockets([ui_socket.name])
|
|
mantis_node.outputs.init_sockets([ui_socket.name])
|
|
@@ -109,31 +107,31 @@ def autogen_node(base_tree, ui_socket, signature, mContext):
|
|
|
|
|
|
|
|
# TODO: investigate whether I can set the properties in the downstream nodes directly.
|
|
# TODO: investigate whether I can set the properties in the downstream nodes directly.
|
|
|
# I am doing this in Schema Solver and it seems to work quite efficiently.
|
|
# I am doing this in Schema Solver and it seems to work quite efficiently.
|
|
|
-def make_connections_to_ng_dummy(base_tree, tree_path_names, local_nc, all_nc, nc_to):
|
|
|
|
|
|
|
+def make_connections_to_ng_dummy(base_tree, tree_path_names, local_mantis_nodes, all_mantis_nodes, to_mantis_node):
|
|
|
from .socket_definitions import no_default_value
|
|
from .socket_definitions import no_default_value
|
|
|
- for inp in nc_to.prototype.inputs:
|
|
|
|
|
|
|
+ for inp in to_mantis_node.ui_node.inputs:
|
|
|
if inp.bl_idname in no_default_value:
|
|
if inp.bl_idname in no_default_value:
|
|
|
continue
|
|
continue
|
|
|
- nc_from = None
|
|
|
|
|
|
|
+ from_mantis_node = None
|
|
|
to_s = inp.identifier
|
|
to_s = inp.identifier
|
|
|
if not inp.is_linked: # make an autogenerated NC for the inputs of the group node
|
|
if not inp.is_linked: # make an autogenerated NC for the inputs of the group node
|
|
|
# This can be run inside schema. Make it unique with uuid() to be safe.
|
|
# This can be run inside schema. Make it unique with uuid() to be safe.
|
|
|
from uuid import uuid4
|
|
from uuid import uuid4
|
|
|
- signature = ("MANTIS_AUTOGENERATED", *tree_path_names, nc_to.ui_signature[-1], inp.name, inp.identifier, str(uuid4()))
|
|
|
|
|
- nc_from = all_nc.get(signature) # creating this without checking and
|
|
|
|
|
|
|
+ signature = ("MANTIS_AUTOGENERATED", *tree_path_names, to_mantis_node.ui_signature[-1], inp.name, inp.identifier, str(uuid4()))
|
|
|
|
|
+ from_mantis_node = all_mantis_nodes.get(signature) # creating this without checking and
|
|
|
# using UUID signature leads to TERRIBLE CONFUSING BUGS.
|
|
# using UUID signature leads to TERRIBLE CONFUSING BUGS.
|
|
|
- if nc_from is None:
|
|
|
|
|
- nc_from = autogen_node(base_tree, inp, signature, nc_to.mContext)
|
|
|
|
|
- from .node_container_common import get_socket_value
|
|
|
|
|
- if nc_from: # autogen can fail and we should catch it.
|
|
|
|
|
- nc_from.parameters = {inp.name:get_socket_value(inp)}
|
|
|
|
|
- local_nc[signature] = nc_from; all_nc[signature] = nc_from
|
|
|
|
|
- nc_from.outputs[inp.name].connect(node=nc_to, socket=to_s, sort_id=0)
|
|
|
|
|
|
|
+ if from_mantis_node is None:
|
|
|
|
|
+ from_mantis_node = autogen_node(base_tree, inp, signature, to_mantis_node.mContext)
|
|
|
|
|
+ from .node_common import get_socket_value
|
|
|
|
|
+ if from_mantis_node: # autogen can fail and we should catch it.
|
|
|
|
|
+ from_mantis_node.parameters = {inp.name:get_socket_value(inp)}
|
|
|
|
|
+ local_mantis_nodes[signature] = from_mantis_node; all_mantis_nodes[signature] = from_mantis_node
|
|
|
|
|
+ from_mantis_node.outputs[inp.name].connect(node=to_mantis_node, socket=to_s, sort_id=0)
|
|
|
else:
|
|
else:
|
|
|
prRed("No available auto-generated class for input %s in %s" % (inp.name, np.name))
|
|
prRed("No available auto-generated class for input %s in %s" % (inp.name, np.name))
|
|
|
|
|
|
|
|
-def gen_node_containers(base_tree, current_tree, tree_path_names, all_nc, local_nc, dummy_nodes, group_nodes, schema_nodes ):
|
|
|
|
|
- from .internal_containers import DummyNode
|
|
|
|
|
|
|
+def gen_mantis_nodes(base_tree, current_tree, tree_path_names, all_mantis_nodes, local_mantis_nodes, dummy_nodes, group_nodes, schema_nodes ):
|
|
|
|
|
+ from .internal_nodes import DummyNode
|
|
|
for ui_node in current_tree.nodes:
|
|
for ui_node in current_tree.nodes:
|
|
|
# HACK I found that this isn't being set sometimes. I wonder why? It makes the most sense to do this here.
|
|
# HACK I found that this isn't being set sometimes. I wonder why? It makes the most sense to do this here.
|
|
|
if hasattr(ui_node, 'initialized'): ui_node.initialized=True
|
|
if hasattr(ui_node, 'initialized'): ui_node.initialized=True
|
|
@@ -144,41 +142,41 @@ def gen_node_containers(base_tree, current_tree, tree_path_names, all_nc, local_
|
|
|
# we only want ONE dummy in/out per tree_path, so use the bl_idname to make a Dummy node
|
|
# we only want ONE dummy in/out per tree_path, so use the bl_idname to make a Dummy node
|
|
|
sig = (None, *tree_path_names, ui_node.bl_idname)
|
|
sig = (None, *tree_path_names, ui_node.bl_idname)
|
|
|
ui_sig = (None, *tree_path_names, ui_node.name)
|
|
ui_sig = (None, *tree_path_names, ui_node.name)
|
|
|
- if not local_nc.get(sig):
|
|
|
|
|
- nc = DummyNode( signature=sig , base_tree=base_tree, prototype=ui_node, ui_signature=ui_sig )
|
|
|
|
|
- local_nc[sig] = nc; all_nc[sig] = nc; dummy_nodes[sig] = nc
|
|
|
|
|
|
|
+ if not local_mantis_nodes.get(sig):
|
|
|
|
|
+ mantis_node = DummyNode( signature=sig , base_tree=base_tree, ui_node=ui_node, ui_signature=ui_sig )
|
|
|
|
|
+ local_mantis_nodes[sig] = mantis_node; all_mantis_nodes[sig] = mantis_node; dummy_nodes[sig] = mantis_node
|
|
|
if ui_node.bl_idname in ["NodeGroupOutput"]:
|
|
if ui_node.bl_idname in ["NodeGroupOutput"]:
|
|
|
- nc.reroute_links = reroute_links_grpout
|
|
|
|
|
|
|
+ mantis_node.reroute_links = reroute_links_grpout
|
|
|
elif ui_node.bl_idname in ["MantisNodeGroup", "MantisSchemaGroup"]:
|
|
elif ui_node.bl_idname in ["MantisNodeGroup", "MantisSchemaGroup"]:
|
|
|
- nc = DummyNode( signature= (sig := (None, *tree_path_names, ui_node.name) ), base_tree=base_tree, prototype=ui_node )
|
|
|
|
|
- local_nc[sig] = nc; all_nc[sig] = nc; dummy_nodes[sig] = nc
|
|
|
|
|
- make_connections_to_ng_dummy(base_tree, tree_path_names, local_nc, all_nc, nc)
|
|
|
|
|
|
|
+ mantis_node = DummyNode( signature= (sig := (None, *tree_path_names, ui_node.name) ), base_tree=base_tree, ui_node=ui_node )
|
|
|
|
|
+ local_mantis_nodes[sig] = mantis_node; all_mantis_nodes[sig] = mantis_node; dummy_nodes[sig] = mantis_node
|
|
|
|
|
+ make_connections_to_ng_dummy(base_tree, tree_path_names, local_mantis_nodes, all_mantis_nodes, mantis_node)
|
|
|
if ui_node.bl_idname == "MantisNodeGroup":
|
|
if ui_node.bl_idname == "MantisNodeGroup":
|
|
|
- group_nodes.append(nc)
|
|
|
|
|
- nc.reroute_links = reroute_links_grp
|
|
|
|
|
|
|
+ group_nodes.append(mantis_node)
|
|
|
|
|
+ mantis_node.reroute_links = reroute_links_grp
|
|
|
else:
|
|
else:
|
|
|
- group_nodes.append(nc)
|
|
|
|
|
- schema_nodes[sig] = nc
|
|
|
|
|
|
|
+ group_nodes.append(mantis_node)
|
|
|
|
|
+ schema_nodes[sig] = mantis_node
|
|
|
# if it wasn't the types we ignore or the types we make a Dummy for, use this to catch all non-special cases.
|
|
# if it wasn't the types we ignore or the types we make a Dummy for, use this to catch all non-special cases.
|
|
|
- elif (nc_cls := ui_node.mantis_class):
|
|
|
|
|
|
|
+ elif (mantis_class := ui_node.mantis_class):
|
|
|
sig = (None, *tree_path_names, ui_node.name)
|
|
sig = (None, *tree_path_names, ui_node.name)
|
|
|
if ui_node.bl_idname in replace_types:
|
|
if ui_node.bl_idname in replace_types:
|
|
|
sig = (None, *tree_path_names, ui_node.bl_idname)
|
|
sig = (None, *tree_path_names, ui_node.bl_idname)
|
|
|
- if local_nc.get(sig):
|
|
|
|
|
|
|
+ if local_mantis_nodes.get(sig):
|
|
|
continue # already made
|
|
continue # already made
|
|
|
- nc = nc_cls( sig , base_tree)
|
|
|
|
|
- local_nc[sig] = nc; all_nc[sig] = nc
|
|
|
|
|
- nc.ui_signature = (*nc.ui_signature[:-1], ui_node.name) # just to ensure it points to a real node.
|
|
|
|
|
|
|
+ mantis_node = mantis_class( sig , base_tree)
|
|
|
|
|
+ local_mantis_nodes[sig] = mantis_node; all_mantis_nodes[sig] = mantis_node
|
|
|
|
|
+ mantis_node.ui_signature = (*mantis_node.ui_signature[:-1], ui_node.name) # just to ensure it points to a real node.
|
|
|
else:
|
|
else:
|
|
|
- nc = None
|
|
|
|
|
- prRed(f"Can't make nc for.. {ui_node.bl_idname}")
|
|
|
|
|
|
|
+ mantis_node = None
|
|
|
|
|
+ prRed(f"Can't make mantis_node for.. {ui_node.bl_idname}")
|
|
|
# this should be done at init
|
|
# this should be done at init
|
|
|
- if nc.signature[0] not in ['MANTIS_AUTOGENERATED'] and nc.node_type not in ['SCHEMA', 'DUMMY', 'DUMMY_SCHEMA']:
|
|
|
|
|
- nc.fill_parameters()
|
|
|
|
|
|
|
+ if mantis_node.signature[0] not in ['MANTIS_AUTOGENERATED'] and mantis_node.node_type not in ['SCHEMA', 'DUMMY', 'DUMMY_SCHEMA']:
|
|
|
|
|
+ mantis_node.fill_parameters()
|
|
|
|
|
|
|
|
-def data_from_tree(base_tree, tree_path, dummy_nodes, all_nc, all_schema):#
|
|
|
|
|
|
|
+def data_from_tree(base_tree, tree_path, dummy_nodes, all_mantis_nodes, all_schema):#
|
|
|
# TODO: it should be relatively easy to make this use a while loop instead of recursion.
|
|
# TODO: it should be relatively easy to make this use a while loop instead of recursion.
|
|
|
- local_nc, group_nodes = {}, []
|
|
|
|
|
|
|
+ local_mantis_nodes, group_nodes = {}, []
|
|
|
tree_path_names = [tree.name for tree in tree_path if hasattr(tree, "name")]
|
|
tree_path_names = [tree.name for tree in tree_path if hasattr(tree, "name")]
|
|
|
if tree_path[-1]:
|
|
if tree_path[-1]:
|
|
|
current_tree = tree_path[-1].node_tree # this may be None.
|
|
current_tree = tree_path[-1].node_tree # this may be None.
|
|
@@ -188,15 +186,15 @@ def data_from_tree(base_tree, tree_path, dummy_nodes, all_nc, all_schema):#
|
|
|
if current_tree: # the node-group may not have a tree set - if so, ignore it.
|
|
if current_tree: # the node-group may not have a tree set - if so, ignore it.
|
|
|
from .utilities import clear_reroutes
|
|
from .utilities import clear_reroutes
|
|
|
links = clear_reroutes(list(current_tree.links))
|
|
links = clear_reroutes(list(current_tree.links))
|
|
|
- gen_node_containers(base_tree, current_tree, tree_path_names, all_nc, local_nc, dummy_nodes, group_nodes, all_schema)
|
|
|
|
|
|
|
+ gen_mantis_nodes(base_tree, current_tree, tree_path_names, all_mantis_nodes, local_mantis_nodes, dummy_nodes, group_nodes, all_schema)
|
|
|
|
|
|
|
|
- from .utilities import link_node_containers
|
|
|
|
|
|
|
+ from .utilities import link_mantis_nodes
|
|
|
for link in links:
|
|
for link in links:
|
|
|
- link_node_containers((None, *tree_path_names), link, local_nc)
|
|
|
|
|
|
|
+ link_mantis_nodes((None, *tree_path_names), link, local_mantis_nodes)
|
|
|
# Now, descend into the Node Groups and recurse
|
|
# Now, descend into the Node Groups and recurse
|
|
|
- for nc in group_nodes:
|
|
|
|
|
- data_from_tree(base_tree, tree_path+[nc.prototype], dummy_nodes, all_nc, all_schema)
|
|
|
|
|
- return dummy_nodes, all_nc, all_schema
|
|
|
|
|
|
|
+ for mantis_node in group_nodes:
|
|
|
|
|
+ data_from_tree(base_tree, tree_path+[mantis_node.ui_node], dummy_nodes, all_mantis_nodes, all_schema)
|
|
|
|
|
+ return dummy_nodes, all_mantis_nodes, all_schema
|
|
|
|
|
|
|
|
from .utilities import check_and_add_root, init_connections, init_dependencies, init_schema_dependencies
|
|
from .utilities import check_and_add_root, init_connections, init_dependencies, init_schema_dependencies
|
|
|
|
|
|
|
@@ -206,29 +204,29 @@ def is_signature_in_other_signature(parent_signature, child_signature):
|
|
|
return False
|
|
return False
|
|
|
return parent_signature[0:] == child_signature[:len(parent_signature)]
|
|
return parent_signature[0:] == child_signature[:len(parent_signature)]
|
|
|
|
|
|
|
|
-def solve_schema_to_tree(nc, all_nc, roots=[], error_popups=False):
|
|
|
|
|
- from .utilities import get_node_prototype
|
|
|
|
|
- np = get_node_prototype(nc.signature, nc.base_tree)
|
|
|
|
|
|
|
+def solve_schema_to_tree(mantis_node, all_mantis_nodes, roots=[], error_popups=False):
|
|
|
|
|
+ from .utilities import get_ui_node
|
|
|
|
|
+ np = get_ui_node(mantis_node.signature, mantis_node.base_tree)
|
|
|
from .schema_solve import SchemaSolver
|
|
from .schema_solve import SchemaSolver
|
|
|
- solver = SchemaSolver(nc, all_nc.copy(), np, error_popups=error_popups)
|
|
|
|
|
|
|
+ solver = SchemaSolver(mantis_node, all_mantis_nodes.copy(), np, error_popups=error_popups)
|
|
|
try:
|
|
try:
|
|
|
solved_nodes = solver.solve()
|
|
solved_nodes = solver.solve()
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
# # the schema will run the error cleanup code, we just need to raise or not
|
|
# # the schema will run the error cleanup code, we just need to raise or not
|
|
|
solved_nodes = {}
|
|
solved_nodes = {}
|
|
|
- nc.base_tree.hash=''
|
|
|
|
|
- raise execution_error_cleanup(nc, e, show_error=error_popups)
|
|
|
|
|
|
|
+ mantis_node.base_tree.hash=''
|
|
|
|
|
+ raise execution_error_cleanup(mantis_node, e, show_error=error_popups)
|
|
|
|
|
|
|
|
# maybe this should be done in schema solver. TODO invesitigate a more efficient way
|
|
# maybe this should be done in schema solver. TODO invesitigate a more efficient way
|
|
|
del_me = []
|
|
del_me = []
|
|
|
- for k, v in all_nc.items():
|
|
|
|
|
- # delete all the schema's prototype and interface nodes. The links have already been deleted by the solver.
|
|
|
|
|
- if v.signature[0] not in ['MANTIS_AUTOGENERATED'] and is_signature_in_other_signature(nc.signature, k):
|
|
|
|
|
|
|
+ for k, v in all_mantis_nodes.items():
|
|
|
|
|
+ # delete all the schema's ui_node and interface nodes. The links have already been deleted by the solver.
|
|
|
|
|
+ if v.signature[0] not in ['MANTIS_AUTOGENERATED'] and is_signature_in_other_signature(mantis_node.signature, k):
|
|
|
del_me.append(k)
|
|
del_me.append(k)
|
|
|
for k in del_me:
|
|
for k in del_me:
|
|
|
- del all_nc[k]
|
|
|
|
|
|
|
+ del all_mantis_nodes[k]
|
|
|
for k,v in solved_nodes.items():
|
|
for k,v in solved_nodes.items():
|
|
|
- all_nc[k]=v
|
|
|
|
|
|
|
+ all_mantis_nodes[k]=v
|
|
|
init_connections(v)
|
|
init_connections(v)
|
|
|
check_and_add_root(v, roots, include_non_hierarchy=True)
|
|
check_and_add_root(v, roots, include_non_hierarchy=True)
|
|
|
|
|
|
|
@@ -277,7 +275,7 @@ def get_schema_length_dependencies(node, all_nodes={}):
|
|
|
# this way we can handle Schema and Array Get nodes with one function
|
|
# this way we can handle Schema and Array Get nodes with one function
|
|
|
extend_dependencies_from_inputs(node)
|
|
extend_dependencies_from_inputs(node)
|
|
|
if node.node_type == 'DUMMY_SCHEMA':
|
|
if node.node_type == 'DUMMY_SCHEMA':
|
|
|
- trees = [(node.prototype.node_tree, node.signature)] # this is UI data
|
|
|
|
|
|
|
+ trees = [(node.ui_node.node_tree, node.signature)] # this is UI data
|
|
|
while trees:
|
|
while trees:
|
|
|
tree, tree_signature = trees.pop()
|
|
tree, tree_signature = trees.pop()
|
|
|
for sub_ui_node in tree.nodes:
|
|
for sub_ui_node in tree.nodes:
|
|
@@ -289,7 +287,7 @@ def get_schema_length_dependencies(node, all_nodes={}):
|
|
|
sub_node = all_nodes[(*tree_signature, sub_ui_node.name)]
|
|
sub_node = all_nodes[(*tree_signature, sub_ui_node.name)]
|
|
|
if sub_node.node_type == 'DUMMY_SCHEMA':
|
|
if sub_node.node_type == 'DUMMY_SCHEMA':
|
|
|
extend_dependencies_from_inputs(sub_node)
|
|
extend_dependencies_from_inputs(sub_node)
|
|
|
- trees.append((sub_node.prototype.node_tree, sub_node.signature))
|
|
|
|
|
|
|
+ trees.append((sub_node.ui_node.node_tree, sub_node.signature))
|
|
|
return list(filter(deps_filter, deps))
|
|
return list(filter(deps_filter, deps))
|
|
|
|
|
|
|
|
|
|
|
|
@@ -306,7 +304,7 @@ def parse_tree(base_tree, error_popups=False):
|
|
|
# then they stick around because the function definition inits them once and keeps a reference
|
|
# then they stick around because the function definition inits them once and keeps a reference
|
|
|
# so instead I have to supply them to avoid ugly code or bugs elsewhere
|
|
# so instead I have to supply them to avoid ugly code or bugs elsewhere
|
|
|
# it's REALLY confusing when you run into this sort of problem. So it warrants four entire lines of comments!
|
|
# it's REALLY confusing when you run into this sort of problem. So it warrants four entire lines of comments!
|
|
|
- dummy_nodes, all_mantis_nodes, all_schema = data_from_tree(base_tree, tree_path = [None], dummy_nodes = {}, all_nc = {}, all_schema={})
|
|
|
|
|
|
|
+ dummy_nodes, all_mantis_nodes, all_schema = data_from_tree(base_tree, tree_path = [None], dummy_nodes = {}, all_mantis_nodes = {}, all_schema={})
|
|
|
for dummy in dummy_nodes.values(): # reroute the links in the group nodes
|
|
for dummy in dummy_nodes.values(): # reroute the links in the group nodes
|
|
|
if (hasattr(dummy, "reroute_links")):
|
|
if (hasattr(dummy, "reroute_links")):
|
|
|
dummy.reroute_links(dummy, all_mantis_nodes)
|
|
dummy.reroute_links(dummy, all_mantis_nodes)
|
|
@@ -323,7 +321,7 @@ def parse_tree(base_tree, error_popups=False):
|
|
|
# add the Mantis Context here, so that it available during parsing.
|
|
# add the Mantis Context here, so that it available during parsing.
|
|
|
mantis_node.mContext = mContext
|
|
mantis_node.mContext = mContext
|
|
|
if mantis_node.node_type in ["DUMMY"]: # clean up the groups
|
|
if mantis_node.node_type in ["DUMMY"]: # clean up the groups
|
|
|
- if mantis_node.prototype.bl_idname in ("MantisNodeGroup", "NodeGroupOutput"):
|
|
|
|
|
|
|
+ if mantis_node.ui_node.bl_idname in ("MantisNodeGroup", "NodeGroupOutput"):
|
|
|
continue
|
|
continue
|
|
|
# Initialize the dependencies and connections (from/to links) for each node.
|
|
# Initialize the dependencies and connections (from/to links) for each node.
|
|
|
# we record & store it because using a getter is much slower (according to profiling)
|
|
# we record & store it because using a getter is much slower (according to profiling)
|
|
@@ -409,18 +407,18 @@ def parse_tree(base_tree, error_popups=False):
|
|
|
# I had a problem with this looping forever. I think it is resolved... but I don't know lol
|
|
# I had a problem with this looping forever. I think it is resolved... but I don't know lol
|
|
|
|
|
|
|
|
all_mantis_nodes = list(all_mantis_nodes.values())
|
|
all_mantis_nodes = list(all_mantis_nodes.values())
|
|
|
- kept_nc = {}
|
|
|
|
|
|
|
+ kept_mantis_node = {}
|
|
|
while (all_mantis_nodes):
|
|
while (all_mantis_nodes):
|
|
|
- nc = all_mantis_nodes.pop()
|
|
|
|
|
- if nc in array_nodes:
|
|
|
|
|
|
|
+ mantis_node = all_mantis_nodes.pop()
|
|
|
|
|
+ if mantis_node in array_nodes:
|
|
|
continue
|
|
continue
|
|
|
- if nc.node_type in ["DUMMY", 'SCHEMA', 'DUMMY_SCHEMA']:
|
|
|
|
|
- continue # screen out the prototype schema nodes, group in/out, and group placeholders
|
|
|
|
|
|
|
+ if mantis_node.node_type in ["DUMMY", 'SCHEMA', 'DUMMY_SCHEMA']:
|
|
|
|
|
+ continue # screen out the ui_node schema nodes, group in/out, and group placeholders
|
|
|
# cleanup autogen nodes
|
|
# cleanup autogen nodes
|
|
|
- if nc.signature[0] == "MANTIS_AUTOGENERATED" and len(nc.inputs) == 0 and len(nc.outputs) == 1:
|
|
|
|
|
|
|
+ if mantis_node.signature[0] == "MANTIS_AUTOGENERATED" and len(mantis_node.inputs) == 0 and len(mantis_node.outputs) == 1:
|
|
|
from .base_definitions import can_remove_socket_for_autogen
|
|
from .base_definitions import can_remove_socket_for_autogen
|
|
|
- output=list(nc.outputs.values())[0]
|
|
|
|
|
- value=list(nc.parameters.values())[0] # IDEA modify the dependecy get function to exclude these nodes completely
|
|
|
|
|
|
|
+ output=list(mantis_node.outputs.values())[0]
|
|
|
|
|
+ value=list(mantis_node.parameters.values())[0] # IDEA modify the dependecy get function to exclude these nodes completely
|
|
|
keep_me = False
|
|
keep_me = False
|
|
|
for l in output.links:
|
|
for l in output.links:
|
|
|
to_node = l.to_node; to_socket = l.to_socket
|
|
to_node = l.to_node; to_socket = l.to_socket
|
|
@@ -433,17 +431,17 @@ def parse_tree(base_tree, error_popups=False):
|
|
|
init_dependencies(to_node) # to remove the autogen node we no longer need.
|
|
init_dependencies(to_node) # to remove the autogen node we no longer need.
|
|
|
if not keep_me:
|
|
if not keep_me:
|
|
|
continue
|
|
continue
|
|
|
- init_connections(nc) # because we have removed many connections.
|
|
|
|
|
|
|
+ init_connections(mantis_node) # because we have removed many connections.
|
|
|
|
|
|
|
|
- if (nc.node_type in ['XFORM']) and ("Relationship" in nc.inputs.keys()):
|
|
|
|
|
- if (new_nc := insert_lazy_parents(nc)):
|
|
|
|
|
- kept_nc[new_nc.signature]=new_nc
|
|
|
|
|
|
|
+ if (mantis_node.node_type in ['XFORM']) and ("Relationship" in mantis_node.inputs.keys()):
|
|
|
|
|
+ if (new_mantis_node := insert_lazy_parents(mantis_node)):
|
|
|
|
|
+ kept_mantis_node[new_mantis_node.signature]=new_mantis_node
|
|
|
# be sure to add the Mantis context.
|
|
# be sure to add the Mantis context.
|
|
|
- new_nc.mContext =mContext
|
|
|
|
|
- kept_nc[nc.signature]=nc
|
|
|
|
|
|
|
+ new_mantis_node.mContext =mContext
|
|
|
|
|
+ kept_mantis_node[mantis_node.signature]=mantis_node
|
|
|
prWhite(f"Parsing tree took {time.time()-start_time} seconds.")
|
|
prWhite(f"Parsing tree took {time.time()-start_time} seconds.")
|
|
|
- prWhite("Number of Nodes: %s" % (len(kept_nc)))
|
|
|
|
|
- return kept_nc
|
|
|
|
|
|
|
+ prWhite("Number of Nodes: %s" % (len(kept_mantis_node)))
|
|
|
|
|
+ return kept_mantis_node
|
|
|
|
|
|
|
|
from .utilities import switch_mode
|
|
from .utilities import switch_mode
|
|
|
|
|
|
|
@@ -487,7 +485,7 @@ def execution_error_cleanup(node, exception, switch_objects = [], show_error=Fal
|
|
|
def sort_execution(nodes, xForm_pass):
|
|
def sort_execution(nodes, xForm_pass):
|
|
|
execution_failed=False
|
|
execution_failed=False
|
|
|
sorted_nodes = []
|
|
sorted_nodes = []
|
|
|
- from .node_container_common import GraphError
|
|
|
|
|
|
|
+ from .node_common import GraphError
|
|
|
# check for cycles here by keeping track of the number of times a node has been visited.
|
|
# check for cycles here by keeping track of the number of times a node has been visited.
|
|
|
visited={}
|
|
visited={}
|
|
|
check_max_len=len(nodes)**2 # seems too high but safe. In a well-ordered graph, I guess this number should be less than the number of nodes.
|
|
check_max_len=len(nodes)**2 # seems too high but safe. In a well-ordered graph, I guess this number should be less than the number of nodes.
|
|
@@ -536,37 +534,45 @@ def sort_execution(nodes, xForm_pass):
|
|
|
xForm_pass.appendleft(conn)
|
|
xForm_pass.appendleft(conn)
|
|
|
return sorted_nodes, execution_failed
|
|
return sorted_nodes, execution_failed
|
|
|
|
|
|
|
|
-def execute_tree(nodes, base_tree, context, error_popups = False):
|
|
|
|
|
|
|
+def execute_tree(nodes, base_tree, context, error_popups = False, profile=False):
|
|
|
assert nodes is not None, "Failed to parse tree."
|
|
assert nodes is not None, "Failed to parse tree."
|
|
|
assert len(nodes) > 0, "No parsed nodes for execution."\
|
|
assert len(nodes) > 0, "No parsed nodes for execution."\
|
|
|
" Mantis probably failed to parse the tree."
|
|
" Mantis probably failed to parse the tree."
|
|
|
import bpy
|
|
import bpy
|
|
|
from time import time
|
|
from time import time
|
|
|
- from .node_container_common import GraphError
|
|
|
|
|
|
|
+ from .node_common import GraphError
|
|
|
original_active = context.view_layer.objects.active
|
|
original_active = context.view_layer.objects.active
|
|
|
start_execution_time = time()
|
|
start_execution_time = time()
|
|
|
mContext = None
|
|
mContext = None
|
|
|
from collections import deque
|
|
from collections import deque
|
|
|
xForm_pass = deque()
|
|
xForm_pass = deque()
|
|
|
- for nc in nodes.values():
|
|
|
|
|
|
|
+ for mantis_node in nodes.values():
|
|
|
if not mContext: # just grab one of these. this is a silly way to do this.
|
|
if not mContext: # just grab one of these. this is a silly way to do this.
|
|
|
- mContext = nc.mContext
|
|
|
|
|
|
|
+ mContext = mantis_node.mContext
|
|
|
mContext.b_objects = {} # clear the objects and recreate them
|
|
mContext.b_objects = {} # clear the objects and recreate them
|
|
|
- nc.reset_execution()
|
|
|
|
|
- check_and_add_root(nc, xForm_pass)
|
|
|
|
|
|
|
+ mantis_node.reset_execution()
|
|
|
|
|
+ check_and_add_root(mantis_node, xForm_pass)
|
|
|
mContext.execution_failed = False
|
|
mContext.execution_failed = False
|
|
|
|
|
|
|
|
switch_me = [] # switch the mode on these objects
|
|
switch_me = [] # switch the mode on these objects
|
|
|
active = None # only need it for switching modes
|
|
active = None # only need it for switching modes
|
|
|
select_me = []
|
|
select_me = []
|
|
|
|
|
+ profiler = None
|
|
|
|
|
+ if profile:
|
|
|
|
|
+ from .dev_helpers.profile_nodes import NodeProfiler
|
|
|
|
|
+ profiler = NodeProfiler()
|
|
|
|
|
+ profiler.new_session(mContext.execution_id)
|
|
|
|
|
+ sort_key = 'total'
|
|
|
try:
|
|
try:
|
|
|
sorted_nodes, execution_failed = sort_execution(nodes, xForm_pass)
|
|
sorted_nodes, execution_failed = sort_execution(nodes, xForm_pass)
|
|
|
for n in sorted_nodes:
|
|
for n in sorted_nodes:
|
|
|
try:
|
|
try:
|
|
|
if not n.prepared:
|
|
if not n.prepared:
|
|
|
- n.bPrepare(context)
|
|
|
|
|
|
|
+ if profiler: profiler.record(n, "bPrepare", context)
|
|
|
|
|
+ else: n.bPrepare(context)
|
|
|
if not n.executed:
|
|
if not n.executed:
|
|
|
- n.bTransformPass(context)
|
|
|
|
|
|
|
+ if profiler: profiler.record(n, "bTransformPass", context)
|
|
|
|
|
+ else: n.bTransformPass(context)
|
|
|
if (n.__class__.__name__ == "xFormArmature" ):
|
|
if (n.__class__.__name__ == "xFormArmature" ):
|
|
|
ob = n.bGetObject()
|
|
ob = n.bGetObject()
|
|
|
switch_me.append(ob)
|
|
switch_me.append(ob)
|
|
@@ -585,10 +591,11 @@ def execute_tree(nodes, base_tree, context, error_popups = False):
|
|
|
|
|
|
|
|
for n in sorted_nodes:
|
|
for n in sorted_nodes:
|
|
|
try:
|
|
try:
|
|
|
- if not n.prepared:
|
|
|
|
|
- n.bPrepare(context)
|
|
|
|
|
|
|
+ if profiler: profiler.record(n, "bPrepare", context)
|
|
|
|
|
+ else: n.bPrepare(context)
|
|
|
if not n.executed:
|
|
if not n.executed:
|
|
|
- n.bRelationshipPass(context)
|
|
|
|
|
|
|
+ if profiler: profiler.record(n, "bRelationshipPass", context)
|
|
|
|
|
+ else: n.bRelationshipPass(context)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
e = execution_error_cleanup(n, e, show_error=error_popups)
|
|
e = execution_error_cleanup(n, e, show_error=error_popups)
|
|
|
if error_popups == False:
|
|
if error_popups == False:
|
|
@@ -606,7 +613,8 @@ def execute_tree(nodes, base_tree, context, error_popups = False):
|
|
|
|
|
|
|
|
for n in sorted_nodes:
|
|
for n in sorted_nodes:
|
|
|
try:
|
|
try:
|
|
|
- n.bFinalize(context)
|
|
|
|
|
|
|
+ if profiler: profiler.record(n, "bFinalize", context)
|
|
|
|
|
+ else: n.bFinalize(context)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
e = execution_error_cleanup(n, e, show_error=error_popups)
|
|
e = execution_error_cleanup(n, e, show_error=error_popups)
|
|
|
if error_popups == False:
|
|
if error_popups == False:
|
|
@@ -621,7 +629,8 @@ def execute_tree(nodes, base_tree, context, error_popups = False):
|
|
|
# finally, apply modifiers and bind stuff
|
|
# finally, apply modifiers and bind stuff
|
|
|
for n in sorted_nodes:
|
|
for n in sorted_nodes:
|
|
|
try:
|
|
try:
|
|
|
- n.bModifierApply(context)
|
|
|
|
|
|
|
+ if profiler: profiler.record(n, "bModifierApply", context)
|
|
|
|
|
+ else: n.bModifierApply(context)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
e = execution_error_cleanup(n, e, show_error=error_popups)
|
|
e = execution_error_cleanup(n, e, show_error=error_popups)
|
|
|
if error_popups == False:
|
|
if error_popups == False:
|
|
@@ -634,6 +643,13 @@ def execute_tree(nodes, base_tree, context, error_popups = False):
|
|
|
tot_time = (time() - start_execution_time)
|
|
tot_time = (time() - start_execution_time)
|
|
|
if not execution_failed:
|
|
if not execution_failed:
|
|
|
prGreen(f"Executed tree of {len(sorted_nodes)} nodes in {tot_time} seconds")
|
|
prGreen(f"Executed tree of {len(sorted_nodes)} nodes in {tot_time} seconds")
|
|
|
|
|
+ if profiler:
|
|
|
|
|
+ from .dev_helpers.profile_nodes import summarize_profile
|
|
|
|
|
+ summarize_profile(profiler._current, pass_name='bPrepare', sort_key = sort_key)
|
|
|
|
|
+ summarize_profile(profiler._current, pass_name='bTransformPass', sort_key = sort_key)
|
|
|
|
|
+ summarize_profile(profiler._current, pass_name='bRelationshipPass', sort_key = sort_key)
|
|
|
|
|
+ summarize_profile(profiler._current, pass_name='bFinalize', sort_key = sort_key)
|
|
|
|
|
+ summarize_profile(profiler._current, pass_name='bModifierApply', sort_key = sort_key)
|
|
|
if (original_active):
|
|
if (original_active):
|
|
|
context.view_layer.objects.active = original_active
|
|
context.view_layer.objects.active = original_active
|
|
|
original_active.select_set(True)
|
|
original_active.select_set(True)
|