Skip to content

Commit

Permalink
Fixup: Removed redundant vectors, simplified matching convert patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
nadult committed Aug 7, 2024
1 parent d191119 commit 752f06a
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions source/MaterialXCore/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,26 +992,14 @@ void Document::upgradeVersion()
{ "color3", 3 }, { "color4", 4 },
{ "vector2", 2 }, { "vector3", 3 }, { "vector4", 4 }
};
const vector<std::pair<std::string, size_t>> CHANNEL_CONVERT_PATTERNS =
const std::pair<std::string, size_t> CHANNEL_CONVERT_PATTERNS[] =
{
{ "rgb", 3 }, { "rgb", 4 }, { "rgba", 4 },
{ "xyz", 3 }, { "xyz", 4 }, { "xyzw", 4 },
{ "rr", 1 }, { "rrr", 1 },
{ "xx", 1 }, { "xxx", 1 }
};
auto matchesConvertPattern = [&](const string& channels, size_t sourceChannelCount)
{
for (auto& pattern : CHANNEL_CONVERT_PATTERNS)
{
if (pattern == std::make_pair(channels, sourceChannelCount))
{
return true;
}
}
return false;
};

const vector<std::pair<StringSet, string>> CHANNEL_ATTRIBUTE_PATTERNS =
const std::pair<StringSet, string> CHANNEL_ATTRIBUTE_PATTERNS[] =
{
{ { "xx", "xxx", "xxxx" }, "float" },
{ { "xyz", "x", "y", "z" }, "vector3" },
Expand Down Expand Up @@ -1245,7 +1233,9 @@ void Document::upgradeVersion()
node->setInputValue("index", (int) CHANNEL_INDEX_MAP.at(channelString[0]));
}
}
else if (sourceType != destType && matchesConvertPattern(channelString, sourceChannelCount))
else if (sourceType != destType &&
std::find(std::begin(CHANNEL_CONVERT_PATTERNS), std::end(CHANNEL_CONVERT_PATTERNS),
std::make_pair(channelString, sourceChannelCount)) != std::end(CHANNEL_CONVERT_PATTERNS))
{
// Replace swizzle with convert.
node->setCategory("convert");
Expand Down

0 comments on commit 752f06a

Please sign in to comment.