Skip to content

Commit

Permalink
#5996: Add more tests checking the resulting skinned model an entity …
Browse files Browse the repository at this point in the history
…using a modelDef as "model" key value
  • Loading branch information
codereader committed Jan 14, 2024
1 parent 0fcbe67 commit b9d6d6a
Show file tree
Hide file tree
Showing 3 changed files with 308 additions and 2 deletions.
48 changes: 48 additions & 0 deletions test/Skin.cpp
Expand Up @@ -692,6 +692,44 @@ void expectModelDefHasMeshAndSkin(const std::string& modelDef, const std::string
EXPECT_EQ(model->getSkin(), expectedSkin) << "Expected skin to be " << expectedSkin << " on modelDef " << modelDef;
}

IEntityNodePtr createStaticEntityWithModel(const std::string& model)
{
auto funcStaticClass = GlobalEntityClassManager().findClass("func_static");
auto entity = GlobalEntityModule().createEntity(funcStaticClass);
entity->getEntity().setKeyValue("model", model);
return entity;
}

void expectEntityHasSkinnedModel(const IEntityNodePtr& entity, const std::string& expectedSkin, const std::vector<std::string>& expectedMaterials)
{
// Check the skinned model node beneath it
SkinnedModelPtr foundModelNode;
entity->foreachNode([&](const auto& child)
{
auto model = std::dynamic_pointer_cast<SkinnedModel>(child);
if (!foundModelNode && model)
{
foundModelNode = model;
}
return true;
});

EXPECT_TRUE(foundModelNode) << "Failed to find the skinned model node";
EXPECT_EQ(foundModelNode->getSkin(), expectedSkin) << "Expected skin to be " << expectedSkin << " on entity with model " << entity->getEntity().getKeyValue("model");

auto modelNode = std::dynamic_pointer_cast<model::ModelNode>(foundModelNode);

EXPECT_TRUE(modelNode) << "Cast to ModelNode failed";
EXPECT_EQ(modelNode->getIModel().getActiveMaterials().size(), expectedMaterials.size()) << "Mismatching number of materials";
EXPECT_TRUE(modelNode->getIModel().getActiveMaterials() == expectedMaterials) << "Material list mismatch";
}

void expectEntityHasSkinnedModel(const std::string& modelKeyValue, const std::string& expectedSkin, const std::vector<std::string>& expectedMaterials)
{
auto entity = createStaticEntityWithModel(modelKeyValue);
expectEntityHasSkinnedModel(entity, expectedSkin, expectedMaterials);
}

// Variations of modelDefs, all of them have a mesh, some of them define a skin, some inherit a skin, some override a skin
TEST_F(ModelSkinTest, ModelDefSkinKeword)
{
Expand All @@ -702,4 +740,14 @@ TEST_F(ModelSkinTest, ModelDefSkinKeword)
expectModelDefHasMeshAndSkin("some_modeldef_overriding_inherited_skin", "models/md5/flag01.md5mesh", "swap_flag_pirate_with_nodraw");
}

// Test the resulting skinned model attached to an entity node using the given modelDef as "model"
TEST_F(ModelSkinTest, EntityUsingModelDef)
{
expectEntityHasSkinnedModel("some_base_modeldef_without_skin", "", { "flag_pirate", "flag_pirate" });
expectEntityHasSkinnedModel("some_base_modeldef_with_skin", "swap_flag_pirate_with_caulk", { "textures/common/caulk", "textures/common/caulk" });
expectEntityHasSkinnedModel("some_modeldef_inheriting_model_only", "", { "flag_pirate", "flag_pirate" });
expectEntityHasSkinnedModel("some_modeldef_inheriting_model_and_skin", "swap_flag_pirate_with_caulk", { "textures/common/caulk", "textures/common/caulk" });
expectEntityHasSkinnedModel("some_modeldef_overriding_inherited_skin", "swap_flag_pirate_with_nodraw", { "textures/common/nodraw", "textures/common/nodraw" });
}

}
30 changes: 28 additions & 2 deletions test/resources/tdm/def/skinned_models.def
@@ -1,12 +1,12 @@
model some_base_modeldef_without_skin
{
mesh models/md5/flag01.md5mesh
mesh models/md5/testflag.md5mesh
}

model some_base_modeldef_with_skin
{
skin swap_flag_pirate_with_caulk
mesh models/md5/flag01.md5mesh
mesh models/md5/testflag.md5mesh
}

model some_modeldef_inheriting_model_only
Expand Down Expand Up @@ -34,3 +34,29 @@ skin swap_flag_pirate_with_nodraw
{
flag_pirate textures/common/nodraw
}

entityDef entity_using_modeldef
{
"inherit" "atdm:ai_humanoid"

"editor_color" "0 1 0"
"editor_mins" "-32 -32 -32"
"editor_maxs" "32 32 32"

"spawnclass" "idAI"
"model" "some_base_modeldef_without_skin"
}

entityDef entity_using_modeldef_with_skin_keyvalue
{
"inherit" "entity_using_modeldef"
"skin" "swap_flag_pirate_with_caulk"
}

entityDef entity_using_skinned_modeldef
{
"inherit" "entity_using_modeldef"
"model" "some_modeldef_with_skin"
}


232 changes: 232 additions & 0 deletions test/resources/tdm/models/md5/testflag.md5mesh
@@ -0,0 +1,232 @@
MD5Version 10
commandline ""

numJoints 14
numMeshes 2

joints {
"origin" -1 ( 0.000000 0.000000 0.000000 ) ( -0.000000 -0.000000 0.707107 ) //
"root" 0 ( -71.658241 0.000002 0.000000 ) ( -0.000000 -0.000000 0.707107 ) // origin
"up" 1 ( -59.658241 0.000003 30.000000 ) ( -0.000000 -0.000000 0.707107 ) // root
"up1" 2 ( -29.658241 0.000006 30.000000 ) ( -0.000000 -0.000000 0.707107 ) // up
"up2" 3 ( -14.658241 0.000007 30.000000 ) ( -0.000000 -0.000000 0.707107 ) // up1
"up3" 4 ( 0.341759 0.000008 30.000000 ) ( -0.000000 -0.000000 0.707107 ) // up2
"up4" 5 ( 15.341759 0.000009 30.000000 ) ( -0.000000 -0.000000 0.707107 ) // up3
"up5" 6 ( 30.341759 0.000010 30.000000 ) ( -0.000000 -0.000000 0.707107 ) // up4
"do" 1 ( -59.658241 0.000003 -30.000000 ) ( -0.000000 -0.000000 0.707107 ) // root
"do1" 8 ( -29.658241 0.000006 -30.000000 ) ( -0.000000 -0.000000 0.707107 ) // do
"do2" 9 ( -14.658241 0.000007 -30.000000 ) ( -0.000000 -0.000000 0.707107 ) // do1
"do3" 10 ( 0.341759 0.000008 -30.000000 ) ( -0.000000 -0.000000 0.707107 ) // do2
"do4" 11 ( 15.341759 0.000009 -30.000000 ) ( -0.000000 -0.000000 0.707107 ) // do3
"do5" 12 ( 30.341759 0.000010 -30.000000 ) ( -0.000000 -0.000000 0.707107 ) // do4
}

mesh {
// meshes: flag

shader "flag_pirate"

numverts 21
vert 0 ( 0.250000 0.000003 ) 0 2
vert 1 ( 0.000003 0.000000 ) 2 1
vert 2 ( 0.000001 0.499996 ) 3 2
vert 3 ( 0.249999 0.499998 ) 5 4
vert 4 ( 0.000000 0.999991 ) 9 1
vert 5 ( 0.249998 0.999994 ) 10 2
vert 6 ( 0.749996 0.500001 ) 12 4
vert 7 ( 0.999995 0.500002 ) 16 2
vert 8 ( 0.749996 0.000004 ) 18 2
vert 9 ( 0.999995 0.000004 ) 20 1
vert 10 ( 0.749996 0.999999 ) 21 2
vert 11 ( 0.999995 1.000000 ) 23 1
vert 12 ( 0.624997 0.500001 ) 24 4
vert 13 ( 0.624996 0.999998 ) 28 2
vert 14 ( 0.624997 0.000004 ) 30 2
vert 15 ( 0.499997 0.500000 ) 32 4
vert 16 ( 0.499996 0.999997 ) 36 2
vert 17 ( 0.499998 0.000004 ) 38 2
vert 18 ( 0.374998 0.499999 ) 40 4
vert 19 ( 0.374997 0.999996 ) 44 2
vert 20 ( 0.374999 0.000003 ) 46 2

numtris 24
tri 0 0 2 1
tri 1 0 3 2
tri 2 3 4 2
tri 3 3 5 4
tri 4 6 8 7
tri 5 7 8 9
tri 6 7 10 6
tri 7 7 11 10
tri 8 12 10 13
tri 9 12 6 10
tri 10 14 6 12
tri 11 14 8 6
tri 12 15 13 16
tri 13 15 12 13
tri 14 17 12 15
tri 15 17 14 12
tri 16 18 16 19
tri 17 18 15 16
tri 18 15 20 17
tri 19 15 18 20
tri 20 3 19 5
tri 21 3 18 19
tri 22 0 18 3
tri 23 0 20 18

numweights 48
weight 0 3 0.500000 ( 0.000006 -0.341759 0.000000 )
weight 1 2 0.500000 ( 0.000006 29.658241 0.000000 )
weight 2 2 1.000000 ( 0.000003 -0.341759 0.000000 )
weight 3 2 0.500000 ( 0.000003 -0.341759 -30.000000 )
weight 4 8 0.500000 ( 0.000003 -0.341759 30.000000 )
weight 5 9 0.250000 ( 0.514180 -0.341759 30.000000 )
weight 6 3 0.250000 ( 0.514180 -0.341759 -30.000000 )
weight 7 2 0.250000 ( 0.514180 29.658241 -30.000000 )
weight 8 8 0.250000 ( 0.514180 29.658241 30.000000 )
weight 9 8 1.000000 ( 0.000003 -0.341759 0.000000 )
weight 10 9 0.500000 ( 0.000006 -0.341759 0.000000 )
weight 11 8 0.500000 ( 0.000006 29.658241 0.000000 )
weight 12 6 0.250000 ( 0.514185 14.658241 -30.000000 )
weight 13 7 0.250000 ( 0.514185 -0.341759 -30.000000 )
weight 14 12 0.250000 ( 0.514185 14.658241 30.000000 )
weight 15 13 0.250000 ( 0.514185 -0.341759 30.000000 )
weight 16 7 0.500000 ( 0.000012 29.658241 -30.000000 )
weight 17 13 0.500000 ( 0.000012 29.658241 30.000000 )
weight 18 6 0.500000 ( 0.000010 14.658241 0.000000 )
weight 19 7 0.500000 ( 0.000010 -0.341759 0.000000 )
weight 20 7 1.000000 ( 0.000012 29.658241 0.000000 )
weight 21 12 0.500000 ( 0.000010 14.658241 0.000000 )
weight 22 13 0.500000 ( 0.000010 -0.341759 0.000000 )
weight 23 13 1.000000 ( 0.000012 29.658241 0.000000 )
weight 24 5 0.250000 ( 0.514184 14.658241 -30.000000 )
weight 25 6 0.250000 ( 0.514184 -0.341759 -30.000000 )
weight 26 11 0.250000 ( 0.514184 14.658241 30.000000 )
weight 27 12 0.250000 ( 0.514184 -0.341759 30.000000 )
weight 28 11 0.500000 ( 0.000009 14.658241 0.000000 )
weight 29 12 0.500000 ( 0.000009 -0.341759 0.000000 )
weight 30 5 0.500000 ( 0.000009 14.658241 0.000000 )
weight 31 6 0.500000 ( 0.000009 -0.341759 0.000000 )
weight 32 4 0.250000 ( 0.514182 14.658241 -30.000000 )
weight 33 5 0.250000 ( 0.514182 -0.341759 -30.000000 )
weight 34 10 0.250000 ( 0.514182 14.658241 30.000000 )
weight 35 11 0.250000 ( 0.514182 -0.341759 30.000000 )
weight 36 10 0.500000 ( 0.000008 14.658241 0.000000 )
weight 37 11 0.500000 ( 0.000008 -0.341759 0.000000 )
weight 38 4 0.500000 ( 0.000008 14.658241 0.000000 )
weight 39 5 0.500000 ( 0.000008 -0.341759 0.000000 )
weight 40 3 0.250000 ( 0.514181 14.658241 -30.000000 )
weight 41 9 0.250000 ( 0.514181 14.658241 30.000000 )
weight 42 4 0.250000 ( 0.514181 -0.341759 -30.000000 )
weight 43 10 0.250000 ( 0.514181 -0.341759 30.000000 )
weight 44 9 0.500000 ( 0.000007 14.658241 0.000000 )
weight 45 10 0.500000 ( 0.000007 -0.341759 0.000000 )
weight 46 3 0.500000 ( 0.000007 14.658241 0.000000 )
weight 47 4 0.500000 ( 0.000007 -0.341759 0.000000 )
}

mesh {
// meshes: flag_back

shader "flag_pirate"

numverts 21
vert 0 ( 0.250000 0.000003 ) 0 2
vert 1 ( 0.000001 0.499996 ) 2 2
vert 2 ( 0.000003 0.000000 ) 4 1
vert 3 ( 0.249999 0.499998 ) 5 4
vert 4 ( 0.000000 0.999991 ) 9 1
vert 5 ( 0.249998 0.999994 ) 10 2
vert 6 ( 0.749996 0.000004 ) 12 2
vert 7 ( 0.999995 0.500002 ) 14 2
vert 8 ( 0.749996 0.500001 ) 16 4
vert 9 ( 0.999995 0.000004 ) 20 1
vert 10 ( 0.749996 0.999999 ) 21 2
vert 11 ( 0.999995 1.000000 ) 23 1
vert 12 ( 0.624997 0.500001 ) 24 4
vert 13 ( 0.624996 0.999998 ) 28 2
vert 14 ( 0.624997 0.000004 ) 30 2
vert 15 ( 0.499997 0.500000 ) 32 4
vert 16 ( 0.499996 0.999997 ) 36 2
vert 17 ( 0.499998 0.000004 ) 38 2
vert 18 ( 0.374998 0.499999 ) 40 4
vert 19 ( 0.374997 0.999996 ) 44 2
vert 20 ( 0.374999 0.000003 ) 46 2

numtris 24
tri 0 0 2 1
tri 1 0 1 3
tri 2 3 1 4
tri 3 3 4 5
tri 4 6 8 7
tri 5 7 9 6
tri 6 7 8 10
tri 7 7 10 11
tri 8 12 13 10
tri 9 12 10 8
tri 10 14 12 8
tri 11 14 8 6
tri 12 15 16 13
tri 13 15 13 12
tri 14 17 15 12
tri 15 17 12 14
tri 16 18 19 16
tri 17 18 16 15
tri 18 15 17 20
tri 19 15 20 18
tri 20 3 5 19
tri 21 3 19 18
tri 22 0 3 18
tri 23 0 18 20

numweights 48
weight 0 3 0.500000 ( 0.000006 -0.341759 0.000000 )
weight 1 2 0.500000 ( 0.000006 29.658241 0.000000 )
weight 2 2 0.500000 ( 0.000003 -0.341759 -30.000000 )
weight 3 8 0.500000 ( 0.000003 -0.341759 30.000000 )
weight 4 2 1.000000 ( 0.000003 -0.341759 0.000000 )
weight 5 9 0.250000 ( -0.788396 -0.341759 30.000000 )
weight 6 3 0.250000 ( -0.788396 -0.341759 -30.000000 )
weight 7 2 0.250000 ( -0.788396 29.658241 -30.000000 )
weight 8 8 0.250000 ( -0.788396 29.658241 30.000000 )
weight 9 8 1.000000 ( 0.000003 -0.341759 0.000000 )
weight 10 9 0.500000 ( 0.000006 -0.341759 0.000000 )
weight 11 8 0.500000 ( 0.000006 29.658241 0.000000 )
weight 12 6 0.500000 ( 0.000010 14.658241 0.000000 )
weight 13 7 0.500000 ( 0.000010 -0.341759 0.000000 )
weight 14 7 0.500000 ( 0.000012 29.658241 -30.000000 )
weight 15 13 0.500000 ( 0.000012 29.658241 30.000000 )
weight 16 6 0.250000 ( -0.788391 14.658241 -30.000000 )
weight 17 7 0.250000 ( -0.788391 -0.341759 -30.000000 )
weight 18 12 0.250000 ( -0.788391 14.658241 30.000000 )
weight 19 13 0.250000 ( -0.788391 -0.341759 30.000000 )
weight 20 7 1.000000 ( 0.000012 29.658241 0.000000 )
weight 21 12 0.500000 ( 0.000010 14.658241 0.000000 )
weight 22 13 0.500000 ( 0.000010 -0.341759 0.000000 )
weight 23 13 1.000000 ( 0.000012 29.658241 0.000000 )
weight 24 5 0.250000 ( -0.788392 14.658241 -30.000000 )
weight 25 6 0.250000 ( -0.788392 -0.341759 -30.000000 )
weight 26 11 0.250000 ( -0.788392 14.658241 30.000000 )
weight 27 12 0.250000 ( -0.788392 -0.341759 30.000000 )
weight 28 11 0.500000 ( 0.000009 14.658241 0.000000 )
weight 29 12 0.500000 ( 0.000009 -0.341759 0.000000 )
weight 30 5 0.500000 ( 0.000009 14.658241 0.000000 )
weight 31 6 0.500000 ( 0.000009 -0.341759 0.000000 )
weight 32 4 0.250000 ( -0.788393 14.658241 -30.000000 )
weight 33 5 0.250000 ( -0.788393 -0.341759 -30.000000 )
weight 34 10 0.250000 ( -0.788393 14.658241 30.000000 )
weight 35 11 0.250000 ( -0.788393 -0.341759 30.000000 )
weight 36 10 0.500000 ( 0.000008 14.658241 0.000000 )
weight 37 11 0.500000 ( 0.000008 -0.341759 0.000000 )
weight 38 4 0.500000 ( 0.000008 14.658241 0.000000 )
weight 39 5 0.500000 ( 0.000008 -0.341759 0.000000 )
weight 40 3 0.250000 ( -0.788394 14.658241 -30.000000 )
weight 41 9 0.250000 ( -0.788394 14.658241 30.000000 )
weight 42 4 0.250000 ( -0.788394 -0.341759 -30.000000 )
weight 43 10 0.250000 ( -0.788394 -0.341759 30.000000 )
weight 44 9 0.500000 ( 0.000007 14.658241 0.000000 )
weight 45 10 0.500000 ( 0.000007 -0.341759 0.000000 )
weight 46 3 0.500000 ( 0.000007 14.658241 0.000000 )
weight 47 4 0.500000 ( 0.000007 -0.341759 0.000000 )
}

0 comments on commit b9d6d6a

Please sign in to comment.