Skip to content

Commit

Permalink
#5584: Refactor rendering of selected brush vertices
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 21, 2022
1 parent 20dca7a commit b2a1d33
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 23 deletions.
4 changes: 3 additions & 1 deletion include/ibrush.h
Expand Up @@ -23,9 +23,11 @@ class IBrushSettings
virtual ~IBrushSettings() {}

virtual const Vector3& getVertexColour() const = 0;

virtual void setVertexColour(const Vector3& colour) = 0;

virtual const Vector3& getSelectedVertexColour() const = 0;
virtual void setSelectedVertexColour(const Vector3& colour) = 0;

virtual sigc::signal<void>& signal_settingsChanged() = 0;
};

Expand Down
19 changes: 13 additions & 6 deletions radiantcore/brush/BrushNode.cpp
Expand Up @@ -15,10 +15,9 @@
BrushNode::BrushNode() :
scene::SelectableNode(),
m_brush(*this),
_selectedPoints(GL_POINTS),
_renderableComponentsNeedUpdate(true),
_untransformedOriginChanged(true),
_renderableVertices(m_brush)
_renderableVertices(m_brush, _selectedPoints)
{
m_brush.attach(*this); // BrushObserver

Expand All @@ -40,10 +39,9 @@ BrushNode::BrushNode(const BrushNode& other) :
PlaneSelectable(other),
Transformable(other),
m_brush(*this, other.m_brush),
_selectedPoints(GL_POINTS),
_renderableComponentsNeedUpdate(true),
_untransformedOriginChanged(true),
_renderableVertices(m_brush)
_renderableVertices(m_brush, _selectedPoints)
{
m_brush.attach(*this); // BrushObserver
}
Expand Down Expand Up @@ -366,6 +364,8 @@ void BrushNode::onPreRender(const VolumeTest& volume)

if (isSelected() && GlobalSelectionSystem().Mode() == selection::SelectionSystem::eComponent)
{
updateSelectedPointsArray();

_renderableVertices.setComponentMode(GlobalSelectionSystem().ComponentMode());
_renderableVertices.update(_pointShader);
}
Expand Down Expand Up @@ -618,7 +618,7 @@ void BrushNode::renderWireframe(IRenderableCollector& collector, const VolumeTes
}
#endif

void BrushNode::updateSelectedPointsArray() const
void BrushNode::updateSelectedPointsArray()
{
if (!_renderableComponentsNeedUpdate) return;

Expand All @@ -630,22 +630,29 @@ void BrushNode::updateSelectedPointsArray() const
{
if (faceInstance.getFace().contributes())
{
faceInstance.iterate_selected(_selectedPoints);
faceInstance.SelectedComponents_foreach([&](const Vector3& vertex)
{
_selectedPoints.push_back(vertex);
});
}
}

_renderableVertices.queueUpdate();
}

void BrushNode::renderSelectedPoints(IRenderableCollector& collector,
const VolumeTest& volume,
const Matrix4& localToWorld) const
{
#if 0
updateSelectedPointsArray();

if (!_selectedPoints.empty())
{
collector.setHighlightFlag(IRenderableCollector::Highlight::Primitives, false);
collector.addRenderable(*m_state_selpoint, _selectedPoints, localToWorld);
}
#endif
}

void BrushNode::evaluateTransform()
Expand Down
6 changes: 3 additions & 3 deletions radiantcore/brush/BrushNode.h
Expand Up @@ -42,8 +42,8 @@ class BrushNode :
typedef std::vector<brush::VertexInstance> VertexInstances;
VertexInstances m_vertexInstances;

// Renderable array of vertex and edge points
mutable RenderablePointVector _selectedPoints;
// All selectable points (corner vertices / edge or face centroids)
std::vector<Vector3> _selectedPoints;

mutable AABB m_aabb_component;
BrushClipPlane m_clipPlane;
Expand Down Expand Up @@ -188,7 +188,7 @@ class BrushNode :
void renderWireframe(IRenderableCollector& collector, const VolumeTest& volume, const Matrix4& localToWorld) const;
#endif

void updateSelectedPointsArray() const;
void updateSelectedPointsArray();
void renderSelectedPoints(IRenderableCollector& collector,
const VolumeTest& volume,
const Matrix4& localToWorld) const;
Expand Down
18 changes: 16 additions & 2 deletions radiantcore/brush/BrushSettings.h
Expand Up @@ -10,12 +10,14 @@ class BrushSettings :
public IBrushSettings
{
private:
Vector3 _vertexColour;
Vector3 _vertexColour;
Vector3 _selectedVertexColour;

sigc::signal<void> _signalSettingsChanged;
public:
BrushSettings() :
_vertexColour(0, 1, 0)
_vertexColour(0, 1, 0),
_selectedVertexColour(0, 0, 1)
{}

const Vector3& getVertexColour() const override
Expand All @@ -30,6 +32,18 @@ class BrushSettings :
_signalSettingsChanged.emit();
}

const Vector3& getSelectedVertexColour() const override
{
return _selectedVertexColour;
}

void setSelectedVertexColour(const Vector3& colour) override
{
_selectedVertexColour = colour;

_signalSettingsChanged.emit();
}

sigc::signal<void>& signal_settingsChanged() override
{
return _signalSettingsChanged;
Expand Down
35 changes: 25 additions & 10 deletions radiantcore/brush/RenderableBrushVertices.cpp
Expand Up @@ -6,6 +6,25 @@
namespace brush
{

namespace detail
{

inline void addColouredVertices(const std::vector<Vector3>& sourceVertices, const Vector4& colour,
std::vector<ArbitraryMeshVertex>& vertices, std::vector<unsigned int>& indices)
{
unsigned int indexOffset = vertices.size();

for (unsigned int i = 0; i < sourceVertices.size(); ++i)
{
const auto& vertex = sourceVertices[i];

vertices.push_back(ArbitraryMeshVertex(vertex, { 0,0,0 }, { 0,0 }, colour));
indices.push_back(indexOffset + i);
}
}

}

void RenderableBrushVertices::updateGeometry()
{
if (!_updateNeeded) return;
Expand All @@ -18,19 +37,15 @@ void RenderableBrushVertices::updateGeometry()
std::vector<ArbitraryMeshVertex> vertices;
std::vector<unsigned int> indices;

vertices.reserve(brushVertices.size());
indices.reserve(brushVertices.size());
auto totalSize = brushVertices.size() + _selectedVertices.size();
vertices.reserve(totalSize);
indices.reserve(totalSize);

static const Vector3& vertexColour = GlobalBrushCreator().getSettings().getVertexColour();
const Vector4 colour(vertexColour, 1);
static const Vector3& selectedVertexColour = GlobalBrushCreator().getSettings().getSelectedVertexColour();

for (auto i = 0; i < brushVertices.size(); ++i)
{
const auto& vertex = brushVertices[i];

vertices.push_back(ArbitraryMeshVertex(vertex, { 0,0,0 }, { 0,0 }, colour));
indices.push_back(i);
}
detail::addColouredVertices(brushVertices, { vertexColour, 1 }, vertices, indices);
detail::addColouredVertices(_selectedVertices, { selectedVertexColour, 1 }, vertices, indices);

RenderableGeometry::updateGeometry(render::GeometryType::Points, vertices, indices);
}
Expand Down
4 changes: 3 additions & 1 deletion radiantcore/brush/RenderableBrushVertices.h
Expand Up @@ -17,15 +17,17 @@ class RenderableBrushVertices :
{
private:
Brush& _brush;
const std::vector<Vector3>& _selectedVertices;

// The mode this renderable has been configured for
selection::ComponentSelectionMode _mode;

bool _updateNeeded;

public:
RenderableBrushVertices(Brush& brush) :
RenderableBrushVertices(Brush& brush, const std::vector<Vector3>& selectedVertices) :
_brush(brush),
_selectedVertices(selectedVertices),
_updateNeeded(true)
{}

Expand Down

0 comments on commit b2a1d33

Please sign in to comment.