Skip to content

Commit

Permalink
#5584: Entity boxes and arrows are using the entity colour now
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Dec 17, 2021
1 parent 8c607e9 commit 7e768fa
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 51 deletions.
14 changes: 8 additions & 6 deletions radiantcore/entity/RenderableArrow.cpp
Expand Up @@ -24,6 +24,8 @@ void RenderableArrow::updateGeometry()
static Vector3 Up(0, 0, 1);
const auto& origin = _node.worldAABB().getOrigin();
const auto& direction = _node.getDirection();
auto colour = _node.getEntityColour();

Vector3 left(-direction.y(), direction.x(), 0);

Vector3 endpoint(origin + direction * 32.0);
Expand All @@ -35,12 +37,12 @@ void RenderableArrow::updateGeometry()

std::vector<ArbitraryMeshVertex> vertices
{
ArbitraryMeshVertex(origin, {1,0,0}, {0,0}),
ArbitraryMeshVertex(endpoint, {1,0,0}, {0,0}),
ArbitraryMeshVertex(tip1, {1,0,0}, {0,0}),
ArbitraryMeshVertex(tip2, {1,0,0}, {0,0}),
ArbitraryMeshVertex(tip3, {1,0,0}, {0,0}),
ArbitraryMeshVertex(tip4, {1,0,0}, {0,0}),
ArbitraryMeshVertex(origin, {1,0,0}, {0,0}, colour),
ArbitraryMeshVertex(endpoint, {1,0,0}, {0,0}, colour),
ArbitraryMeshVertex(tip1, {1,0,0}, {0,0}, colour),
ArbitraryMeshVertex(tip2, {1,0,0}, {0,0}, colour),
ArbitraryMeshVertex(tip3, {1,0,0}, {0,0}, colour),
ArbitraryMeshVertex(tip4, {1,0,0}, {0,0}, colour),
};

// Indices are always the same, therefore constant
Expand Down
75 changes: 39 additions & 36 deletions radiantcore/entity/RenderableEntityBox.cpp
Expand Up @@ -8,65 +8,65 @@ namespace entity
namespace
{

inline std::vector<ArbitraryMeshVertex> getFillBoxVertices(const Vector3& min, const Vector3& max)
inline std::vector<ArbitraryMeshVertex> getFillBoxVertices(const Vector3& min, const Vector3& max, const Vector4& colour)
{
// Load the 6 times 4 = 24 corner points, each with the correct face normal
return
{
// Bottom quad
ArbitraryMeshVertex({ min[0], min[1], min[2] }, {0,0,-1}, {0,0}),
ArbitraryMeshVertex({ max[0], min[1], min[2] }, {0,0,-1}, {0,0}),
ArbitraryMeshVertex({ max[0], max[1], min[2] }, {0,0,-1}, {0,0}),
ArbitraryMeshVertex({ min[0], max[1], min[2] }, {0,0,-1}, {0,0}),
ArbitraryMeshVertex({ min[0], min[1], min[2] }, {0,0,-1}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], min[1], min[2] }, {0,0,-1}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], max[1], min[2] }, {0,0,-1}, {0,0}, colour),
ArbitraryMeshVertex({ min[0], max[1], min[2] }, {0,0,-1}, {0,0}, colour),

// Top quad
ArbitraryMeshVertex({ min[0], min[1], max[2] }, {0,0,+1}, {0,0}),
ArbitraryMeshVertex({ max[0], min[1], max[2] }, {0,0,+1}, {0,0}),
ArbitraryMeshVertex({ max[0], max[1], max[2] }, {0,0,+1}, {0,0}),
ArbitraryMeshVertex({ min[0], max[1], max[2] }, {0,0,+1}, {0,0}),
ArbitraryMeshVertex({ min[0], min[1], max[2] }, {0,0,+1}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], min[1], max[2] }, {0,0,+1}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], max[1], max[2] }, {0,0,+1}, {0,0}, colour),
ArbitraryMeshVertex({ min[0], max[1], max[2] }, {0,0,+1}, {0,0}, colour),

// Front quad
ArbitraryMeshVertex({ min[0], min[1], min[2] }, {0,-1,0}, {0,0}),
ArbitraryMeshVertex({ max[0], min[1], min[2] }, {0,-1,0}, {0,0}),
ArbitraryMeshVertex({ max[0], min[1], max[2] }, {0,-1,0}, {0,0}),
ArbitraryMeshVertex({ min[0], min[1], max[2] }, {0,-1,0}, {0,0}),
ArbitraryMeshVertex({ min[0], min[1], min[2] }, {0,-1,0}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], min[1], min[2] }, {0,-1,0}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], min[1], max[2] }, {0,-1,0}, {0,0}, colour),
ArbitraryMeshVertex({ min[0], min[1], max[2] }, {0,-1,0}, {0,0}, colour),

// Back quad
ArbitraryMeshVertex({ max[0], max[1], min[2] }, {0,+1,0}, {0,0}),
ArbitraryMeshVertex({ min[0], max[1], min[2] }, {0,+1,0}, {0,0}),
ArbitraryMeshVertex({ min[0], max[1], max[2] }, {0,+1,0}, {0,0}),
ArbitraryMeshVertex({ max[0], max[1], max[2] }, {0,+1,0}, {0,0}),
ArbitraryMeshVertex({ max[0], max[1], min[2] }, {0,+1,0}, {0,0}, colour),
ArbitraryMeshVertex({ min[0], max[1], min[2] }, {0,+1,0}, {0,0}, colour),
ArbitraryMeshVertex({ min[0], max[1], max[2] }, {0,+1,0}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], max[1], max[2] }, {0,+1,0}, {0,0}, colour),

// Right quad
ArbitraryMeshVertex({ max[0], min[1], min[2] }, {+1,0,0}, {0,0}),
ArbitraryMeshVertex({ max[0], max[1], min[2] }, {+1,0,0}, {0,0}),
ArbitraryMeshVertex({ max[0], max[1], max[2] }, {+1,0,0}, {0,0}),
ArbitraryMeshVertex({ min[0], max[1], max[2] }, {+1,0,0}, {0,0}),
ArbitraryMeshVertex({ max[0], min[1], min[2] }, {+1,0,0}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], max[1], min[2] }, {+1,0,0}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], max[1], max[2] }, {+1,0,0}, {0,0}, colour),
ArbitraryMeshVertex({ min[0], max[1], max[2] }, {+1,0,0}, {0,0}, colour),

// Left quad
ArbitraryMeshVertex({ min[0], max[1], min[2] }, {-1,0,0}, {0,0}),
ArbitraryMeshVertex({ min[0], min[1], min[2] }, {-1,0,0}, {0,0}),
ArbitraryMeshVertex({ min[0], min[1], max[2] }, {-1,0,0}, {0,0}),
ArbitraryMeshVertex({ min[0], max[1], max[2] }, {-1,0,0}, {0,0}),
ArbitraryMeshVertex({ min[0], max[1], min[2] }, {-1,0,0}, {0,0}, colour),
ArbitraryMeshVertex({ min[0], min[1], min[2] }, {-1,0,0}, {0,0}, colour),
ArbitraryMeshVertex({ min[0], min[1], max[2] }, {-1,0,0}, {0,0}, colour),
ArbitraryMeshVertex({ min[0], max[1], max[2] }, {-1,0,0}, {0,0}, colour),
};
}

inline std::vector<ArbitraryMeshVertex> getWireframeBoxVertices(const Vector3& min, const Vector3& max)
inline std::vector<ArbitraryMeshVertex> getWireframeBoxVertices(const Vector3& min, const Vector3& max, const Vector4& colour)
{
// Load the 8 corner points
return
{
// Bottom quad
ArbitraryMeshVertex({ min[0], min[1], min[2] }, {0,0,1}, {0,0}),
ArbitraryMeshVertex({ max[0], min[1], min[2] }, {0,0,1}, {0,0}),
ArbitraryMeshVertex({ max[0], max[1], min[2] }, {0,0,1}, {0,0}),
ArbitraryMeshVertex({ min[0], max[1], min[2] }, {0,0,1}, {0,0}),
ArbitraryMeshVertex({ min[0], min[1], min[2] }, {0,0,1}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], min[1], min[2] }, {0,0,1}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], max[1], min[2] }, {0,0,1}, {0,0}, colour),
ArbitraryMeshVertex({ min[0], max[1], min[2] }, {0,0,1}, {0,0}, colour),

// Top quad
ArbitraryMeshVertex({ min[0], min[1], max[2] }, {0,0,1}, {0,0}),
ArbitraryMeshVertex({ max[0], min[1], max[2] }, {0,0,1}, {0,0}),
ArbitraryMeshVertex({ max[0], max[1], max[2] }, {0,0,1}, {0,0}),
ArbitraryMeshVertex({ min[0], max[1], max[2] }, {0,0,1}, {0,0}),
ArbitraryMeshVertex({ min[0], min[1], max[2] }, {0,0,1}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], min[1], max[2] }, {0,0,1}, {0,0}, colour),
ArbitraryMeshVertex({ max[0], max[1], max[2] }, {0,0,1}, {0,0}, colour),
ArbitraryMeshVertex({ min[0], max[1], max[2] }, {0,0,1}, {0,0}, colour),
};
}

Expand Down Expand Up @@ -103,7 +103,8 @@ static const std::vector<unsigned int> FillBoxIndices

}

RenderableEntityBox::RenderableEntityBox(const AABB& bounds, const Vector3& worldPos) :
RenderableEntityBox::RenderableEntityBox(const IEntityNode& entity, const AABB& bounds, const Vector3& worldPos) :
_entity(entity),
_bounds(bounds),
_worldPos(worldPos),
_needsUpdate(true),
Expand Down Expand Up @@ -137,7 +138,9 @@ void RenderableEntityBox::updateGeometry()
Vector3 max(Origin + _bounds.extents);
Vector3 min(Origin - _bounds.extents);

auto vertices = _filledBox ? getFillBoxVertices(min, max) : getWireframeBoxVertices(min, max);
auto colour = _entity.getEntityColour();

auto vertices = _filledBox ? getFillBoxVertices(min, max, colour) : getWireframeBoxVertices(min, max, colour);

// Move the points to their world position
for (auto& vertex : vertices)
Expand Down
3 changes: 2 additions & 1 deletion radiantcore/entity/RenderableEntityBox.h
Expand Up @@ -11,13 +11,14 @@ class RenderableEntityBox :
public render::RenderableGeometry
{
private:
const IEntityNode& _entity;
const AABB& _bounds;
const Vector3& _worldPos;
bool _needsUpdate;
bool _filledBox;

public:
RenderableEntityBox(const AABB& bounds, const Vector3& worldPos);
RenderableEntityBox(const IEntityNode& entity, const AABB& bounds, const Vector3& worldPos);

void queueUpdate();
void setFillMode(bool fill);
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/entity/generic/GenericEntityNode.cpp
Expand Up @@ -14,7 +14,7 @@ GenericEntityNode::GenericEntityNode(const IEntityClassPtr& eclass) :
m_angle(AngleKey::IDENTITY),
m_rotationKey(std::bind(&GenericEntityNode::rotationChanged, this)),
_renderableArrow(*this),
_renderableBox(localAABB(), worldAABB().getOrigin()),
_renderableBox(*this, localAABB(), worldAABB().getOrigin()),
_allow3Drotations(_spawnArgs.getKeyValue("editor_rotatable") == "1")
{}

Expand All @@ -27,7 +27,7 @@ GenericEntityNode::GenericEntityNode(const GenericEntityNode& other) :
m_angle(AngleKey::IDENTITY),
m_rotationKey(std::bind(&GenericEntityNode::rotationChanged, this)),
_renderableArrow(*this),
_renderableBox(localAABB(), worldAABB().getOrigin()),
_renderableBox(*this, localAABB(), worldAABB().getOrigin()),
_allow3Drotations(_spawnArgs.getKeyValue("editor_rotatable") == "1")
{}

Expand Down
4 changes: 2 additions & 2 deletions radiantcore/entity/speaker/SpeakerNode.cpp
Expand Up @@ -18,7 +18,7 @@ SpeakerNode::SpeakerNode(const IEntityClassPtr& eclass) :
EntityNode(eclass),
m_originKey(std::bind(&SpeakerNode::originChanged, this)),
m_origin(ORIGINKEY_IDENTITY),
_renderableBox(m_aabb_local, worldAABB().getOrigin()),
_renderableBox(*this, m_aabb_local, worldAABB().getOrigin()),
_renderableRadiiWireframe(*this, m_origin, _radiiTransformed),
_renderableRadiiFill(*this, m_origin, _radiiTransformed),
_showRadiiWhenUnselected(EntitySettings::InstancePtr()->getShowAllSpeakerRadii()),
Expand All @@ -36,7 +36,7 @@ SpeakerNode::SpeakerNode(const SpeakerNode& other) :
Snappable(other),
m_originKey(std::bind(&SpeakerNode::originChanged, this)),
m_origin(ORIGINKEY_IDENTITY),
_renderableBox(m_aabb_local, worldAABB().getOrigin()),
_renderableBox(*this, m_aabb_local, worldAABB().getOrigin()),
_renderableRadiiWireframe(*this, m_origin, _radiiTransformed),
_renderableRadiiFill(*this, m_origin, _radiiTransformed),
_showRadiiWhenUnselected(EntitySettings::InstancePtr()->getShowAllSpeakerRadii()),
Expand Down
1 change: 0 additions & 1 deletion tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -768,7 +768,6 @@
<ClInclude Include="..\..\radiantcore\entity\EntityNode.h" />
<ClInclude Include="..\..\radiantcore\entity\EntitySettings.h" />
<ClInclude Include="..\..\radiantcore\entity\generic\GenericEntityNode.h" />
<ClInclude Include="..\..\radiantcore\entity\generic\RenderableArrow.h" />
<ClInclude Include="..\..\radiantcore\entity\KeyObserverDelegate.h" />
<ClInclude Include="..\..\radiantcore\entity\KeyObserverMap.h" />
<ClInclude Include="..\..\radiantcore\entity\KeyValue.h" />
Expand Down
3 changes: 0 additions & 3 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -1476,9 +1476,6 @@
<ClInclude Include="..\..\radiantcore\entity\generic\GenericEntityNode.h">
<Filter>src\entity\generic</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\entity\generic\RenderableArrow.h">
<Filter>src\entity\generic</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\entity\curve\Curve.h">
<Filter>src\entity\curve</Filter>
</ClInclude>
Expand Down

0 comments on commit 7e768fa

Please sign in to comment.