diff --git a/source/MaterialXCore/Version.cpp b/source/MaterialXCore/Version.cpp index 668c233bb7..34d9b3b02c 100644 --- a/source/MaterialXCore/Version.cpp +++ b/source/MaterialXCore/Version.cpp @@ -992,16 +992,19 @@ void Document::upgradeVersion() { "color3", 3 }, { "color4", 4 }, { "vector2", 2 }, { "vector3", 3 }, { "vector4", 4 } }; - const StringSet CHANNEL_CONVERT_PATTERNS = - { - "rgb", "rgba", "xyz", "xyzw", "rrr", "xxx" - }; - const vector> CHANNEL_ATTRIBUTE_PATTERNS = - { + const std::array, 10> CHANNEL_CONVERT_PATTERNS = + { { + { "rgb", 3 }, { "rgb", 4 }, { "rgba", 4 }, + { "xyz", 3 }, { "xyz", 4 }, { "xyzw", 4 }, + { "rr", 1 }, { "rrr", 1 }, + { "xx", 1 }, { "xxx", 1 } + } }; + const std::array, 3> CHANNEL_ATTRIBUTE_PATTERNS = + { { { { "xx", "xxx", "xxxx" }, "float" }, { { "xyz", "x", "y", "z" }, "vector3" }, { { "rgba", "a" }, "color4" } - }; + } }; // Convert channels attributes to legacy swizzle nodes, which are then converted // to modern nodes in a second pass. @@ -1169,8 +1172,10 @@ void Document::upgradeVersion() CHANNEL_COUNT_MAP.count(node->getType())) { string channelString = channelsInput ? channelsInput->getValueString() : EMPTY_STRING; - size_t sourceChannelCount = CHANNEL_COUNT_MAP.at(inInput->getType()); - size_t destChannelCount = CHANNEL_COUNT_MAP.at(node->getType()); + string sourceType = inInput->getType(); + string destType = node->getType(); + size_t sourceChannelCount = CHANNEL_COUNT_MAP.at(sourceType); + size_t destChannelCount = CHANNEL_COUNT_MAP.at(destType); // Resolve the invalid case of having both a connection and a value // by removing the value attribute. @@ -1228,7 +1233,8 @@ void Document::upgradeVersion() node->setInputValue("index", (int) CHANNEL_INDEX_MAP.at(channelString[0])); } } - else if (CHANNEL_CONVERT_PATTERNS.count(channelString)) + else if (sourceType != destType && std::find(CHANNEL_CONVERT_PATTERNS.begin(), CHANNEL_CONVERT_PATTERNS.end(), + std::make_pair(channelString, sourceChannelCount)) != CHANNEL_CONVERT_PATTERNS.end()) { // Replace swizzle with convert. node->setCategory("convert");