From 95d9ee0a46c6df509f7c92f7fefc684cd9d4c092 Mon Sep 17 00:00:00 2001 From: ld-kerley <154285602+ld-kerley@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:14:40 -0800 Subject: [PATCH] Fix for custom node groups in graph editor menu (#1617) Currently if you have node definitions added to groups that aren't in the fixed list that MaterialXGraphEditor understands, then they won't be added to the menu. --- source/MaterialXGraphEditor/Graph.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/MaterialXGraphEditor/Graph.cpp b/source/MaterialXGraphEditor/Graph.cpp index fc682e8f05..f0d1791143 100644 --- a/source/MaterialXGraphEditor/Graph.cpp +++ b/source/MaterialXGraphEditor/Graph.cpp @@ -1248,6 +1248,7 @@ void Graph::createNodeUIList(mx::DocumentPtr doc) auto nodeDefs = doc->getNodeDefs(); std::unordered_map> groupToNodeDef; + std::vector groupList = std::vector(NODE_GROUP_ORDER.begin(), NODE_GROUP_ORDER.end()); for (const auto& nodeDef : nodeDefs) { @@ -1257,6 +1258,12 @@ void Graph::createNodeUIList(mx::DocumentPtr doc) group = NODE_GROUP_ORDER.back(); } + // If the group is not in the groupList already (seeded by NODE_GROUP_ORDER) then add it. + if (std::find(groupList.begin(), groupList.end(), group) == groupList.end()) + { + groupList.emplace_back(group); + } + if (groupToNodeDef.find(group) == groupToNodeDef.end()) { groupToNodeDef[group] = std::vector(); @@ -1264,7 +1271,7 @@ void Graph::createNodeUIList(mx::DocumentPtr doc) groupToNodeDef[group].push_back(nodeDef); } - for (const auto& group : NODE_GROUP_ORDER) + for (const auto& group : groupList) { auto it = groupToNodeDef.find(group); if (it != groupToNodeDef.end())