Skip to content

Commit

Permalink
#5964: Add unit test checking the model localToWorld transform after …
Browse files Browse the repository at this point in the history
…the parent entity has been created
  • Loading branch information
codereader committed Jun 2, 2022
1 parent 7034589 commit bbb3ce3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/Models.cpp
Expand Up @@ -3,6 +3,9 @@
#include <unordered_set>
#include "imodelsurface.h"
#include "imodelcache.h"
#include "scenelib.h"
#include "algorithm/Entity.h"
#include "algorithm/Scene.h"

#include "render/VertexHashing.h"

Expand Down Expand Up @@ -453,4 +456,26 @@ TEST_F(ModelTest, LoadFbxModel)
EXPECT_EQ(model->getPolyCount(), 12);
}

// #5964: Model nodes below a func_emitter didn't get rendered at the entity's origin after creating the entity
TEST_F(ModelTest, NullModelTransformAfterSceneInsertion)
{
auto entityOrigin = Vector3(320, 100, 0);
auto funcEmitter = GlobalEntityModule().createEntityFromSelection("func_emitter", entityOrigin);

EXPECT_EQ(funcEmitter->getEntity().getKeyValue("model"), "-") << "Expected func_emitter to have a model after creation";

scene::addNodeToContainer(funcEmitter, GlobalMapModule().getRoot());

// Get the child model node of the func_emitter
auto nullModelNode = algorithm::getNthChild(funcEmitter, 0);

EXPECT_TRUE(nullModelNode) << "func_emitter should have a child node";
EXPECT_EQ(nullModelNode->getNodeType(), scene::INode::Type::Model) << "func_emitter should have a model node as child";

// Check the localToWorld() matrix of the model node, it should be a translation to the entity's origin
auto modelTranslation = nullModelNode->localToWorld().tCol().getVector3();
EXPECT_TRUE(math::isNear(modelTranslation, entityOrigin, 0.01)) <<
"Model node should be at the entity's origin, but was at " << modelTranslation;
}

}
14 changes: 14 additions & 0 deletions test/resources/tdm/def/func.def
@@ -0,0 +1,14 @@

// func_emitter has its "model" key set to "-" after creation
entityDef func_emitter
{
"inherit" "func_static"

"editor_color" "0 0.5 0.8"
"editor_mins" "-12 -12 -12"
"editor_maxs" "12 12 12"

"spawnclass" "idFuncEmitter"

"editor_setKeyValue model" "-"
}

0 comments on commit bbb3ce3

Please sign in to comment.