Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi output nodes #66

Merged
merged 3 commits into from
Jun 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions src/QuiltiX/qx_nodegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,12 @@ def get_mx_doc_from_serialized_data(self, serialized_data, mx_parent=None, paren
output = mx_node.addOutput(
port_data["name"], port_type
)
output.setConnectedNode(
qx_node_ids_to_mx_nodes[connected_data[0]]
)
mx_sub_node = qx_node_ids_to_mx_nodes[connected_data[0]]
if mx_node.getType() == "multioutput":
con_output = mx_sub_node.getActiveOutput(connected_data[1])
output.setConnectedOutput(con_output)
else:
output.setConnectedNode(mx_sub_node)

elif node_data["type_"] in ["Inputs.QxPortInputNode", "Outputs.QxPortOutputNode"]:
continue
Expand All @@ -505,13 +508,13 @@ def get_mx_doc_from_serialized_data(self, serialized_data, mx_parent=None, paren
mx_node = main_mx_node_graph.addNode(
mx_def.getNodeString(),
node_data["name"],
mx_def.getActiveOutputs()[0].getType(),
mx_def.getType(),
)
else:
mx_node = mx_parent.addNode(
mx_def.getNodeString(),
node_data["name"],
mx_def.getActiveOutputs()[0].getType(),
mx_def.getType(),
)
else:
logger.warning("node has no outputs: %s" % mx_def.getNodeString())
Expand Down Expand Up @@ -558,6 +561,13 @@ def get_mx_doc_from_serialized_data(self, serialized_data, mx_parent=None, paren
if not hasGeomProp:
self.set_mx_input_value(mx_input, val)

for output_data in node_data.get("output_ports", {}):
if node_data["type_"] == "Other.QxGroupNode":
continue

mx_output_type = mx_def.getActiveOutput(output_data["name"]).getType()
mx_node.addOutput(output_data["name"], mx_output_type)

qx_node_ids_to_mx_nodes[node_id] = mx_node

if ng_abstraction:
Expand All @@ -576,7 +586,7 @@ def get_mx_doc_from_serialized_data(self, serialized_data, mx_parent=None, paren

connected_node_data = serialized_data["nodes"][connection["in"][0]]
connected_mx_def = self.get_mx_node_def(connected_node_data["type_"], connected_node_data.get("custom", {}).get("type"))
connected_port_type = connected_mx_def.getActiveOutputs()[0].getType()
connected_port_type = connected_mx_def.getType()
if connected_port_type in ("material", "surfaceshader"):
output_name = f"output_{node_data['name']}_{output_data['name']}"
if main_mx_node_graph.getOutput(output_name):
Expand All @@ -586,9 +596,13 @@ def get_mx_doc_from_serialized_data(self, serialized_data, mx_parent=None, paren
output_name,
mx_output_type,
)
main_mx_node_graph_output.setConnectedNode(
qx_node_ids_to_mx_nodes[node_id]
)
mx_node = qx_node_ids_to_mx_nodes[node_id]
if mx_node.getType() == "multioutput":
output = mx_node.getActiveOutput(connection["out"][1])
main_mx_node_graph_output.setConnectedOutput(output)
else:
main_mx_node_graph_output.setConnectedNode(mx_node)

if node_id not in main_mx_node_graph_outputs:
main_mx_node_graph_outputs[node_id] = {}

Expand Down Expand Up @@ -620,9 +634,12 @@ def get_mx_doc_from_serialized_data(self, serialized_data, mx_parent=None, paren
main_mx_node_graph_outputs[connection["out"][0]][connection["out"][1]]
)
else:
mx_input.setConnectedNode(
qx_node_ids_to_mx_nodes[connection["out"][0]]
)
mx_node = qx_node_ids_to_mx_nodes[connection["out"][0]]
if mx_node.getType() == "multioutput":
output = mx_node.getActiveOutput(connection["out"][1])
mx_input.setConnectedOutput(output)
else:
mx_input.setConnectedNode(mx_node)

return mx_parent

Expand All @@ -639,7 +656,7 @@ def set_mx_input_value(self, mx_input, val):
val = mx.PyMaterialXCore.Color4(val)

# We do not need to set a value if it is connected to a node
if val != "" or mx_input_type == "string":
if val != "" or mx_input_type in ["string", "filename"]:
if mx_input_type == "filename":
mx_input.setValueString(val)
mx_input.setAttribute("colorspace", "srgb_texture")
Expand Down Expand Up @@ -796,7 +813,7 @@ def connect_qx_inputs_from_mx_node(self, qx_node, mx_node):

mx_connected_node = mx_input.getConnectedNode()
if mx_connected_node:
if mx_connected_port:
if mx_connected_port and mx_connected_port.getParent().CATEGORY == "nodegraph":
port_node = qx_input_node.get_sub_graph().get_output_port_nodes()[0]
qx_input_port = port_node.get_input(mx_connected_port.getName())
mx_input_node_name = mx_connected_node.getName()
Expand Down