Skip to content

Commit

Permalink
#5584: StaticGeometryNode's origin vertex is using RenderableGeometry…
Browse files Browse the repository at this point in the history
… now
  • Loading branch information
codereader committed Jan 22, 2022
1 parent fde64a9 commit fa3a453
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 9 deletions.
51 changes: 51 additions & 0 deletions radiantcore/entity/doom3group/RenderableVertex.h
@@ -0,0 +1,51 @@
#pragma once

#include "../VertexInstance.h"
#include "../EntitySettings.h"
#include "render/RenderableGeometry.h"

namespace entity
{

class RenderableVertex :
public render::RenderableGeometry
{
private:
const VertexInstance& _instance;
const Matrix4& _localToWorld;

bool _needsUpdate;

public:
RenderableVertex(const VertexInstance& instance, const Matrix4& localToWorld) :
_instance(instance),
_localToWorld(localToWorld),
_needsUpdate(true)
{}

void queueUpdate()
{
_needsUpdate = true;
}

protected:
void updateGeometry() override
{
if (!_needsUpdate) return;

_needsUpdate = false;

std::vector<ArbitraryMeshVertex> vertices;
static std::vector<unsigned int> Indices = { 0 };

auto colour = entity::EntitySettings::InstancePtr()->getLightVertexColour(
_instance.isSelected() ? LightEditVertexType::Selected : LightEditVertexType::Deselected
);

vertices.push_back(ArbitraryMeshVertex(_localToWorld * _instance.getVertex(), { 0,0,0 }, { 0,0 }, colour));

RenderableGeometry::updateGeometry(render::GeometryType::Points, vertices, Indices);
}
};

}
41 changes: 33 additions & 8 deletions radiantcore/entity/doom3group/StaticGeometryNode.cpp
Expand Up @@ -21,9 +21,10 @@ StaticGeometryNode::StaticGeometryNode(const IEntityClassPtr& eclass) :
std::bind(&StaticGeometryNode::selectionChangedComponent, this, std::placeholders::_1)),
_catmullRomEditInstance(m_curveCatmullRom,
std::bind(&StaticGeometryNode::selectionChangedComponent, this, std::placeholders::_1)),
_originInstance(VertexInstance(getOrigin(), std::bind(&StaticGeometryNode::selectionChangedComponent, this, std::placeholders::_1))),
_originInstance(getOrigin(), std::bind(&StaticGeometryNode::selectionChangedComponent, this, std::placeholders::_1)),
_nurbsVertices(m_curveNURBS, _nurbsEditInstance),
_catmullRomVertices(m_curveCatmullRom, _catmullRomEditInstance)
_catmullRomVertices(m_curveCatmullRom, _catmullRomEditInstance),
_renderableOriginVertex(_originInstance, localToWorld())
{}

StaticGeometryNode::StaticGeometryNode(const StaticGeometryNode& other) :
Expand All @@ -45,9 +46,10 @@ StaticGeometryNode::StaticGeometryNode(const StaticGeometryNode& other) :
std::bind(&StaticGeometryNode::selectionChangedComponent, this, std::placeholders::_1)),
_catmullRomEditInstance(m_curveCatmullRom,
std::bind(&StaticGeometryNode::selectionChangedComponent, this, std::placeholders::_1)),
_originInstance(VertexInstance(getOrigin(), std::bind(&StaticGeometryNode::selectionChangedComponent, this, std::placeholders::_1))),
_originInstance(getOrigin(), std::bind(&StaticGeometryNode::selectionChangedComponent, this, std::placeholders::_1)),
_nurbsVertices(m_curveNURBS, _nurbsEditInstance),
_catmullRomVertices(m_curveCatmullRom, _catmullRomEditInstance)
_catmullRomVertices(m_curveCatmullRom, _catmullRomEditInstance),
_renderableOriginVertex(_originInstance, localToWorld())
{
// greebo: Don't call construct() here, this should be invoked by the
// clone() method
Expand Down Expand Up @@ -107,13 +109,15 @@ void StaticGeometryNode::onVisibilityChanged(bool isVisibleNow)
m_curveCatmullRom.updateRenderable();
_nurbsVertices.queueUpdate();
_catmullRomVertices.queueUpdate();
_renderableOriginVertex.queueUpdate();
}
else
{
m_curveNURBS.clearRenderable();
m_curveCatmullRom.clearRenderable();
_nurbsVertices.clear();
_catmullRomVertices.clear();
_renderableOriginVertex.clear();
}
}

Expand All @@ -126,12 +130,14 @@ void StaticGeometryNode::onSelectionStatusChange(bool changeGroupStatus)
_renderOrigin.queueUpdate();
_nurbsVertices.queueUpdate();
_catmullRomVertices.queueUpdate();
_renderableOriginVertex.queueUpdate();
}
else
{
_renderOrigin.clear();
_nurbsVertices.clear();
_catmullRomVertices.clear();
_renderableOriginVertex.clear();
}
}

Expand Down Expand Up @@ -212,6 +218,7 @@ void StaticGeometryNode::selectionChangedComponent(const ISelectable& selectable

_nurbsVertices.queueUpdate();
_catmullRomVertices.queueUpdate();
_renderableOriginVertex.queueUpdate();
}

bool StaticGeometryNode::isSelectedComponents() const {
Expand Down Expand Up @@ -338,17 +345,28 @@ void StaticGeometryNode::onPreRender(const VolumeTest& volume)
if (GlobalSelectionSystem().ComponentMode() == selection::ComponentSelectionMode::Vertex)
{
// Selected patches in component mode render the lattice connecting the control points
_nurbsVertices.update(_curveCtrlPointShader);
_catmullRomVertices.update(_curveCtrlPointShader);
_nurbsVertices.update(_pointShader);
_catmullRomVertices.update(_pointShader);

if (!isModel())
{
_renderableOriginVertex.update(_pointShader);
}
else
{
_renderableOriginVertex.clear();
}
}
else
{
_nurbsVertices.clear();
_catmullRomVertices.clear();
_renderableOriginVertex.clear();

// Queue an update the next time it's rendered
_nurbsVertices.queueUpdate();
_catmullRomVertices.queueUpdate();
_renderableOriginVertex.queueUpdate();
}
}
}
Expand All @@ -370,28 +388,31 @@ void StaticGeometryNode::setRenderSystem(const RenderSystemPtr& renderSystem)
m_curveCatmullRom.clearRenderable();
_nurbsVertices.clear();
_catmullRomVertices.clear();
_renderableOriginVertex.clear();

if (renderSystem)
{
_pivotShader = renderSystem->capture("$PIVOT");
_curveCtrlPointShader = renderSystem->capture("$POINT");
_pointShader = renderSystem->capture("$BIGPOINT");
}
else
{
_pivotShader.reset();
_curveCtrlPointShader.reset();
_pointShader.reset();
}

_originInstance.setRenderSystem(renderSystem);
}

void StaticGeometryNode::renderComponents(IRenderableCollector& collector, const VolumeTest& volume) const
{
#if 0
if (!isModel() && GlobalSelectionSystem().ComponentMode() == selection::ComponentSelectionMode::Vertex)
{
// Register the renderable with OpenGL
_originInstance.render(collector, volume, localToWorld());
}
#endif
}

void StaticGeometryNode::evaluateTransform()
Expand Down Expand Up @@ -436,6 +457,7 @@ void StaticGeometryNode::transformComponents(const Matrix4& matrix)
if (_originInstance.isSelected())
{
translateOrigin(getTranslation());
_renderableOriginVertex.queueUpdate();
}
}

Expand Down Expand Up @@ -468,6 +490,7 @@ void StaticGeometryNode::_onTransformationChanged()
m_curveCatmullRom.curveChanged();
_nurbsVertices.queueUpdate();
_catmullRomVertices.queueUpdate();
_renderableOriginVertex.queueUpdate();
}

void StaticGeometryNode::_applyTransformation()
Expand Down Expand Up @@ -758,6 +781,8 @@ void StaticGeometryNode::originChanged()
{
_renderableName.setOrigin(getOrigin());
}

_renderableOriginVertex.queueUpdate();
_renderOrigin.queueUpdate();
}

Expand Down
4 changes: 3 additions & 1 deletion radiantcore/entity/doom3group/StaticGeometryNode.h
Expand Up @@ -16,6 +16,7 @@
#include "../EntityNode.h"
#include "../KeyObserverDelegate.h"
#include "render/RenderablePivot.h"
#include "RenderableVertex.h"

namespace entity
{
Expand Down Expand Up @@ -68,10 +69,11 @@ class StaticGeometryNode :
VertexInstance _originInstance;

ShaderPtr _pivotShader;
ShaderPtr _curveCtrlPointShader;
ShaderPtr _pointShader;

RenderableCurveVertices _nurbsVertices;
RenderableCurveVertices _catmullRomVertices;
RenderableVertex _renderableOriginVertex;

private:
// Constructor
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -764,6 +764,7 @@
<ClInclude Include="..\..\radiantcore\entity\curve\CurveNURBS.h" />
<ClInclude Include="..\..\radiantcore\entity\curve\RenderableCurve.h" />
<ClInclude Include="..\..\radiantcore\entity\curve\RenderableCurveVertices.h" />
<ClInclude Include="..\..\radiantcore\entity\doom3group\RenderableVertex.h" />
<ClInclude Include="..\..\radiantcore\entity\doom3group\StaticGeometryNode.h" />
<ClInclude Include="..\..\radiantcore\entity\eclassmodel\EclassModelNode.h" />
<ClInclude Include="..\..\radiantcore\entity\EntityModule.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -2277,5 +2277,8 @@
<ClInclude Include="..\..\radiantcore\entity\light\LightVertexInstanceSet.h">
<Filter>src\entity\light</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\entity\doom3group\RenderableVertex.h">
<Filter>src\entity\doom3group</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit fa3a453

Please sign in to comment.