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

Definition and NodeGraph Publishing Logic Updates #1303

Closed
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dd2155f
Update nodedef creation logic to match specification, add in interfac…
kwokcb Mar 22, 2023
d1d1e16
Merge branch 'main' into nodedef_API_spec_updates
kwokcb Mar 22, 2023
4ea33b8
Fix remove removeInterfaceName() to copy back any value from the inte…
kwokcb Mar 23, 2023
dd03d17
Update test file.
kwokcb Mar 23, 2023
8823164
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb Mar 29, 2023
11bdd6b
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb Apr 5, 2023
1a4da27
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb Apr 13, 2023
b245be5
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb Apr 16, 2023
301f39c
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb Apr 17, 2023
0ffc0c9
Use definition creation in Node Editor.
kwokcb Apr 19, 2023
cda1e6a
Merge remote-tracking branch 'aswf/main' into nodedef_API_spec_updates
kwokcb Apr 20, 2023
96735ea
User tables for formatting property panel.
kwokcb Apr 20, 2023
f226abe
Cleanup table conversion.
kwokcb Apr 20, 2023
04b589a
Clleanup + add publish button to property editor.
kwokcb Apr 21, 2023
2d7dca6
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb Apr 28, 2023
665c643
Merge branch 'main' of https://github.com/AcademySoftwareFoundation/M…
kwokcb May 5, 2023
c83b102
Rework to have user dialog for input and create default "user_library…
kwokcb May 5, 2023
e7fa28a
Doc-string, and enum fo nodegroup.
kwokcb May 6, 2023
a3f3d16
Consolidate creation into addNoDefFromGraph. Fix up namespaces.
kwokcb May 6, 2023
7a28a7a
Fix warning.
kwokcb May 6, 2023
e26bdc7
Add createdefinition.py script. Works for pre 1.38.8 by applying the …
kwokcb May 8, 2023
ed4c56e
Hook up remaining attributes, comments, and custom location browsing.
kwokcb May 9, 2023
8694cd6
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb May 13, 2023
29eccb7
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb May 17, 2023
ffcf89f
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb May 22, 2023
02ac316
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb May 24, 2023
8a12cd0
Remove node positions
jstone-lucasfilm May 26, 2023
1c7ef0a
Remove node positions
jstone-lucasfilm May 26, 2023
9200855
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb May 30, 2023
6de05cd
Merge branch 'main' into nodedef_API_spec_updates
kwokcb Jun 15, 2023
db43c3c
Create new options class: NodeDefCreateOptions
kwokcb Jun 15, 2023
4ee2a18
Fix build.
kwokcb Jun 15, 2023
ba9c3ee
Use new options class for graph editor and createdefinitions.py script.
kwokcb Jun 16, 2023
3e810aa
Revert accidental check-in.
kwokcb Jun 16, 2023
98cd6e6
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb Jun 23, 2023
4873512
Merge branch 'AcademySoftwareFoundation:main' into nodedef_API_spec_u…
kwokcb Jul 5, 2023
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
Original file line number Diff line number Diff line change
@@ -1,76 +1,29 @@
<?xml version="1.0"?>
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
<materialx version="1.38">
<nodegraph name="test_colorcorrect">
<range name="AlphaClampAndGamma" type="float">
<input name="in" type="float" nodename="AlphaOffset" />
<input name="gamma" type="float" value="3" />
<input name="doclamp" type="boolean" value="true" />
</range>
<multiply name="AlphaGain" type="float">
<input name="in1" type="float" nodename="extractAlphaForGain" />
<multiply name="AlphaGain" type="float" xpos="-17.746376" ypos="1.379310">
<input name="in1" type="float" nodename="inputAlpha" />
<input name="in2" type="float" value="0.8" />
</multiply>
<add name="AlphaOffset" type="float">
<add name="AlphaOffset" type="float" xpos="-13.065217" ypos="1.689655">
<input name="in1" type="float" nodename="AlphaGain" />
<input name="in2" type="float" value="1" />
</add>
<range name="ColorClampAndGamma" type="color3">
<input name="in" type="color3" nodename="ColorOffset" />
<input name="gamma" type="color3" value="2, 1, 1" />
</range>
<multiply name="ColorGain" type="color3">
<input name="in1" type="color3" nodename="HSV_adjust" />
<multiply name="ColorGain" type="color3" xpos="-17.514492" ypos="-0.801724">
<input name="in1" type="color3" nodename="inputColor" />
<input name="in2" type="color3" value="0.9, 0.9, 0.9" />
</multiply>
<add name="ColorOffset" type="color3">
<add name="ColorOffset" type="color3" xpos="-13.043478" ypos="-0.318966">
<input name="in1" type="color3" nodename="ColorGain" />
<input name="in2" type="color3" value="0.379147, 0.0341412, 0.0341412" />
</add>
<combine2 name="CombineColorAlpha" type="color4">
<input name="in1" type="color3" nodename="ColorClampAndGamma" />
<input name="in2" type="float" nodename="AlphaClampAndGamma" />
</combine2>
<hsvadjust name="HSV_adjust" type="color3">
<input name="in" type="color3" nodename="extractColorForHsv" />
</hsvadjust>
<premult name="premultiplyColor" type="color4">
<input name="in" type="color4" nodename="CombineColorAlpha" />
</premult>
<ifequal name="if_premultiply_condition" type="color4">
<input name="value2" type="boolean" value="true" />
<input name="in1" type="color4" nodename="premultiplyColor" />
<input name="in2" type="color4" nodename="CombineColorAlpha" />
</ifequal>
<unpremult name="unpremultiply" type="color4">
<input name="in" type="color4" nodename="combineInput" />
</unpremult>
<ifequal name="if_unpremultiply_condition" type="color4">
<input name="value2" type="boolean" value="true" />
<input name="in1" type="color4" nodename="unpremultiply" />
<input name="in2" type="color4" nodename="combineInput" />
</ifequal>
<swizzle name="outputColor" type="color3">
<input name="in" type="color4" nodename="if_premultiply_condition" />
<input name="channels" type="string" value="rgb" />
</swizzle>
<swizzle name="outputAlpha" type="float">
<input name="in" type="color4" nodename="if_premultiply_condition" />
<input name="channels" type="string" value="a" />
</swizzle>
<swizzle name="extractColorForHsv" type="color3">
<input name="in" type="color4" nodename="if_unpremultiply_condition" />
<input name="channels" type="string" value="rgb" />
</swizzle>
<swizzle name="extractAlphaForGain" type="float">
<input name="in" type="color4" nodename="if_unpremultiply_condition" />
</swizzle>
<constant name="inputColor" type="color3">
<constant name="inputColor" type="color3" xpos="-21.094202" ypos="-0.508621">
<input name="value" type="color3" value="0.5, 0.5, 0.5" />
</constant>
<constant name="inputAlpha" type="float">
<constant name="inputAlpha" type="float" xpos="-21.094202" ypos="0.818965">
<input name="value" type="float" value="1" />
</constant>
<combine2 name="combineInput" type="color4">
<input name="in1" type="color3" nodename="inputColor" />
<input name="in2" type="float" nodename="inputAlpha" />
</combine2>
<output name="out" type="color3" nodename="outputColor" />
<output name="out1" type="float" nodename="outputAlpha" />
<output name="out" type="color3" nodename="ColorOffset" xpos="-3.347826" ypos="-0.655172" />
<output name="out1" type="float" nodename="AlphaOffset" xpos="-3.347826" ypos="0.672414" />
</nodegraph>
</materialx>
44 changes: 42 additions & 2 deletions source/MaterialXCore/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,49 @@ NodeDefPtr Document::addNodeDefFromGraph(const NodeGraphPtr nodeGraph, const str
}
}

for (auto output : graph->getOutputs())
// Expose any existing interface.
// Any connection attributes on the existing interface should be removed from the definition.
// as well as any source URI

// Attributes which should not be copied over
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
StringSet filterAttributes = { PortElement::NODE_GRAPH_ATTRIBUTE, PortElement::NODE_NAME_ATTRIBUTE,
PortElement::CHANNELS_ATTRIBUTE, PortElement::INTERFACE_NAME_ATTRIBUTE,
"xpos", "ypos" };

// Transfer input interface from the graph to the nodedef
for (InputPtr input : graph->getInputs())
{
InputPtr nodeDefInput = nodeDef->addInput(input->getName(), input->getType());
if (nodeDefInput)
{
nodeDefInput->copyContentFrom(input);
for (const string& filterAttribute : filterAttributes )
{
nodeDefInput->removeAttribute(filterAttribute);
}
nodeDefInput->setSourceUri(EMPTY_STRING);
input->setInterfaceName(nodeDefInput->getName());
}
}
// Remove interface from the nodegraph
for (InputPtr input : graph->getInputs())
{
nodeDef->addOutput(output->getName(), output->getType());
graph->removeInput(input->getName());
}

// Copy the output interface from the graph to the nodedef
for (OutputPtr output : graph->getOutputs())
{
OutputPtr nodeDefOutput = nodeDef->addOutput(output->getName(), output->getType());
if (nodeDefOutput)
{
nodeDefOutput->copyContentFrom(output);
for (const string& filterAttribute : filterAttributes)
{
nodeDefOutput->removeAttribute(filterAttribute);
}
nodeDefOutput->setSourceUri(EMPTY_STRING);
}
}

return nodeDef;
Expand Down
53 changes: 36 additions & 17 deletions source/MaterialXCore/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,34 +652,33 @@ void Node::addInputsFromNodeDef()
}
}

void NodeGraph::addInterfaceName(const string& inputPath, const string& interfaceName)
InputPtr NodeGraph::addInterfaceName(const string& inputPath, const string& interfaceName)
{
NodeDefPtr nodeDef = getNodeDef();
if (!nodeDef)
InterfaceElementPtr interfaceElement = ( nodeDef ? nodeDef->asA<InterfaceElement>() : getSelf()->asA<InterfaceElement>() );
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
if (interfaceElement->getChild(interfaceName))
{
throw Exception("Cannot declare an interface for a nodegraph which is not associated with a node definition: " + getName());
}
if (nodeDef->getChild(interfaceName))
{
throw Exception("Interface: " + interfaceName + " has already been declared on the node definition: " + nodeDef->getName());
throw Exception("Interface: " + interfaceName + " has already been declared on the interface: " + interfaceElement->getNamePath());
}

InputPtr interfaceInput = nullptr;
ElementPtr elem = getDescendant(inputPath);
InputPtr input = elem ? elem->asA<Input>() : nullptr;
if (input && !input->getConnectedNode())
{
input->setInterfaceName(interfaceName);
InputPtr nodeDefInput = nodeDef->getInput(interfaceName);
if (!nodeDefInput)
interfaceInput = interfaceElement->getInput(interfaceName);
if (!interfaceInput)
{
nodeDefInput = nodeDef->addInput(interfaceName, input->getType());
interfaceInput = interfaceElement->addInput(interfaceName, input->getType());
}
if (input->hasValue())
{
nodeDefInput->setValueString(input->getValueString());
interfaceInput->setValueString(input->getValueString());
input->removeAttribute(Input::VALUE_ATTRIBUTE);
}
}
return interfaceInput;
}

void NodeGraph::removeInterfaceName(const string& inputPath)
Expand All @@ -689,24 +688,44 @@ void NodeGraph::removeInterfaceName(const string& inputPath)
if (input)
{
const string& interfaceName = input->getInterfaceName();
getNodeDef()->removeChild(interfaceName);
input->setInterfaceName(EMPTY_STRING);
if (!interfaceName.empty())
{
NodeDefPtr nodeDef = getNodeDef();
InterfaceElementPtr interface = ( nodeDef ? nodeDef->asA<InterfaceElement>() : getSelf()->asA<InterfaceElement>() );
ElementPtr interfaceElement = interface->getChild(interfaceName);
if (interfaceElement)
{
InputPtr interfaceInput = interfaceElement ? interfaceElement->asA<Input>() : nullptr;
if (interfaceInput && interfaceInput->hasValue())
{
input->setValueString(interfaceInput->getValueString());
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
}
interface->removeChild(interfaceName);
}
input->setInterfaceName(EMPTY_STRING);
}
}
}

void NodeGraph::modifyInterfaceName(const string& inputPath, const string& interfaceName)
{
NodeDefPtr nodeDef = getNodeDef();
InterfaceElementPtr interfaceElement = ( nodeDef ? nodeDef->asA<InterfaceElement>() : getSelf()->asA<InterfaceElement>() );

ElementPtr desc = getDescendant(inputPath);
InputPtr input = desc ? desc->asA<Input>() : nullptr;
if (input)
{
const string& previousName = input->getInterfaceName();
ElementPtr previousChild = getNodeDef()->getChild(previousName);
if (previousChild)
if (previousName != interfaceName)
{
previousChild->setName(interfaceName);
ElementPtr previousChild = interfaceElement->getChild(previousName);
if (previousChild)
{
previousChild->setName(interfaceName);
}
input->setInterfaceName(interfaceName);
}
input->setInterfaceName(interfaceName);
}
}

Expand Down
3 changes: 2 additions & 1 deletion source/MaterialXCore/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ class MX_CORE_API NodeGraph : public GraphElement
/// Add an interface name to an existing NodeDef associated with this NodeGraph.
/// @param inputPath Path to an input descendant of this graph.
/// @param interfaceName The new interface name.
void addInterfaceName(const string& inputPath, const string& interfaceName);
/// @return Interface input.
InputPtr addInterfaceName(const string& inputPath, const string& interfaceName);

/// Remove an interface name from an existing NodeDef associated with this NodeGraph.
/// @param inputPath Path to an input descendant of this graph.
Expand Down
Loading