/
FaceInstance.h
198 lines (149 loc) · 5.57 KB
/
FaceInstance.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#pragma once
#include "math/Plane3.h"
#include "math/Line.h"
#include "render.h"
#include "render/VectorLightList.h"
#include "ObservedSelectable.h"
#include "SelectableComponents.h"
#include "VertexSelection.h"
#include "Face.h"
#include "Brush.h"
typedef const Plane3* PlanePointer;
typedef PlanePointer* PlanesIterator;
class RenderableCollector;
class FaceInstance;
typedef std::list<FaceInstance*> FaceInstanceSet;
class FaceInstance
{
private:
Face* m_face;
SelectionChangedSlot m_selectionChanged;
selection::ObservedSelectable m_selectable;
selection::ObservedSelectable m_selectableVertices;
selection::ObservedSelectable m_selectableEdges;
VertexSelection m_vertexSelection;
VertexSelection m_edgeSelection;
static FaceInstanceSet _selectedFaceInstances;
public:
mutable render::lib::VectorLightList m_lights;
FaceInstance(Face& face, const SelectionChangedSlot& observer);
FaceInstance(const FaceInstance& other);
FaceInstance& operator=(const FaceInstance& other);
Face& getFace();
const Face& getFace() const;
void selectedChanged(const ISelectable& selectable);
bool selectedVertices() const;
bool selectedEdges() const;
bool isSelected() const;
bool selectedComponents() const;
bool selectedComponents(SelectionSystem::EComponentMode mode) const;
void setSelected(SelectionSystem::EComponentMode mode, bool select);
void invertSelected();
template<typename Functor>
void SelectedVertices_foreach(Functor functor) const {
for (VertexSelection::const_iterator i = m_vertexSelection.begin(); i != m_vertexSelection.end(); ++i) {
std::size_t index = getFace().getWinding().findAdjacent(*i);
if (index != brush::c_brush_maxFaces) {
functor(getFace().getWinding()[index].vertex);
}
}
}
template<typename Functor>
void SelectedEdges_foreach(Functor functor) const {
for (VertexSelection::const_iterator i = m_edgeSelection.begin(); i != m_edgeSelection.end(); ++i) {
std::size_t index = getFace().getWinding().findAdjacent(*i);
if (index != brush::c_brush_maxFaces) {
const Winding& winding = getFace().getWinding();
std::size_t adjacent = winding.next(index);
functor(winding[index].vertex.mid(winding[adjacent].vertex));
}
}
}
template<typename Functor>
void SelectedFaces_foreach(Functor functor) const {
if (isSelected()) {
functor(centroid());
}
}
template<typename Functor>
void SelectedComponents_foreach(Functor functor) const {
SelectedVertices_foreach(functor);
SelectedEdges_foreach(functor);
SelectedFaces_foreach(functor);
}
void iterate_selected(AABB& aabb) const;
class RenderablePointVectorPushBack {
RenderablePointVector& m_points;
public:
RenderablePointVectorPushBack(RenderablePointVector& points) : m_points(points) {}
void operator()(const Vector3& point) const {
const Colour4b colour_selected(0, 0, 255, 255);
m_points.push_back(VertexCb(point, colour_selected));
}
};
void iterate_selected(RenderablePointVector& points) const;
bool intersectVolume(const VolumeTest& volume) const;
bool intersectVolume(const VolumeTest& volume, const Matrix4& localToWorld) const;
// Frontend render methods for submitting the face to the given collector
void renderSolid(RenderableCollector& collector, const VolumeTest& volume,
const IRenderEntity& entity) const;
void renderWireframe(RenderableCollector& collector, const VolumeTest& volume,
const IRenderEntity& entity) const;
void testSelect(SelectionTest& test, SelectionIntersection& best);
void testSelect(Selector& selector, SelectionTest& test);
void testSelect_centroid(Selector& selector, SelectionTest& test);
void selectPlane(Selector& selector, const Line& line, PlanesIterator first, PlanesIterator last, const PlaneCallback& selectedPlaneCallback);
void selectReversedPlane(Selector& selector, const SelectedPlanes& selectedPlanes);
void transformComponents(const Matrix4& matrix);
void snapto(float snap);
void snapComponents(float snap);
void update_move_planepts_vertex(std::size_t index);
void update_move_planepts_vertex2(std::size_t index, std::size_t other);
void update_selection_vertex();
void select_vertex(std::size_t index, bool select);
bool selected_vertex(std::size_t index) const;
void update_move_planepts_edge(std::size_t index);
void update_selection_edge();
void select_edge(std::size_t index, bool select);
bool selected_edge(std::size_t index) const;
const Vector3& centroid() const;
void connectivityChanged();
void addLight(const Matrix4& localToWorld, const RendererLight& light);
bool faceIsVisible() const
{
return m_face->faceIsVisible();
}
void updateFaceVisibility();
// greebo: Provides access to the set of selected face instances
// This should be a replacement for the old g_SelectedFaceInstances global.
static FaceInstanceSet& Selection();
}; // class FaceInstance
// ===========================================================================================
typedef std::vector<FaceInstance> FaceInstances;
/*class FaceInstanceSet
{
typedef SelectionList<FaceInstance> FaceInstances;
FaceInstances m_faceInstances;
public:
void insert(FaceInstance& faceInstance) {
m_faceInstances.append(faceInstance);
}
void erase(FaceInstance& faceInstance) {
m_faceInstances.erase(faceInstance);
}
template<typename Functor>
void foreach(Functor& functor) {
for (FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i) {
functor(*(*i));
}
}
bool empty() const {
return m_faceInstances.empty();
}
FaceInstance& last() const {
return m_faceInstances.back();
}
std::size_t size() const {
return m_faceInstances.size();
}
};*/