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

Improvements to publishing API #1403

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
660f779
API logic updates and updated testing.
kwokcb Jul 11, 2023
92ac629
Add createdefinition Python utility.
kwokcb Jul 11, 2023
595e8f0
Revert whitespace edit
jstone-lucasfilm Jul 13, 2023
f8d7ad6
Merge branch 'AcademySoftwareFoundation:main' into nodedef_creation_api
kwokcb Jul 24, 2023
16f0b53
Merge branch 'AcademySoftwareFoundation:main' into nodedef_creation_api
kwokcb Jul 30, 2023
59e8e89
Merge branch 'AcademySoftwareFoundation:main' into nodedef_creation_api
kwokcb Aug 16, 2023
f06edc3
Remove sample script.
kwokcb Aug 20, 2023
e0f9d5e
Proposed simplified const interface.
kwokcb Aug 20, 2023
281fbe3
Merge branch 'AcademySoftwareFoundation:main' into nodedef_creation_api
kwokcb Sep 1, 2023
18ad877
Merge branch 'main' into nodedef_creation_api
jstone-lucasfilm Sep 1, 2023
ced6cb7
Merge branch 'AcademySoftwareFoundation:main' into nodedef_creation_api
kwokcb Sep 4, 2023
1fa27c1
Update Javascript wrapper.
kwokcb Sep 4, 2023
198fabc
Merge branch 'main' into nodedef_creation_api
jstone-lucasfilm Sep 4, 2023
025a37a
Minor format edit
jstone-lucasfilm Sep 5, 2023
2b0da25
Review updates.
kwokcb Sep 6, 2023
80354bd
Minor spelling fix
jstone-lucasfilm Sep 7, 2023
8b75c28
Merge branch 'main' into nodedef_creation_api
jstone-lucasfilm Oct 9, 2023
cc7ad49
Omit file writes in unit tests
jstone-lucasfilm Oct 10, 2023
358d359
Minor whitespace fixes
jstone-lucasfilm Oct 10, 2023
e0917f4
Additional whitespace fixes
jstone-lucasfilm Oct 10, 2023
75a413a
Standardize formatting
jstone-lucasfilm Oct 10, 2023
090d435
Align formatting
jstone-lucasfilm Oct 10, 2023
ae75615
Merge branch 'AcademySoftwareFoundation:main' into nodedef_creation_api
kwokcb Oct 19, 2023
1feba6e
Merge branch 'AcademySoftwareFoundation:main' into nodedef_creation_api
kwokcb Dec 5, 2023
929614c
Merge branch 'main' into nodedef_creation_api
jstone-lucasfilm Jan 24, 2024
ca4cbae
Clarify comment
jstone-lucasfilm Jan 24, 2024
65818e0
Clarify comments
jstone-lucasfilm Jan 24, 2024
52eab15
Clarify comment
jstone-lucasfilm Jan 24, 2024
f9516b1
Remove second unit test
jstone-lucasfilm Jan 24, 2024
188541c
Maintain original validation step
jstone-lucasfilm Jan 24, 2024
bfa9270
Minor grammar fix
jstone-lucasfilm Jan 24, 2024
b1e4b7b
Remove extra parentheses
jstone-lucasfilm Jan 24, 2024
9d1733e
Remove assignment that duplicates constructor
jstone-lucasfilm Jan 24, 2024
d1c95a2
Remove extra parentheses
jstone-lucasfilm Jan 25, 2024
c04789b
Merge branch 'main' into nodedef_creation_api
jstone-lucasfilm Jan 26, 2024
8943ba3
Update test to create node instances from definitions.
kwokcb Jan 30, 2024
c32136d
Remove hard-coded strings.
kwokcb Jan 30, 2024
abe7265
Merge branch 'AcademySoftwareFoundation:main' into nodedef_creation_api
kwokcb Jan 30, 2024
c034d51
Merge branch 'main' into nodedef_creation_api
jstone-lucasfilm Jan 31, 2024
475a981
Merge branch 'main' into nodedef_creation_api
jstone-lucasfilm Feb 1, 2024
dcc97f8
Merge branch 'main' into nodedef_creation_api
jstone-lucasfilm Mar 6, 2024
a9cf526
Merge branch 'dev_1.39' into nodedef_creation_api
kwokcb Mar 16, 2024
39ac8a9
Add in method deprecation.
kwokcb Mar 16, 2024
050961b
Add C++ fallback, and proper pybind11 and emscripten deprecation inte…
kwokcb Mar 18, 2024
e7ebe25
Fix string for JS message.
kwokcb Mar 18, 2024
083f2c5
Merge branch 'dev_1.39' of https://github.com/AcademySoftwareFoundati…
kwokcb Apr 9, 2024
d315c05
Remove JS deprecation method.
kwokcb Apr 9, 2024
76402bd
Minor whitespace fixes
jstone-lucasfilm Apr 11, 2024
2855b3c
Merge branch 'dev_1.39' into nodedef_creation_api
jstone-lucasfilm Apr 15, 2024
0f36e4b
Merge branch 'dev_1.39' into nodedef_creation_api
jstone-lucasfilm May 11, 2024
e48f4f9
Remove references to channels in 1.39
jstone-lucasfilm May 11, 2024
56cb334
Remove references to channels in 1.39
jstone-lucasfilm May 11, 2024
bf85dfe
Merge branch 'dev_1.39' into nodedef_creation_api
jstone-lucasfilm May 21, 2024
41099a1
Minor fix to JavaScript binding
jstone-lucasfilm May 24, 2024
616f00e
Merge branch 'dev_1.39' into nodedef_creation_api
jstone-lucasfilm May 24, 2024
a2ccbfd
Simplify validation logic
jstone-lucasfilm May 24, 2024
5aaf451
Minor consistency improvements
jstone-lucasfilm May 24, 2024
779af87
Minor formatting fixes
jstone-lucasfilm May 26, 2024
39f25db
Merge branch 'dev_1.39' into nodedef_creation_api
jstone-lucasfilm May 27, 2024
cdff9e1
Simplify unit tests
jstone-lucasfilm May 27, 2024
3f184df
Fix typo
jstone-lucasfilm May 27, 2024
266d41e
Fix typo
jstone-lucasfilm May 27, 2024
1d8a34a
Minor clarity improvements
jstone-lucasfilm May 28, 2024
d8010a4
Remove unused qualifier
jstone-lucasfilm May 28, 2024
987c32f
Remove unused qualifiers
jstone-lucasfilm May 28, 2024
c342133
Remove unused qualifier
jstone-lucasfilm May 28, 2024
735e13e
Remove unused qualifiers
jstone-lucasfilm May 28, 2024
47f04f4
Clarify variable name
jstone-lucasfilm May 28, 2024
2198f7b
Merge branch 'dev_1.39' into nodedef_creation_api
jstone-lucasfilm May 28, 2024
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"?>
<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" />
<input name="in1" type="float" nodename="inputAlpha" />
<input name="in2" type="float" value="0.8" />
</multiply>
<add name="AlphaOffset" type="float">
<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" />
<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">
<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">
<input name="value" type="color3" value="0.5, 0.5, 0.5" />
</constant>
<constant name="inputAlpha" type="float">
<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" />
<output name="out1" type="float" nodename="AlphaOffset" />
</nodegraph>
</materialx>
50 changes: 48 additions & 2 deletions source/MaterialXCore/Document.cpp
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ NodeDefPtr Document::addNodeDefFromGraph(const NodeGraphPtr nodeGraph, const str
}
graph = addNodeGraph(newGraphName);
graph->copyContentFrom(nodeGraph);

for (auto graphChild : graph->getChildren())
{
graphChild->removeAttribute("xpos");
graphChild->removeAttribute("ypos");
}
}
graph->setNodeDefString(nodeDefName);

Expand All @@ -208,9 +214,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
StringSet filterAttributes = { PortElement::NODE_GRAPH_ATTRIBUTE, PortElement::NODE_NAME_ATTRIBUTE,
PortElement::CHANNELS_ATTRIBUTE, PortElement::INTERFACE_NAME_ATTRIBUTE,
"xpos", "ypos" };
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved

// 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())
{
graph->removeInput(input->getName());
}

// Copy the output interface from the graph to the nodedef
for (OutputPtr output : graph->getOutputs())
{
nodeDef->addOutput(output->getName(), output->getType());
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
2 changes: 1 addition & 1 deletion source/MaterialXCore/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ class MX_CORE_API Document : public GraphElement
/// @param node Node type for the new declaration
/// @param version Version for the new declaration
/// @param isDefaultVersion If a version is specified is thie definition the default version
/// @param nodeGroup Optional node group for the new declaration. The Default value is an emptry string.
/// @param newGraphName Make a copy of this NodeGraph with the given name if a non-empty name is provided. Otherwise
/// modify the existing NodeGraph. Default value is an empty string.
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
/// @param nodeGroup Optional node group for the new declaration. The Default value is an emptry string.
/// @return New declaration if successful.
NodeDefPtr addNodeDefFromGraph(const NodeGraphPtr nodeGraph, const string& nodeDefName, const string& node, const string& version,
bool isDefaultVersion, const string& nodeGroup, const string& newGraphName);
Expand Down
53 changes: 36 additions & 17 deletions source/MaterialXCore/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,34 +657,33 @@ void Node::addInputsFromNodeDef()
}
}

void NodeGraph::addInterfaceName(const string& inputPath, const string& interfaceName)
InputPtr NodeGraph::addInterfaceName(const string& inputPath, const string& interfaceName)
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
{
NodeDefPtr nodeDef = getNodeDef();
if (!nodeDef)
InterfaceElementPtr interfaceElement = ( nodeDef ? nodeDef->asA<InterfaceElement>() : getSelf()->asA<InterfaceElement>() );
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 @@ -694,24 +693,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());
}
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