Skip to content

Commit

Permalink
#5584: Infrastructure to render the generic entity boxes (with and wi…
Browse files Browse the repository at this point in the history
…thout arrows)
  • Loading branch information
codereader committed Dec 8, 2021
1 parent b62f0b2 commit 33a6c52
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 2 deletions.
32 changes: 32 additions & 0 deletions radiantcore/entity/RenderableEntityBox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "RenderableEntityBox.h"

#include "EntityNode.h"

namespace entity
{

RenderableEntityBox::RenderableEntityBox(EntityNode& node) :
_needsUpdate(true),
_filledBox(true)
{}

void RenderableEntityBox::queueUpdate()
{
_needsUpdate = true;
}

void RenderableEntityBox::setFillMode(bool fill)
{
_filledBox = fill;
}

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

_needsUpdate = false;


}

}
26 changes: 26 additions & 0 deletions radiantcore/entity/RenderableEntityBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "render/RenderableGeometry.h"

namespace entity
{

class EntityNode;

class RenderableEntityBox :
public render::RenderableGeometry
{
private:
bool _needsUpdate;
bool _filledBox;

public:
RenderableEntityBox(EntityNode& node);

void queueUpdate();
void setFillMode(bool fill);

virtual void updateGeometry() override;
};

}
54 changes: 52 additions & 2 deletions radiantcore/entity/generic/GenericEntityNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ GenericEntityNode::GenericEntityNode(const IEntityClassPtr& eclass) :
m_arrow(m_ray),
m_aabb_solid(m_aabb_local),
m_aabb_wire(m_aabb_local),
_renderableBox(*this),
_allow3Drotations(_spawnArgs.getKeyValue("editor_rotatable") == "1"),
_solidAABBRenderMode(SolidBoxes)
{}
Expand All @@ -31,6 +32,7 @@ GenericEntityNode::GenericEntityNode(const GenericEntityNode& other) :
m_arrow(m_ray),
m_aabb_solid(m_aabb_local),
m_aabb_wire(m_aabb_local),
_renderableBox(*this),
_allow3Drotations(_spawnArgs.getKeyValue("editor_rotatable") == "1"),
_solidAABBRenderMode(other._solidAABBRenderMode)
{}
Expand Down Expand Up @@ -127,6 +129,13 @@ GenericEntityNode::SolidAAABBRenderMode GenericEntityNode::getSolidAABBRenderMod
return _solidAABBRenderMode;
}

void GenericEntityNode::onPreRender(const VolumeTest& volume)
{
EntityNode::onPreRender(volume);

_renderableBox.update(getColourShader());
}

void GenericEntityNode::renderArrow(const ShaderPtr& shader, IRenderableCollector& collector,
const VolumeTest& volume, const Matrix4& localToWorld) const
{
Expand All @@ -139,20 +148,30 @@ void GenericEntityNode::renderArrow(const ShaderPtr& shader, IRenderableCollecto
void GenericEntityNode::renderSolid(IRenderableCollector& collector, const VolumeTest& volume) const
{
EntityNode::renderSolid(collector, volume);

#if 0
const ShaderPtr& shader = getSolidAABBRenderMode() == GenericEntityNode::WireFrameOnly ?
getWireShader() : getFillShader();

collector.addRenderable(*shader, m_aabb_solid, localToWorld());
renderArrow(shader, collector, volume, localToWorld());
#endif
}

void GenericEntityNode::renderWireframe(IRenderableCollector& collector, const VolumeTest& volume) const
{
EntityNode::renderWireframe(collector, volume);

#if 0
collector.addRenderable(*getWireShader(), m_aabb_wire, localToWorld());
renderArrow(getWireShader(), collector, volume, localToWorld());
#endif
}

void GenericEntityNode::setRenderSystem(const RenderSystemPtr& renderSystem)
{
EntityNode::setRenderSystem(renderSystem);

// Clear the geometry from any previous shader
_renderableBox.clear();
}

const Vector3& GenericEntityNode::getDirection() const
Expand Down Expand Up @@ -231,6 +250,7 @@ void GenericEntityNode::_onTransformationChanged()
rotate(getRotation());

updateTransform();
_renderableBox.queueUpdate();
}
}

Expand Down Expand Up @@ -293,6 +313,36 @@ void GenericEntityNode::onChildRemoved(const scene::INodePtr& child)
});
}

void GenericEntityNode::onInsertIntoScene(scene::IMapRootNode& root)
{
// Call the base class first
EntityNode::onInsertIntoScene(root);

_renderableBox.queueUpdate();
}

void GenericEntityNode::onRemoveFromScene(scene::IMapRootNode& root)
{
// Call the base class first
EntityNode::onRemoveFromScene(root);

_renderableBox.clear();
}

void GenericEntityNode::onVisibilityChanged(bool isVisibleNow)
{
EntityNode::onVisibilityChanged(isVisibleNow);

if (isVisibleNow)
{
_renderableBox.queueUpdate();
}
else
{
_renderableBox.clear();
}
}

void GenericEntityNode::originChanged()
{
m_origin = m_originKey.get();
Expand Down
9 changes: 9 additions & 0 deletions radiantcore/entity/generic/GenericEntityNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "../KeyObserverDelegate.h"

#include "RenderableArrow.h"
#include "../RenderableEntityBox.h"

namespace entity
{
Expand Down Expand Up @@ -48,6 +49,7 @@ class GenericEntityNode: public EntityNode, public Snappable
RenderableArrow m_arrow;
RenderableSolidAABB m_aabb_solid;
RenderableWireframeAABB m_aabb_wire;
RenderableEntityBox _renderableBox;

// TRUE if this entity's arrow can be rotated in all directions,
// FALSE if the arrow is caught in the xy plane
Expand Down Expand Up @@ -99,10 +101,12 @@ class GenericEntityNode: public EntityNode, public Snappable
scene::INodePtr clone() const override;

// Renderable implementation
void onPreRender(const VolumeTest& volume) override;
void renderArrow(const ShaderPtr& shader, IRenderableCollector& collector,
const VolumeTest& volume, const Matrix4& localToWorld) const;
void renderSolid(IRenderableCollector& collector, const VolumeTest& volume) const override;
void renderWireframe(IRenderableCollector& collector, const VolumeTest& volume) const override;
void setRenderSystem(const RenderSystemPtr& renderSystem) override;

SolidAAABBRenderMode getSolidAABBRenderMode() const;

Expand All @@ -115,6 +119,9 @@ class GenericEntityNode: public EntityNode, public Snappable
void onChildAdded(const scene::INodePtr& child) override;
void onChildRemoved(const scene::INodePtr& child) override;

void onInsertIntoScene(scene::IMapRootNode& root) override;
void onRemoveFromScene(scene::IMapRootNode& root) override;

protected:
// Gets called by the Transformable implementation whenever
// scale, rotation or translation is changed.
Expand All @@ -126,6 +133,8 @@ class GenericEntityNode: public EntityNode, public Snappable

// Override EntityNode::construct()
void construct() override;

void onVisibilityChanged(bool isVisibleNow) override;
};

} // namespace entity
2 changes: 2 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<ClCompile Include="..\..\radiantcore\entity\ModelKey.cpp" />
<ClCompile Include="..\..\radiantcore\entity\NameKeyObserver.cpp" />
<ClCompile Include="..\..\radiantcore\entity\NamespaceManager.cpp" />
<ClCompile Include="..\..\radiantcore\entity\RenderableEntityBox.cpp" />
<ClCompile Include="..\..\radiantcore\entity\RotationKey.cpp" />
<ClCompile Include="..\..\radiantcore\entity\RotationMatrix.cpp" />
<ClCompile Include="..\..\radiantcore\entity\ShaderParms.cpp" />
Expand Down Expand Up @@ -782,6 +783,7 @@
<ClInclude Include="..\..\radiantcore\entity\NameKeyObserver.h" />
<ClInclude Include="..\..\radiantcore\entity\NamespaceManager.h" />
<ClInclude Include="..\..\radiantcore\entity\OriginKey.h" />
<ClInclude Include="..\..\radiantcore\entity\RenderableEntityBox.h" />
<ClInclude Include="..\..\radiantcore\entity\RotationKey.h" />
<ClInclude Include="..\..\radiantcore\entity\RotationMatrix.h" />
<ClInclude Include="..\..\radiantcore\entity\ShaderParms.h" />
Expand Down
6 changes: 6 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,9 @@
<ClCompile Include="..\..\radiantcore\undo\UndoSystemFactory.cpp">
<Filter>src\undo</Filter>
</ClCompile>
<ClCompile Include="..\..\radiantcore\entity\RenderableEntityBox.cpp">
<Filter>src\entity</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiantcore\modulesystem\ModuleLoader.h">
Expand Down Expand Up @@ -2256,5 +2259,8 @@
<ClInclude Include="..\..\radiantcore\rendersystem\backend\GeometryRenderer.h">
<Filter>src\rendersystem\backend</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\entity\RenderableEntityBox.h">
<Filter>src\entity</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 33a6c52

Please sign in to comment.