Skip to content

Commit 4d16d01

Browse files
Improvements to swizzle upgrade logic (#2282)
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. New examples of this usage have been added to the `TestSuite/stdlib/upgrade` folder for validation in unit testing.
1 parent 7abbbdc commit 4d16d01

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

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

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

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"/>
76+
<input name="channels" type="string" value="bgr" />
77+
</swizzle>
78+
<standard_surface name="N_surface_4" type="surfaceshader">
79+
<input name="base_color" type="color3" nodename="N_swizzle_3" />
80+
</standard_surface>
81+
<surfacematerial name="N_material_4" type="material">
82+
<input name="surfaceshader" type="surfaceshader" nodename="N_surface_4" />
83+
</surfacematerial>
84+
6685
</materialx>

source/MaterialXCore/Version.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,10 @@ void Document::upgradeVersion()
11911191
{
11921192
// Replace swizzle with constant.
11931193
node->setCategory("constant");
1194+
if (node->hasNodeDefString())
1195+
{
1196+
node->setNodeDefString("ND_constant_" + node->getType());
1197+
}
11941198
string valueString = inInput->getValueString();
11951199
StringVec origValueTokens = splitString(valueString, ARRAY_VALID_SEPARATORS);
11961200
StringVec newValueTokens;
@@ -1228,6 +1232,10 @@ void Document::upgradeVersion()
12281232
{
12291233
// Replace swizzle with extract.
12301234
node->setCategory("extract");
1235+
if (node->hasNodeDefString())
1236+
{
1237+
node->setNodeDefString("ND_extract_" + node->getType());
1238+
}
12311239
if (!channelString.empty() && CHANNEL_INDEX_MAP.count(channelString[0]))
12321240
{
12331241
node->setInputValue("index", (int) CHANNEL_INDEX_MAP.at(channelString[0]));
@@ -1238,11 +1246,19 @@ void Document::upgradeVersion()
12381246
{
12391247
// Replace swizzle with convert.
12401248
node->setCategory("convert");
1249+
if (node->hasNodeDefString())
1250+
{
1251+
node->setNodeDefString("ND_convert_" + sourceType + "_" + destType);
1252+
}
12411253
}
12421254
else if (sourceChannelCount == 1)
12431255
{
12441256
// Replace swizzle with combine.
12451257
node->setCategory("combine" + std::to_string(destChannelCount));
1258+
if (node->hasNodeDefString())
1259+
{
1260+
node->setNodeDefString("ND_combine" + std::to_string(destChannelCount) + "_" + node->getType());
1261+
}
12461262
for (size_t i = 0; i < destChannelCount; i++)
12471263
{
12481264
InputPtr combineInInput = node->addInput(std::string("in") + std::to_string(i + 1), "float");
@@ -1269,6 +1285,10 @@ void Document::upgradeVersion()
12691285
graph->setChildIndex(separateNode->getName(), childIndex);
12701286
}
12711287
node->setCategory("combine" + std::to_string(destChannelCount));
1288+
if (node->hasNodeDefString())
1289+
{
1290+
node->setNodeDefString("ND_combine" + std::to_string(destChannelCount) + "_" + node->getType());
1291+
}
12721292
for (size_t i = 0; i < destChannelCount; i++)
12731293
{
12741294
InputPtr combineInInput = node->addInput(std::string("in") + std::to_string(i + 1), "float");

0 commit comments

Comments
 (0)