From 48bb2978afa17c95d11df75701535e3ab0ed4266 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Fri, 24 Jan 2020 13:14:37 -0500 Subject: [PATCH 1/2] Added support to load HL1 MDL external texture files directly. --- code/MDL/HalfLife/HL1MDLLoader.cpp | 35 +++++++++++++----------- test/unit/ImportExport/utMDLImporter.cpp | 15 ++++++++-- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/code/MDL/HalfLife/HL1MDLLoader.cpp b/code/MDL/HalfLife/HL1MDLLoader.cpp index 06ffd7801..a53004eb5 100644 --- a/code/MDL/HalfLife/HL1MDLLoader.cpp +++ b/code/MDL/HalfLife/HL1MDLLoader.cpp @@ -182,6 +182,13 @@ void HL1MDLLoader::load_file() { read_global_info(); + if (!header_->numbodyparts) { + // This could be an MDL external texture file. In this case, + // add this flag to allow the scene to be loaded even if it + // has no meshes. + scene_->mFlags |= AI_SCENE_FLAGS_INCOMPLETE; + } + // Append children to root node. if (rootnode_children_.size()) { scene_->mRootNode->addChildren( @@ -218,21 +225,6 @@ void HL1MDLLoader::validate_header(const Header_HL1 *header, bool is_texture_hea } } else { - // Every single Half-Life model is assumed to have at least one bodypart. - if (!header->numbodyparts) { - throw DeadlyImportError(MDL_HALFLIFE_LOG_HEADER "Model has no bodyparts"); - } - - // Every single Half-Life model is assumed to have at least one bone. - if (!header->numbones) { - throw DeadlyImportError(MDL_HALFLIFE_LOG_HEADER "Model has no bones"); - } - - // Every single Half-Life model is assumed to have at least one sequence group, - // which is the "default" sequence group. - if (!header->numseqgroups) { - throw DeadlyImportError(MDL_HALFLIFE_LOG_HEADER "Model has no sequence groups"); - } if (header->numbodyparts > AI_MDL_HL1_MAX_BODYPARTS) { log_warning_limit_exceeded(header->numbodyparts, "bodyparts"); @@ -498,6 +490,10 @@ void HL1MDLLoader::read_skins() { // ------------------------------------------------------------------------------------------------ void HL1MDLLoader::read_bones() { + if (!header_->numbones) { + return; + } + const Bone_HL1 *pbone = (const Bone_HL1 *)((uint8_t *)header_ + header_->boneindex); std::vector unique_bones_names(header_->numbones); @@ -588,6 +584,9 @@ void HL1MDLLoader::read_bones() { triangles, respectively (3 indices per face). */ void HL1MDLLoader::read_meshes() { + if (!header_->numbodyparts) { + return; + } int total_verts = 0; int total_triangles = 0; @@ -964,8 +963,9 @@ void HL1MDLLoader::read_meshes() { // ------------------------------------------------------------------------------------------------ void HL1MDLLoader::read_animations() { - if (!header_->numseq) + if (!header_->numseq) { return; + } const SequenceDesc_HL1 *pseqdesc = (const SequenceDesc_HL1 *)((uint8_t *)header_ + header_->seqindex); const SequenceGroup_HL1 *pseqgroup = nullptr; @@ -1067,6 +1067,9 @@ void HL1MDLLoader::read_animations() { // ------------------------------------------------------------------------------------------------ void HL1MDLLoader::read_sequence_groups_info() { + if (!header_->numseqgroups) { + return; + } aiNode *sequence_groups_node = new aiNode(AI_MDL_HL1_NODE_SEQUENCE_GROUPS); rootnode_children_.push_back(sequence_groups_node); diff --git a/test/unit/ImportExport/utMDLImporter.cpp b/test/unit/ImportExport/utMDLImporter.cpp index 561b3009f..aa188fd86 100644 --- a/test/unit/ImportExport/utMDLImporter.cpp +++ b/test/unit/ImportExport/utMDLImporter.cpp @@ -57,13 +57,24 @@ public: virtual bool importerTest() { Assimp::Importer importer; - const aiScene *scene = importer.ReadFile(MDL_HL1_FILE_MAN, 0); - EXPECT_NE(nullptr, scene); + importerTest_HL1(&importer); // Add further MDL tests... return true; } + +private: + void importerTest_HL1(Assimp::Importer* const importer) { + const aiScene *scene = importer->ReadFile(MDL_HL1_FILE_MAN, 0); + EXPECT_NE(nullptr, scene); + + // Test that the importer can directly load an HL1 MDL external texture file. + scene = importer->ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "manT.mdl", aiProcess_ValidateDataStructure); + EXPECT_NE(nullptr, scene); + EXPECT_NE(0, scene->mNumTextures); + EXPECT_NE(0, scene->mNumMaterials); + } }; TEST_F(utMDLImporter, importMDLFromFileTest) { From fc4ae3586e1112648a356c3985b4293ee1d71a52 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 25 Jan 2020 11:31:14 +0100 Subject: [PATCH 2/2] Update utMDLImporter.cpp unittests: Fix compiler warning: comparison between signed and unsigned. --- test/unit/ImportExport/utMDLImporter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/ImportExport/utMDLImporter.cpp b/test/unit/ImportExport/utMDLImporter.cpp index aa188fd86..b9a850175 100644 --- a/test/unit/ImportExport/utMDLImporter.cpp +++ b/test/unit/ImportExport/utMDLImporter.cpp @@ -72,8 +72,8 @@ private: // Test that the importer can directly load an HL1 MDL external texture file. scene = importer->ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "manT.mdl", aiProcess_ValidateDataStructure); EXPECT_NE(nullptr, scene); - EXPECT_NE(0, scene->mNumTextures); - EXPECT_NE(0, scene->mNumMaterials); + EXPECT_NE(0u, scene->mNumTextures); + EXPECT_NE(0u, scene->mNumMaterials); } };