-
Notifications
You must be signed in to change notification settings - Fork 47
/
FaceNode.h
126 lines (97 loc) · 2.85 KB
/
FaceNode.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
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
#pragma once
#include "ibrush.h"
#include "NodeBase.h"
#include "math/Matrix3.h"
namespace textool
{
class FaceNode :
public NodeBase
{
private:
IFace& _face;
mutable AABB _bounds;
public:
FaceNode(IFace& face) :
_face(face)
{}
void beginTransformation() override
{
_face.undoSave();
}
void revertTransformation() override
{
_face.revertTransform();
}
void applyTransformToSelected(const Matrix3& transform) override
{
for (auto& vertex : _face.getWinding())
{
vertex.texcoord = transform * vertex.texcoord;
}
Vector3 vertices[3] = { _face.getWinding().at(0).vertex, _face.getWinding().at(1).vertex, _face.getWinding().at(2).vertex };
Vector2 texcoords[3] = { _face.getWinding().at(0).texcoord, _face.getWinding().at(1).texcoord, _face.getWinding().at(2).texcoord };
_face.setTexDefFromPoints(vertices, texcoords);
}
void commitTransformation() override
{
_face.freezeTransform();
}
const AABB& localAABB() const
{
_bounds = AABB();
for (const auto& vertex : _face.getWinding())
{
_bounds.includePoint({ vertex.texcoord.x(), vertex.texcoord.y(), 0 });
}
return _bounds;
}
void testSelect(Selector& selector, SelectionTest& test) override
{
// Arrange the UV coordinates in a Vector3 array for testing
std::vector<Vector3> uvs;
uvs.reserve(_face.getWinding().size());
for (const auto& vertex : _face.getWinding())
{
uvs.emplace_back(vertex.texcoord.x(), vertex.texcoord.y(), 0);
}
test.BeginMesh(Matrix4::getIdentity(), true);
SelectionIntersection best;
test.TestPolygon(VertexPointer(uvs.data(), sizeof(Vector3)), uvs.size(), best);
if (best.isValid())
{
Selector_add(selector, *this);
}
}
void render() override
{
glEnable(GL_BLEND);
glBlendColor(0, 0, 0, 0.3f);
glBlendFunc(GL_CONSTANT_ALPHA_EXT, GL_ONE_MINUS_CONSTANT_ALPHA_EXT);
if (isSelected())
{
glColor3f(1, 0.5f, 0);
}
else {
glColor3f(0.8f, 0.8f, 0.8f);
}
glBegin(GL_TRIANGLE_FAN);
for (const auto& vertex : _face.getWinding())
{
glVertex2d(vertex.texcoord[0], vertex.texcoord[1]);
}
glEnd();
glDisable(GL_BLEND);
glPointSize(5);
glBegin(GL_POINTS);
/*for (Winding::const_iterator i = _winding.begin(); i != _winding.end(); ++i)
{
glVertex2f(i->texcoord[0], i->texcoord[1]);
}*/
//glColor3f(1, 1, 1);
//Vector2 centroid = _face.getWinding();
//glVertex2d(centroid[0], centroid[1]);
glEnd();
glDisable(GL_BLEND);
}
};
}