/
Scene.h
63 lines (50 loc) · 1.46 KB
/
Scene.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include <cstddef>
#include "inode.h"
#include "ientity.h"
#include "ibrush.h"
namespace test::algorithm
{
// Returns the n-th child of the given parent node
inline scene::INodePtr getNthChild(const scene::INodePtr& parent, std::size_t index)
{
std::size_t n = 0;
scene::INodePtr candidate;
parent->foreachNode([&](const scene::INodePtr& node)
{
if (n == index)
{
candidate = node;
return false;
}
++n;
return true;
});
return candidate;
}
// Finds the first matching child brush of the given parent node matching the given predicate
inline scene::INodePtr findFirstBrush(const scene::INodePtr& parent,
const std::function<bool(const IBrushNodePtr&)>& predicate)
{
scene::INodePtr candidate;
parent->foreachNode([&](const scene::INodePtr& node)
{
auto brushNode = std::dynamic_pointer_cast<IBrushNode>(node);
if (brushNode && predicate(brushNode))
{
candidate = node;
return false;
}
return true;
});
return candidate;
}
// Finds the first matching child brush of the given parent node, with any of the brush's faces matching the given material
inline scene::INodePtr findFirstBrushWithMaterial(const scene::INodePtr& parent, const std::string& material)
{
return findFirstBrush(parent, [&](const IBrushNodePtr& brush)
{
return brush->getIBrush().hasShader(material);
});
}
}