/
TextureTool.cpp
156 lines (119 loc) · 5.75 KB
/
TextureTool.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "RadiantTest.h"
#include "imap.h"
#include "ipatch.h"
#include "iselectable.h"
#include "itexturetoolmodel.h"
#include "iselection.h"
#include "scenelib.h"
#include "algorithm/Primitives.h"
namespace test
{
using TextureToolTest = RadiantTest;
inline std::size_t getTextureToolNodeCount()
{
std::size_t count = 0;
GlobalTextureToolSceneGraph().foreachNode([&](const textool::INode::Ptr& node)
{
++count;
return true;
});
return count;
}
inline textool::INode::Ptr getFirstTextureToolNode()
{
textool::INode::Ptr returnValue;
GlobalTextureToolSceneGraph().foreachNode([&](const textool::INode::Ptr& node)
{
returnValue = node;
return false;
});
return returnValue;
}
// Checks that changing the regular scene selection will have an effect on the tex tool scene
TEST_F(TextureToolTest, SceneGraphObservesSelection)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brush1 = algorithm::createCubicBrush(worldspawn, Vector3(0,0,0), "textures/numbers/1");
auto brush2 = algorithm::createCubicBrush(worldspawn, Vector3(0,256,256), "textures/numbers/1");
// Empty tex tool scenegraph on empty scene selection
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0) << "Non-empty selection at startup";
EXPECT_EQ(getTextureToolNodeCount(), 0) << "There shouldn't be any textool nodes when the scene is empty";
Node_setSelected(brush1, true);
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1) << "1 Brush must be selected";
// We don't know how many tex tool nodes there are, but it should be more than 0
auto nodeCount = getTextureToolNodeCount();
EXPECT_GT(nodeCount, 0) << "There should be some tex tool nodes now";
Node_setSelected(brush2, true);
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 2) << "2 Brushes must be selected";
// Should be even more now
auto nodeCount2 = getTextureToolNodeCount();
EXPECT_GT(nodeCount2, nodeCount) << "There should be more tex tool nodes now";
GlobalSelectionSystem().setSelectedAll(false);
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0) << "Non-empty selection at shutdown";
EXPECT_EQ(getTextureToolNodeCount(), 0) << "There shouldn't be any textool nodes when the scene is empty";
}
TEST_F(TextureToolTest, SceneGraphNeedsUniqueShader)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brush1 = algorithm::createCubicBrush(worldspawn, Vector3(0, 0, 0), "textures/numbers/1");
auto brush2 = algorithm::createCubicBrush(worldspawn, Vector3(0, 256, 256), "textures/numbers/2");
Node_setSelected(brush1, true);
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1) << "1 Brush must be selected";
// We don't know how many tex tool nodes there are, but it should be more than 0
EXPECT_GT(getTextureToolNodeCount(), 0) << "There should be some tex tool nodes now";
Node_setSelected(brush2, true);
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 2) << "2 Brushes must be selected";
EXPECT_EQ(getTextureToolNodeCount(), 0) << "There should be no nodes now, since the material is non unique";
// Deselect brush 1, now only brush 2 is selected
Node_setSelected(brush1, false);
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1) << "1 Brush must be selected";
EXPECT_GT(getTextureToolNodeCount(), 0) << "There should be some tex tool nodes again";
}
TEST_F(TextureToolTest, SceneGraphRecognisesBrushes)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brush1 = algorithm::createCubicBrush(worldspawn, Vector3(0, 0, 0), "textures/numbers/1");
Node_setSelected(brush1, true);
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1) << "1 Brush must be selected";
// We don't know how many tex tool nodes there are, but it should be more than 0
EXPECT_GT(getTextureToolNodeCount(), 0) << "There should be some tex tool nodes now";
}
TEST_F(TextureToolTest, SceneGraphRecognisesPatches)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto patch = GlobalPatchModule().createPatch(patch::PatchDefType::Def2);
scene::addNodeToContainer(patch, worldspawn);
Node_setSelected(patch, true);
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1) << "1 patch must be selected";
// We don't know how many tex tool nodes there are, but it should be more than 0
EXPECT_GT(getTextureToolNodeCount(), 0) << "There should be some tex tool nodes now";
}
TEST_F(TextureToolTest, PatchNodeBounds)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto patchNode = GlobalPatchModule().createPatch(patch::PatchDefType::Def2);
auto patch = Node_getIPatch(patchNode);
patch->setDims(3, 3);
auto origin = Vector2(5.4, -78.3);
auto step = 0.45;
// Accumulate the test bounds
AABB checkedBounds;
for (auto col = 0; col < 3; ++col)
{
for (auto row = 0; row < 3; ++row)
{
auto& ctrl = patch->ctrlAt(row, col);
ctrl.texcoord = Vector2(origin.x() + step * col, origin.y() + step * row);
checkedBounds.includePoint({ ctrl.texcoord.x(), ctrl.texcoord.y(), 0 });
}
}
scene::addNodeToContainer(patchNode, worldspawn);
Node_setSelected(patchNode, true);
auto node = getFirstTextureToolNode();
EXPECT_TRUE(node) << "No texture tool node here";
EXPECT_TRUE(math::isNear(node->localAABB().getOrigin(), checkedBounds.getOrigin(), 0.01)) <<
"Bounds mismatch, got " << node->localAABB().getOrigin() << " instead of " << checkedBounds.getOrigin();
EXPECT_TRUE(math::isNear(node->localAABB().getExtents(), checkedBounds.getExtents(), 0.01)) <<
"Bounds mismatch, got " << node->localAABB().getExtents() << " instead of " << checkedBounds.getExtents();
}
}