From 85a6450077003f61daeff2c31548b9383b369c04 Mon Sep 17 00:00:00 2001 From: codereader Date: Sat, 26 Mar 2022 14:47:21 +0100 Subject: [PATCH] #219: Add TDM-specific support for noshadows_lit, since that is the setting of most wall torches --- radiantcore/entity/EntityNode.h | 2 +- .../entity/eclassmodel/EclassModelNode.cpp | 20 +++++++++++++++++-- .../entity/eclassmodel/EclassModelNode.h | 5 +++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/radiantcore/entity/EntityNode.h b/radiantcore/entity/EntityNode.h index 9d4b592610..67729660dc 100644 --- a/radiantcore/entity/EntityNode.h +++ b/radiantcore/entity/EntityNode.h @@ -138,7 +138,7 @@ class EntityNode : virtual void foreachRenderable(const ObjectVisitFunction& functor) override; virtual void foreachRenderableTouchingBounds(const AABB& bounds, const ObjectVisitFunction& functor) override; - virtual bool isShadowCasting() const; + virtual bool isShadowCasting() const override; // IMatrixTransform implementation Matrix4 localToParent() const override { return _localToParent; } diff --git a/radiantcore/entity/eclassmodel/EclassModelNode.cpp b/radiantcore/entity/eclassmodel/EclassModelNode.cpp index 4ea5e35f46..39ecc38365 100644 --- a/radiantcore/entity/eclassmodel/EclassModelNode.cpp +++ b/radiantcore/entity/eclassmodel/EclassModelNode.cpp @@ -12,7 +12,8 @@ EclassModelNode::EclassModelNode(const IEntityClassPtr& eclass) : _angleKey(std::bind(&EclassModelNode::angleChanged, this)), _angle(AngleKey::IDENTITY), _renderOrigin(_origin), - _localAABB(Vector3(0,0,0), Vector3(1,1,1)) // minimal AABB, is determined by child bounds anyway + _localAABB(Vector3(0,0,0), Vector3(1,1,1)), // minimal AABB, is determined by child bounds anyway + _noShadowsLit(false) {} EclassModelNode::EclassModelNode(const EclassModelNode& other) : @@ -24,7 +25,8 @@ EclassModelNode::EclassModelNode(const EclassModelNode& other) : _angleKey(std::bind(&EclassModelNode::angleChanged, this)), _angle(AngleKey::IDENTITY), _renderOrigin(_origin), - _localAABB(Vector3(0,0,0), Vector3(1,1,1)) // minimal AABB, is determined by child bounds anyway + _localAABB(Vector3(0,0,0), Vector3(1,1,1)), // minimal AABB, is determined by child bounds anyway + _noShadowsLit(false) {} EclassModelNode::~EclassModelNode() @@ -51,6 +53,7 @@ void EclassModelNode::construct() observeKey("angle", sigc::mem_fun(_rotationKey, &RotationKey::angleChanged)); observeKey("rotation", sigc::mem_fun(_rotationKey, &RotationKey::rotationChanged)); observeKey("origin", sigc::mem_fun(_originKey, &OriginKey::onKeyValueChanged)); + observeKey("noshadows_lit", sigc::mem_fun(this, &EclassModelNode::onNoshadowsLitChanged)); } // Snappable implementation @@ -188,6 +191,19 @@ void EclassModelNode::angleChanged() updateTransform(); } +void EclassModelNode::onNoshadowsLitChanged(const std::string& value) +{ + _noShadowsLit = value == "1"; +} + +bool EclassModelNode::isShadowCasting() const +{ + // Both noShadowsLit and noShadows should be false + // It's hard to determine whether a compound entity like wall toches are starting + // in lit state, so we rather turn off shadow casting for them regardless of their state. + return !_noShadowsLit && EntityNode::isShadowCasting(); +} + void EclassModelNode::onSelectionStatusChange(bool changeGroupStatus) { EntityNode::onSelectionStatusChange(changeGroupStatus); diff --git a/radiantcore/entity/eclassmodel/EclassModelNode.h b/radiantcore/entity/eclassmodel/EclassModelNode.h index bc0c8f0345..f2aa39aaf0 100644 --- a/radiantcore/entity/eclassmodel/EclassModelNode.h +++ b/radiantcore/entity/eclassmodel/EclassModelNode.h @@ -47,6 +47,8 @@ class EclassModelNode : AABB _localAABB; + bool _noShadowsLit; + private: // Constructor EclassModelNode(const IEntityClassPtr& eclass); @@ -75,6 +77,8 @@ class EclassModelNode : const Vector3& getWorldPosition() const override; + virtual bool isShadowCasting() const override; + protected: // Gets called by the Transformable implementation whenever // scale, rotation or translation is changed. @@ -102,6 +106,7 @@ class EclassModelNode : void originChanged(); void rotationChanged(); void angleChanged(); + void onNoshadowsLitChanged(const std::string& value); }; } // namespace