Skip to content

Commit

Permalink
#5584: Clip Plane rendering migrated to shader-attached windings.
Browse files Browse the repository at this point in the history
Brushes now update their clip plane when their selection status is changing.
  • Loading branch information
codereader committed Dec 21, 2021
1 parent 91cc631 commit 1f90c3e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
4 changes: 4 additions & 0 deletions include/iclipper.h
Expand Up @@ -3,6 +3,7 @@
#include "imodule.h"
#include "iorthoview.h"
#include "math/Vector3.h"
#include "math/Plane3.h"

// The possible split modes
enum EBrushSplit {
Expand Down Expand Up @@ -68,6 +69,9 @@ class IClipper :

// Updates the clip plane information
virtual void update() = 0;

// Returns the currently active clip plane (might be invalid)
virtual const Plane3& getClipPlane() = 0;
};

// The accessor for the clipper module
Expand Down
22 changes: 18 additions & 4 deletions radiantcore/brush/BrushClipPlane.h
Expand Up @@ -4,34 +4,45 @@
#include "irender.h"
#include "irenderable.h"
#include "Winding.h"
#include "RenderableWinding.h"

class BrushClipPlane :
public OpenGLRenderable
public render::RenderableWinding
{
private:
Plane3 _plane;
Winding _winding;
ShaderPtr _shader;

public:
BrushClipPlane() :
RenderableWinding(_winding)
{}

virtual ~BrushClipPlane() {}

void setPlane(const Brush& brush, const Plane3& plane)
void setPlane(const Brush& brush, const Plane3& plane, IRenderEntity& entity)
{
_plane = plane;

if (_plane.isValid())
{
brush.windingForClipPlane(_winding, _plane);

_winding.updateNormals(_plane.normal());

// Update the RenderableWinding
queueUpdate();
update(_shader, entity);
}
else
{
_winding.resize(0);
clear();
}

_winding.updateNormals(_plane.normal());
}

#if 0
void render(const RenderInfo& info) const override
{
if (info.checkFlag(RENDER_FILL))
Expand All @@ -43,6 +54,7 @@ class BrushClipPlane :
_winding.drawWireframe();
}
}
#endif

void setRenderSystem(const RenderSystemPtr& renderSystem)
{
Expand All @@ -56,8 +68,10 @@ class BrushClipPlane :
}
}

#if 0
void render(IRenderableCollector& collector, const VolumeTest& volume, const Matrix4& localToWorld) const
{
collector.addRenderable(*_shader, *this, localToWorld);
}
#endif
};
27 changes: 24 additions & 3 deletions radiantcore/brush/BrushNode.cpp
Expand Up @@ -426,7 +426,7 @@ void BrushNode::renderHighlights(IRenderableCollector& collector, const VolumeTe

if (wholeBrushSelected && GlobalClipper().clipMode())
{
m_clipPlane.render(collector, volume, Matrix4::getIdentity());
collector.addHighlightRenderable(m_clipPlane, Matrix4::getIdentity());
}

collector.setHighlightFlag(IRenderableCollector::Highlight::Primitives, false);
Expand Down Expand Up @@ -704,8 +704,12 @@ void BrushNode::transformComponents(const Matrix4& matrix) {
}
}

void BrushNode::setClipPlane(const Plane3& plane) {
m_clipPlane.setPlane(m_brush, plane);
void BrushNode::setClipPlane(const Plane3& plane)
{
if (_renderEntity)
{
m_clipPlane.setPlane(m_brush, plane, *_renderEntity);
}
}

void BrushNode::forEachFaceInstance(const std::function<void(FaceInstance&)>& functor)
Expand Down Expand Up @@ -769,4 +773,21 @@ void BrushNode::onVisibilityChanged(bool isVisibleNow)
{
face.getFace().onBrushVisibilityChanged(isVisibleNow);
});

m_clipPlane.clear();
}

void BrushNode::onSelectionStatusChange(bool changeGroupStatus)
{
SelectableNode::onSelectionStatusChange(changeGroupStatus);

// In clip mode we need to check if there's an active clip plane defined in the scene
if (isSelected() && GlobalClipper().clipMode())
{
setClipPlane(GlobalClipper().getClipPlane());
}
else
{
m_clipPlane.clear();
}
}
2 changes: 2 additions & 0 deletions radiantcore/brush/BrushNode.h
Expand Up @@ -186,6 +186,8 @@ class BrushNode :
// or when reverting transformations.
void _applyTransformation() override;

void onSelectionStatusChange(bool changeGroupStatus) override;

private:
void transformComponents(const Matrix4& matrix);

Expand Down
6 changes: 6 additions & 0 deletions radiantcore/clipper/Clipper.cpp
Expand Up @@ -137,8 +137,14 @@ void Clipper::getPlanePoints(Vector3 planepts[3], const AABB& bounds) const {
}
}

const Plane3& Clipper::getClipPlane()
{
return _clipPlane;
}

void Clipper::setClipPlane(const Plane3& plane)
{
_clipPlane = plane;
algorithm::setBrushClipPlane(plane);
}

Expand Down
6 changes: 5 additions & 1 deletion radiantcore/clipper/Clipper.h
Expand Up @@ -11,7 +11,7 @@ namespace
const unsigned int NUM_CLIP_POINTS = 3;
}

class Clipper :
class Clipper final :
public IClipper
{
private:
Expand All @@ -32,6 +32,9 @@ class Clipper :
// The shader name used for new faces when _useCaulk is true
std::string _caulkShader;

// The plane defined by the clip points (might be invalid)
Plane3 _clipPlane;

private:
// Update the internally stored variables on registry key change
void keyChanged();
Expand Down Expand Up @@ -60,6 +63,7 @@ class Clipper :
void draw(float scale) override;
void getPlanePoints(Vector3 planepts[3], const AABB& bounds) const;

const Plane3& getClipPlane() override;
void setClipPlane(const Plane3& plane);

void update() override;
Expand Down

0 comments on commit 1f90c3e

Please sign in to comment.