Skip to content

Commit 63f155f

Browse files
Replace rather than delete nodedef strings
This changelist updates the upgrade logic to replace rather than delete nodedef strings, following the pattern recommended by Karen at Pixar.
1 parent 017dfaa commit 63f155f

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,20 @@
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" />
66+
<swizzle name="N_swizzle_1" type="color3" nodedef="ND_swizzle_color3_color3">
67+
<input name="in" type="color3" value="0.4, 0.5, 0.6" />
68+
<input name="channels" type="string" value="bgr" />
69+
</swizzle>
70+
<swizzle name="N_swizzle_2" type="color4" nodedef="ND_swizzle_color3_color4">
71+
<input name="in" type="color3" nodename="N_swizzle_1" />
72+
<input name="channels" type="string" value="rgb1" />
73+
</swizzle>
74+
<swizzle name="N_swizzle_3" type="color3">
75+
<input name="in" type="color4" nodename="N_swizzle_2" nodedef="ND_swizzle_color4_color3"/>
6876
<input name="channels" type="string" value="bgr" />
6977
</swizzle>
7078
<standard_surface name="N_surface_4" type="surfaceshader">
71-
<input name="base_color" type="color3" nodename="N_swizzle" />
79+
<input name="base_color" type="color3" nodename="N_swizzle_3" />
7280
</standard_surface>
7381
<surfacematerial name="N_material_4" type="material">
7482
<input name="surfaceshader" type="surfaceshader" nodename="N_surface_4" />

source/MaterialXCore/Version.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,10 @@ void Document::upgradeVersion()
11911191
{
11921192
// Replace swizzle with constant.
11931193
node->setCategory("constant");
1194-
node->removeAttribute(InterfaceElement::NODE_DEF_ATTRIBUTE);
1194+
if (node->hasNodeDefString())
1195+
{
1196+
node->setNodeDefString("ND_constant_" + node->getType());
1197+
}
11951198
string valueString = inInput->getValueString();
11961199
StringVec origValueTokens = splitString(valueString, ARRAY_VALID_SEPARATORS);
11971200
StringVec newValueTokens;
@@ -1229,7 +1232,10 @@ void Document::upgradeVersion()
12291232
{
12301233
// Replace swizzle with extract.
12311234
node->setCategory("extract");
1232-
node->removeAttribute(InterfaceElement::NODE_DEF_ATTRIBUTE);
1235+
if (node->hasNodeDefString())
1236+
{
1237+
node->setNodeDefString("ND_extract_" + node->getType());
1238+
}
12331239
if (!channelString.empty() && CHANNEL_INDEX_MAP.count(channelString[0]))
12341240
{
12351241
node->setInputValue("index", (int) CHANNEL_INDEX_MAP.at(channelString[0]));
@@ -1240,13 +1246,19 @@ void Document::upgradeVersion()
12401246
{
12411247
// Replace swizzle with convert.
12421248
node->setCategory("convert");
1243-
node->removeAttribute(InterfaceElement::NODE_DEF_ATTRIBUTE);
1249+
if (node->hasNodeDefString())
1250+
{
1251+
node->setNodeDefString("ND_convert_" + sourceType + "_" + destType);
1252+
}
12441253
}
12451254
else if (sourceChannelCount == 1)
12461255
{
12471256
// Replace swizzle with combine.
12481257
node->setCategory("combine" + std::to_string(destChannelCount));
1249-
node->removeAttribute(InterfaceElement::NODE_DEF_ATTRIBUTE);
1258+
if (node->hasNodeDefString())
1259+
{
1260+
node->setNodeDefString("ND_combine" + std::to_string(destChannelCount) + "_" + node->getType());
1261+
}
12501262
for (size_t i = 0; i < destChannelCount; i++)
12511263
{
12521264
InputPtr combineInInput = node->addInput(std::string("in") + std::to_string(i + 1), "float");
@@ -1273,7 +1285,10 @@ void Document::upgradeVersion()
12731285
graph->setChildIndex(separateNode->getName(), childIndex);
12741286
}
12751287
node->setCategory("combine" + std::to_string(destChannelCount));
1276-
node->removeAttribute(InterfaceElement::NODE_DEF_ATTRIBUTE);
1288+
if (node->hasNodeDefString())
1289+
{
1290+
node->setNodeDefString("ND_combine" + std::to_string(destChannelCount) + "_" + node->getType());
1291+
}
12771292
for (size_t i = 0; i < destChannelCount; i++)
12781293
{
12791294
InputPtr combineInInput = node->addInput(std::string("in") + std::to_string(i + 1), "float");

0 commit comments

Comments
 (0)