Skip to content

Commit 017dfaa

Browse files
Improvements to 'swizzle' upgrade logic
This changelist improves the upgrade logic for the `swizzle` node in v1.38 documents, extending support to nodes with explicit `nodedef` attributes, while maintaining support for nodes without them. An example of this usage has been added to the `TestSuite/stdlib/upgrade` folder for validation in unit testing.
1 parent 7abbbdc commit 017dfaa

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

resources/Materials/TestSuite/stdlib/upgrade/syntax_1_38.mtlx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,15 @@
6363
<input name="surfaceshader" type="surfaceshader" nodename="N_surface_3" />
6464
</surfacematerial>
6565

66+
<swizzle name="N_swizzle" type="color3" nodedef="ND_swizzle_color3_color3">
67+
<input name="in" type="color3" value="0.8, 0.7, 0.6" />
68+
<input name="channels" type="string" value="bgr" />
69+
</swizzle>
70+
<standard_surface name="N_surface_4" type="surfaceshader">
71+
<input name="base_color" type="color3" nodename="N_swizzle" />
72+
</standard_surface>
73+
<surfacematerial name="N_material_4" type="material">
74+
<input name="surfaceshader" type="surfaceshader" nodename="N_surface_4" />
75+
</surfacematerial>
76+
6677
</materialx>

source/MaterialXCore/Version.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ void Document::upgradeVersion()
11911191
{
11921192
// Replace swizzle with constant.
11931193
node->setCategory("constant");
1194+
node->removeAttribute(InterfaceElement::NODE_DEF_ATTRIBUTE);
11941195
string valueString = inInput->getValueString();
11951196
StringVec origValueTokens = splitString(valueString, ARRAY_VALID_SEPARATORS);
11961197
StringVec newValueTokens;
@@ -1228,6 +1229,7 @@ void Document::upgradeVersion()
12281229
{
12291230
// Replace swizzle with extract.
12301231
node->setCategory("extract");
1232+
node->removeAttribute(InterfaceElement::NODE_DEF_ATTRIBUTE);
12311233
if (!channelString.empty() && CHANNEL_INDEX_MAP.count(channelString[0]))
12321234
{
12331235
node->setInputValue("index", (int) CHANNEL_INDEX_MAP.at(channelString[0]));
@@ -1238,11 +1240,13 @@ void Document::upgradeVersion()
12381240
{
12391241
// Replace swizzle with convert.
12401242
node->setCategory("convert");
1243+
node->removeAttribute(InterfaceElement::NODE_DEF_ATTRIBUTE);
12411244
}
12421245
else if (sourceChannelCount == 1)
12431246
{
12441247
// Replace swizzle with combine.
12451248
node->setCategory("combine" + std::to_string(destChannelCount));
1249+
node->removeAttribute(InterfaceElement::NODE_DEF_ATTRIBUTE);
12461250
for (size_t i = 0; i < destChannelCount; i++)
12471251
{
12481252
InputPtr combineInInput = node->addInput(std::string("in") + std::to_string(i + 1), "float");
@@ -1269,6 +1273,7 @@ void Document::upgradeVersion()
12691273
graph->setChildIndex(separateNode->getName(), childIndex);
12701274
}
12711275
node->setCategory("combine" + std::to_string(destChannelCount));
1276+
node->removeAttribute(InterfaceElement::NODE_DEF_ATTRIBUTE);
12721277
for (size_t i = 0; i < destChannelCount; i++)
12731278
{
12741279
InputPtr combineInInput = node->addInput(std::string("in") + std::to_string(i + 1), "float");

0 commit comments

Comments
 (0)