diff --git a/test/Models.cpp b/test/Models.cpp index a1eafb7463..cd24e20f02 100644 --- a/test/Models.cpp +++ b/test/Models.cpp @@ -3,6 +3,9 @@ #include #include "imodelsurface.h" #include "imodelcache.h" +#include "scenelib.h" +#include "algorithm/Entity.h" +#include "algorithm/Scene.h" #include "render/VertexHashing.h" @@ -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; +} + } diff --git a/test/resources/tdm/def/func.def b/test/resources/tdm/def/func.def new file mode 100644 index 0000000000..9f2db5fe91 --- /dev/null +++ b/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" "-" +}