Skip to content

Commit

Permalink
#5263: Apply the same modified scale to the new model after being cloned
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 11, 2020
1 parent 407bcc4 commit f7790a6
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 0 deletions.
30 changes: 30 additions & 0 deletions radiantcore/entity/EntityNode.cpp
Expand Up @@ -69,6 +69,31 @@ void EntityNode::construct()
_shaderParms.addKeyObservers();
}

void EntityNode::constructClone(const EntityNode& original)
{
// We just got cloned, it's possible that this node is the parent of a scaled model node
auto originalChildModel = original.getModelKey().getNode();

if (originalChildModel)
{
model::ModelNodePtr originalModel = Node_getModel(originalChildModel);

// Check if the original model node is scaled
if (originalModel && originalModel->hasModifiedScale())
{
assert(getModelKey().getNode()); // clone should have a child model like the original
auto transformable = Node_getTransformable(getModelKey().getNode());

if (transformable)
{
transformable->setType(TRANSFORM_PRIMITIVE);
transformable->setScale(originalModel->getModelScale());
transformable->freezeTransform();
}
}
}
}

void EntityNode::destruct()
{
_shaderParms.removeKeyObservers();
Expand Down Expand Up @@ -283,6 +308,11 @@ ModelKey& EntityNode::getModelKey()
return _modelKey;
}

const ModelKey& EntityNode::getModelKey() const
{
return _modelKey;
}

void EntityNode::onModelKeyChanged(const std::string& value)
{
// Default implementation suitable for Light, Generic and EClassModel
Expand Down
4 changes: 4 additions & 0 deletions radiantcore/entity/EntityNode.h
Expand Up @@ -135,6 +135,7 @@ class EntityNode :
const ShaderPtr& getColourShader() const;

ModelKey& getModelKey(); // needed by the Doom3Group class, could be a fixme
const ModelKey& getModelKey() const;

const ShaderPtr& getWireShader() const override;
const ShaderPtr& getFillShader() const;
Expand All @@ -154,6 +155,9 @@ class EntityNode :
*/
virtual void construct();

// Called after cloning and construct to perform additional setup
virtual void constructClone(const EntityNode& original);

// Signal method to be overridden by subclasses.
// Don't forget to call the base class implementation as this will
// reload the entity key values and notify observers
Expand Down
1 change: 1 addition & 0 deletions radiantcore/entity/doom3group/Doom3GroupNode.cpp
Expand Up @@ -222,6 +222,7 @@ scene::INodePtr Doom3GroupNode::clone() const
{
Doom3GroupNodePtr clone(new Doom3GroupNode(*this));
clone->construct();
clone->constructClone(*this);

return clone;
}
Expand Down
1 change: 1 addition & 0 deletions radiantcore/entity/eclassmodel/EclassModelNode.cpp
Expand Up @@ -99,6 +99,7 @@ scene::INodePtr EclassModelNode::clone() const
{
EclassModelNodePtr node(new EclassModelNode(*this));
node->construct();
node->constructClone(*this);

return node;
}
Expand Down
1 change: 1 addition & 0 deletions radiantcore/entity/generic/GenericEntityNode.cpp
Expand Up @@ -53,6 +53,7 @@ scene::INodePtr GenericEntityNode::clone() const
{
GenericEntityNodePtr node(new GenericEntityNode(*this));
node->construct();
node->constructClone(*this);

return node;
}
Expand Down
1 change: 1 addition & 0 deletions radiantcore/entity/light/LightNode.cpp
Expand Up @@ -253,6 +253,7 @@ scene::INodePtr LightNode::clone() const
{
LightNodePtr node(new LightNode(*this));
node->construct();
node->constructClone(*this);

return node;
}
Expand Down
1 change: 1 addition & 0 deletions radiantcore/entity/speaker/SpeakerNode.cpp
Expand Up @@ -232,6 +232,7 @@ scene::INodePtr SpeakerNode::clone() const
{
SpeakerNodePtr node(new SpeakerNode(*this));
node->construct();
node->constructClone(*this);

return node;
}
Expand Down

0 comments on commit f7790a6

Please sign in to comment.