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
|
#include "Node.h"
#include "math/Vector2.h"
#include "math/Matrix4.h"
#include "itexturetoolcolours.h"
#include <sigc++/functors/mem_fun.h>
#include <GL/glew.h>
namespace textool
{
Node::Node() :
_selectable(std::bind(&Node::onSelectionStatusChanged, this, std::placeholders::_1))
{}
void Node::setSelected(bool select)
{
_selectable.setSelected(select);
}
bool Node::isSelected() const
{
return _selectable.isSelected();
}
bool Node::hasSelectedComponents() const
{
for (auto& vertex : _vertices)
{
if (vertex.isSelected())
{
return true;
}
}
return false;
}
std::size_t Node::getNumSelectedComponents() const
{
std::size_t count = 0;
for (const auto& vertex : _vertices)
{
if (vertex.isSelected())
{
++count;
}
}
return count;
}
void Node::clearComponentSelection()
{
for (auto& vertex : _vertices)
{
vertex.setSelected(false);
}
}
void Node::testSelectComponents(Selector& selector, SelectionTest& test)
{
test.BeginMesh(Matrix4::getIdentity(), true);
for (auto& vertex : _vertices)
{
SelectionIntersection intersection;
test.TestPoint(Vector3(vertex.getTexcoord().x(), vertex.getTexcoord().y(), 0), intersection);
if (intersection.isValid())
{
selector.addWithNullIntersection(vertex);
}
}
}
AABB Node::getSelectedComponentBounds()
{
AABB bounds;
for (const auto& vertex : _vertices)
{
if (!vertex.isSelected()) continue;
bounds.includePoint({ vertex.getTexcoord().x(), vertex.getTexcoord().y(), 0 });
}
return bounds;
}
void Node::expandComponentSelectionToRelated()
{
if (!hasSelectedComponents())
{
return;
}
for (auto& vertex : _vertices)
{
vertex.setSelected(true);
}
}
Colour4 Node::getSurfaceColour(SelectionMode mode)
{
if (mode == SelectionMode::Surface && isSelected())
{
return GlobalTextureToolColourSchemeManager().getColour(SchemeElement::SelectedSurface);
}
else if (mode == SelectionMode::Vertex)
{
return GlobalTextureToolColourSchemeManager().getColour(SchemeElement::SurfaceInComponentMode);
}
else
{
return GlobalTextureToolColourSchemeManager().getColour(SchemeElement::SurfaceInSurfaceMode);
}
}
void Node::renderComponents()
{
glPointSize(5);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glBegin(GL_POINTS);
auto deselectedColour = GlobalTextureToolColourSchemeManager().getColour(SchemeElement::Vertex);
auto selectedColour = GlobalTextureToolColourSchemeManager().getColour(SchemeElement::SelectedVertex);
for (const auto& vertex : _vertices)
{
if (vertex.isSelected())
{
glColor4fv(selectedColour);
}
else
{
glColor4fv(deselectedColour);
}
// Move the selected vertices a bit up in the Z area
glVertex3d(vertex.getTexcoord().x(), vertex.getTexcoord().y(), vertex.isSelected() ? 0.1f : 0);
}
glEnd();
glDisable(GL_DEPTH_TEST);
}
void Node::onSelectionStatusChanged(const ISelectable& selectable)
{
GlobalTextureToolSelectionSystem().onNodeSelectionChanged(*this);
}
}
|