Skip to content

Commit

Permalink
#5795: Only run tests in evaluateViewDependent() if the visibility of…
Browse files Browse the repository at this point in the history
… any face actually changed. This can be the case either by forcing a brush to be visible or by its material filter status.
  • Loading branch information
codereader committed Oct 31, 2021
1 parent f35bc34 commit 115cdd2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion libs/scene/Node.h
Expand Up @@ -196,7 +196,7 @@ class Node :

protected:
// Set the "forced visible" flag, only to be used internally by subclasses
void setForcedVisibility(bool forceVisible, bool includeChildren) override;
virtual void setForcedVisibility(bool forceVisible, bool includeChildren) override;

// Method for subclasses to check whether this node is forcedly visible
bool isForcedVisible() const;
Expand Down
24 changes: 19 additions & 5 deletions radiantcore/brush/BrushNode.cpp
Expand Up @@ -15,6 +15,7 @@
BrushNode::BrushNode() :
scene::SelectableNode(),
m_brush(*this),
_faceVisibilityChanged(true),
_selectedPoints(GL_POINTS),
_faceCentroidPointsCulled(GL_POINTS),
m_viewChanged(false),
Expand Down Expand Up @@ -42,6 +43,7 @@ BrushNode::BrushNode(const BrushNode& other) :
LitObject(other),
Transformable(other),
m_brush(*this, other.m_brush),
_faceVisibilityChanged(true),
_selectedPoints(GL_POINTS),
_faceCentroidPointsCulled(GL_POINTS),
m_viewChanged(false),
Expand Down Expand Up @@ -355,7 +357,7 @@ void BrushNode::renderComponents(RenderableCollector& collector, const VolumeTes

if (volume.fill() && GlobalSelectionSystem().ComponentMode() == selection::ComponentSelectionMode::Face)
{
evaluateViewDependent(volume, l2w);
updateWireframeVisibility(volume, l2w);
collector.addRenderable(*m_brush.m_state_point, _faceCentroidPointsCulled, l2w);
}
else
Expand Down Expand Up @@ -418,11 +420,23 @@ std::size_t BrushNode::getHighlightFlags()
return isGroupMember() ? (Highlight::Selected | Highlight::GroupMember) : Highlight::Selected;
}

void BrushNode::evaluateViewDependent(const VolumeTest& volume, const Matrix4& localToWorld) const
void BrushNode::onFaceVisibilityChanged()
{
if (!m_viewChanged) return;
_faceVisibilityChanged = true;
}

void BrushNode::setForcedVisibility(bool forceVisible, bool includeChildren)
{
Node::setForcedVisibility(forceVisible, includeChildren);

_faceVisibilityChanged = true;
}

void BrushNode::updateWireframeVisibility(const VolumeTest& volume, const Matrix4& localToWorld) const
{
if (!_faceVisibilityChanged) return;

m_viewChanged = false;
_faceVisibilityChanged = false;

// Array of booleans to indicate which faces are visible
static bool faces_visible[brush::c_brush_maxFaces];
Expand Down Expand Up @@ -503,7 +517,7 @@ void BrushNode::renderWireframe(RenderableCollector& collector, const VolumeTest
{
//renderCommon(collector, volume);

evaluateViewDependent(volume, localToWorld);
updateWireframeVisibility(volume, localToWorld);

if (m_render_wireframe.m_size != 0)
{
Expand Down
9 changes: 8 additions & 1 deletion radiantcore/brush/BrushNode.h
Expand Up @@ -42,6 +42,8 @@ class BrushNode :
typedef std::vector<brush::VertexInstance> VertexInstances;
VertexInstances m_vertexInstances;

mutable bool _faceVisibilityChanged;

mutable RenderableWireframe m_render_wireframe;

// Renderable array of vertex and edge points
Expand Down Expand Up @@ -168,10 +170,15 @@ class BrushNode :
// Should only be used by the internal Brush object
bool facesAreForcedVisible();

// Will be invoked if one of this brush's faces updates its visibility status
void onFaceVisibilityChanged();

void onPostUndo() override;
void onPostRedo() override;

protected:
virtual void setForcedVisibility(bool forceVisible, bool includeChildren) override;

// Gets called by the Transformable implementation whenever
// scale, rotation or translation is changed.
void _onTransformationChanged() override;
Expand All @@ -192,7 +199,7 @@ class BrushNode :
const Matrix4& localToWorld) const;

void renderClipPlane(RenderableCollector& collector, const VolumeTest& volume) const;
void evaluateViewDependent(const VolumeTest& volume, const Matrix4& localToWorld) const;
void updateWireframeVisibility(const VolumeTest& volume, const Matrix4& localToWorld) const;

}; // class BrushNode
typedef std::shared_ptr<BrushNode> BrushNodePtr;
9 changes: 8 additions & 1 deletion radiantcore/brush/Face.cpp
Expand Up @@ -724,7 +724,14 @@ bool Face::isVisible() const

void Face::updateFaceVisibility()
{
_faceIsVisible = contributes() && getFaceShader().getGLShader()->getMaterial()->isVisible();
auto newValue = contributes() && getFaceShader().getGLShader()->getMaterial()->isVisible();

// Notify the owning brush if the value changes
if (newValue != _faceIsVisible)
{
_faceIsVisible = newValue;
_owner.getBrushNode().onFaceVisibilityChanged();
}
}

sigc::signal<void>& Face::signal_texdefChanged()
Expand Down

0 comments on commit 115cdd2

Please sign in to comment.