in GLTFSDK/Inc/GLTFSDK/Traverse.h [24:75]
void TraverseDepthFirst(const Node& node, const Document& gltfDocument, Fn& fn)
{
struct StackValue
{
StackValue(const Node& node, const Node* nodeParent = nullptr) :
m_node(node),
m_nodeParent(nodeParent),
m_childIndex(0UL),
m_childCount(node.children.size())
{
}
bool HasChildren() const
{
return m_childIndex < m_childCount;
}
const Node& m_node;
const Node* const m_nodeParent;
size_t m_childIndex;
const size_t m_childCount;
bool m_visited = false;
};
typedef std::stack<StackValue> Stack;
Stack stack;
stack.emplace(node);
do
{
auto& currentNodeValue = stack.top();
auto& currentNode = currentNodeValue.m_node;
if (!currentNodeValue.m_visited)
{
currentNodeValue.m_visited = true;
fn(currentNode, currentNodeValue.m_nodeParent);
}
if (currentNodeValue.HasChildren())
{
stack.emplace(gltfDocument.nodes.Get(currentNode.children[currentNodeValue.m_childIndex++]), ¤tNode);
}
else
{
stack.pop();
}
} while (!stack.empty());
}