Skip to content

Commit

Permalink
#5584: Construct RenderableLightVertices class which will be taking c…
Browse files Browse the repository at this point in the history
…are of drawing all the manipulatable light vertices.
  • Loading branch information
codereader committed Jan 21, 2022
1 parent e68b735 commit f2b990b
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 2 deletions.
43 changes: 41 additions & 2 deletions radiantcore/entity/light/LightNode.cpp
Expand Up @@ -34,6 +34,7 @@ LightNode::LightNode(const IEntityClassPtr& eclass)
_dragPlanes(sigc::mem_fun(this, &LightNode::selectedChangedComponent)),
_renderableOctagon(*this),
_renderableLightVolume(*this),
_renderableVertices(*this, _instances),
_showLightVolumeWhenUnselected(EntitySettings::InstancePtr()->getShowAllLightRadii()),
_overrideColKey(colours::RKEY_OVERRIDE_LIGHTCOL)
{
Expand All @@ -60,6 +61,7 @@ LightNode::LightNode(const LightNode& other)
_dragPlanes(std::bind(&LightNode::selectedChangedComponent, this, std::placeholders::_1)),
_renderableOctagon(*this),
_renderableLightVolume(*this),
_renderableVertices(*this, _instances),
_showLightVolumeWhenUnselected(other._showLightVolumeWhenUnselected),
_overrideColKey(colours::RKEY_OVERRIDE_LIGHTCOL)
{
Expand Down Expand Up @@ -172,6 +174,7 @@ void LightNode::onRemoveFromScene(scene::IMapRootNode& root)

_renderableOctagon.clear();
_renderableLightVolume.clear();
_renderableVertices.clear();
}

void LightNode::testSelect(Selector& selector, SelectionTest& test)
Expand Down Expand Up @@ -337,9 +340,12 @@ scene::INodePtr LightNode::clone() const
return node;
}

void LightNode::selectedChangedComponent(const ISelectable& selectable) {
void LightNode::selectedChangedComponent(const ISelectable& selectable)
{
// add the selectable to the list of selected components (see RadiantSelectionSystem::onComponentSelection)
GlobalSelectionSystem().onComponentSelection(Node::getSelf(), selectable);

_renderableVertices.queueUpdate();
}

void LightNode::onPreRender(const VolumeTest& volume)
Expand All @@ -348,20 +354,34 @@ void LightNode::onPreRender(const VolumeTest& volume)
const auto& colourShader = _overrideColKey.get() ? getColourShader() : _colourKey.getColourShader();
_renderableOctagon.update(colourShader);

bool lightIsSelected = isSelected();

// Depending on the selected status or the entity settings, we need to update the wireframe volume
if (_showLightVolumeWhenUnselected || isSelected())
if (_showLightVolumeWhenUnselected || lightIsSelected)
{
if (isProjected())
{
updateProjection();
}

_renderableLightVolume.update(colourShader);

// Update vertices when the light is selected
if (lightIsSelected)
{
_renderableVertices.setComponentMode(GlobalSelectionSystem().ComponentMode());
_renderableVertices.update(_vertexShader);
}
else
{
_renderableVertices.clear();
}
}
else
{
// Light volume is not visible, hide it
_renderableLightVolume.clear();
_renderableVertices.clear();
}
}

Expand Down Expand Up @@ -400,6 +420,7 @@ void LightNode::setRenderSystem(const RenderSystemPtr& renderSystem)
// Clear the geometry from any previous shader
_renderableOctagon.clear();
_renderableLightVolume.clear();
_renderableVertices.clear();

// The renderable vertices are maintaining shader objects, acquire/free them now
_rCentre.setRenderSystem(renderSystem);
Expand All @@ -411,6 +432,16 @@ void LightNode::setRenderSystem(const RenderSystemPtr& renderSystem)

m_shader.setRenderSystem(renderSystem);

if (renderSystem)
{
_vertexShader = renderSystem->capture("$BIGPOINT");
_renderableVertices.queueUpdate();
}
else
{
_vertexShader.reset();
}

_instances.center.setRenderSystem(renderSystem);
_instances.target.setRenderSystem(renderSystem);
_instances.right.setRenderSystem(renderSystem);
Expand All @@ -422,6 +453,7 @@ void LightNode::setRenderSystem(const RenderSystemPtr& renderSystem)
// Renders the components of this light instance
void LightNode::renderComponents(IRenderableCollector& collector, const VolumeTest& volume) const
{
#if 0
// Render the components (light center) as selected/deselected, if we are in the according mode
if (GlobalSelectionSystem().ComponentMode() == selection::ComponentSelectionMode::Vertex)
{
Expand Down Expand Up @@ -471,10 +503,12 @@ void LightNode::renderComponents(IRenderableCollector& collector, const VolumeTe
}
}
}
#endif
}

void LightNode::renderInactiveComponents(IRenderableCollector& collector, const VolumeTest& volume, const bool selected) const
{
#if 0
// greebo: We are not in component selection mode (and the light is still selected),
// check if we should draw the center of the light anyway
if (selected
Expand Down Expand Up @@ -504,6 +538,7 @@ void LightNode::renderInactiveComponents(IRenderableCollector& collector, const
renderLightCentre(collector, volume, localToWorld());
}
}
#endif
}

Vector4 LightNode::getEntityColour() const
Expand Down Expand Up @@ -610,6 +645,7 @@ void LightNode::_onTransformationChanged()

_renderableOctagon.queueUpdate();
_renderableLightVolume.queueUpdate();
_renderableVertices.queueUpdate();
}

void LightNode::_applyTransformation()
Expand Down Expand Up @@ -652,11 +688,13 @@ void LightNode::onVisibilityChanged(bool isVisibleNow)
{
_renderableOctagon.queueUpdate();
_renderableLightVolume.queueUpdate();
_renderableVertices.queueUpdate();
}
else
{
_renderableLightVolume.clear();
_renderableOctagon.clear();
_renderableVertices.clear();
}
}

Expand All @@ -666,6 +704,7 @@ void LightNode::onSelectionStatusChange(bool changeGroupStatus)

// Volume renderable is not always prepared for rendering, queue an update
_renderableLightVolume.queueUpdate();
_renderableVertices.queueUpdate();
}

void LightNode::onEntitySettingsChanged()
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/entity/light/LightNode.h
Expand Up @@ -77,6 +77,7 @@ class LightNode :
mutable bool _projectionChanged;

LightShader m_shader;
ShaderPtr _vertexShader;

// The 8x8 box representing the light object itself
AABB _lightBox;
Expand All @@ -93,6 +94,7 @@ class LightNode :
// Renderable components of this light
RenderableLightOctagon _renderableOctagon;
RenderableLightVolume _renderableLightVolume;
RenderableLightVertices _renderableVertices;

bool _showLightVolumeWhenUnselected;

Expand Down
3 changes: 3 additions & 0 deletions radiantcore/entity/light/LightVertexInstanceSet.h
Expand Up @@ -29,6 +29,9 @@ struct LightVertexInstanceSet
VertexInstance start;
VertexInstance end;

// The number of vertex member in this struct
constexpr static std::size_t NumVertices = 6;

LightVertexInstanceSet(Vector3& center, Projected<Vector3>& projected,
const SelectionChangedSlot& selectionChanged) :
center(center, selectionChanged),
Expand Down
45 changes: 45 additions & 0 deletions radiantcore/entity/light/Renderables.cpp
@@ -1,6 +1,7 @@
#include "Renderables.h"

#include "LightNode.h"
#include "../EntitySettings.h"

namespace entity
{
Expand Down Expand Up @@ -226,4 +227,48 @@ void RenderableLightVolume::updateProjectedLightVolume()
}
}

void RenderableLightVertices::updateGeometry()
{
if (!_needsUpdate) return;

_needsUpdate = false;

std::vector<ArbitraryMeshVertex> vertices;
std::vector<unsigned int> indices;

vertices.reserve(LightVertexInstanceSet::NumVertices);
indices.reserve(LightVertexInstanceSet::NumVertices);

auto& settings = *EntitySettings::InstancePtr();
const auto& colourVertexSelected = settings.getLightVertexColour(LightEditVertexType::Selected);
const auto& colourVertexDeselected = settings.getLightVertexColour(LightEditVertexType::Deselected);
const auto& colourVertexInactive = settings.getLightVertexColour(LightEditVertexType::Inactive);

unsigned int index = 0;

if (_light.isProjected())
{
// TODO
}
else
{
// Not a projected light, include just the light centre vertex
const auto& colour = _mode != selection::ComponentSelectionMode::Vertex ? colourVertexInactive :
_instances.center.isSelected() ? colourVertexSelected : colourVertexDeselected;

vertices.push_back(ArbitraryMeshVertex(_instances.center.getVertex(), { 0,0,0 }, { 0,0 }, colour));
indices.push_back(index++);
}

// Apply the local2world transform to all the vertices
const auto& local2World = _light.localToWorld();

for (auto& vertex : vertices)
{
vertex.vertex = local2World * vertex.vertex;
}

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

} // namespace
38 changes: 38 additions & 0 deletions radiantcore/entity/light/Renderables.h
@@ -1,5 +1,6 @@
#pragma once

#include "LightVertexInstanceSet.h"
#include "render/RenderableGeometry.h"

namespace entity
Expand Down Expand Up @@ -60,4 +61,41 @@ class RenderableLightVolume :
void updateProjectedLightVolume();
};

// All manipulatable vertices, with the colour
// corresponding to their selection status
class RenderableLightVertices :
public render::RenderableGeometry
{
private:
const LightNode& _light;
const LightVertexInstanceSet& _instances;

bool _needsUpdate;
selection::ComponentSelectionMode _mode;

public:
RenderableLightVertices(const LightNode& light, const LightVertexInstanceSet& instances) :
_light(light),
_instances(instances),
_needsUpdate(true),
_mode(selection::ComponentSelectionMode::Default)
{}

void queueUpdate()
{
_needsUpdate = true;
}

void setComponentMode(selection::ComponentSelectionMode mode)
{
if (_mode == mode) return;

_mode = mode;
queueUpdate();
}

protected:
void updateGeometry() override;
};

} // namespace entity

0 comments on commit f2b990b

Please sign in to comment.