Merge pull request #2952 from malortie/hl1-mdl-load-external-textures

Added support to load HL1 MDL external texture files directly.
pull/2962/head
Kim Kulling 2020-01-25 19:23:05 +01:00 committed by GitHub
commit a1fbe74e87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 18 deletions

View File

@ -182,6 +182,13 @@ void HL1MDLLoader::load_file() {
read_global_info(); 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. // Append children to root node.
if (rootnode_children_.size()) { if (rootnode_children_.size()) {
scene_->mRootNode->addChildren( scene_->mRootNode->addChildren(
@ -218,21 +225,6 @@ void HL1MDLLoader::validate_header(const Header_HL1 *header, bool is_texture_hea
} }
} else { } 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) { if (header->numbodyparts > AI_MDL_HL1_MAX_BODYPARTS) {
log_warning_limit_exceeded<AI_MDL_HL1_MAX_BODYPARTS>(header->numbodyparts, "bodyparts"); log_warning_limit_exceeded<AI_MDL_HL1_MAX_BODYPARTS>(header->numbodyparts, "bodyparts");
@ -498,6 +490,10 @@ void HL1MDLLoader::read_skins() {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void HL1MDLLoader::read_bones() { void HL1MDLLoader::read_bones() {
if (!header_->numbones) {
return;
}
const Bone_HL1 *pbone = (const Bone_HL1 *)((uint8_t *)header_ + header_->boneindex); const Bone_HL1 *pbone = (const Bone_HL1 *)((uint8_t *)header_ + header_->boneindex);
std::vector<std::string> unique_bones_names(header_->numbones); std::vector<std::string> unique_bones_names(header_->numbones);
@ -588,6 +584,9 @@ void HL1MDLLoader::read_bones() {
triangles, respectively (3 indices per face). triangles, respectively (3 indices per face).
*/ */
void HL1MDLLoader::read_meshes() { void HL1MDLLoader::read_meshes() {
if (!header_->numbodyparts) {
return;
}
int total_verts = 0; int total_verts = 0;
int total_triangles = 0; int total_triangles = 0;
@ -964,8 +963,9 @@ void HL1MDLLoader::read_meshes() {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void HL1MDLLoader::read_animations() { void HL1MDLLoader::read_animations() {
if (!header_->numseq) if (!header_->numseq) {
return; return;
}
const SequenceDesc_HL1 *pseqdesc = (const SequenceDesc_HL1 *)((uint8_t *)header_ + header_->seqindex); const SequenceDesc_HL1 *pseqdesc = (const SequenceDesc_HL1 *)((uint8_t *)header_ + header_->seqindex);
const SequenceGroup_HL1 *pseqgroup = nullptr; const SequenceGroup_HL1 *pseqgroup = nullptr;
@ -1067,6 +1067,9 @@ void HL1MDLLoader::read_animations() {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void HL1MDLLoader::read_sequence_groups_info() { void HL1MDLLoader::read_sequence_groups_info() {
if (!header_->numseqgroups) {
return;
}
aiNode *sequence_groups_node = new aiNode(AI_MDL_HL1_NODE_SEQUENCE_GROUPS); aiNode *sequence_groups_node = new aiNode(AI_MDL_HL1_NODE_SEQUENCE_GROUPS);
rootnode_children_.push_back(sequence_groups_node); rootnode_children_.push_back(sequence_groups_node);

View File

@ -57,13 +57,24 @@ public:
virtual bool importerTest() { virtual bool importerTest() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(MDL_HL1_FILE_MAN, 0); importerTest_HL1(&importer);
EXPECT_NE(nullptr, scene);
// Add further MDL tests... // Add further MDL tests...
return true; 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(0u, scene->mNumTextures);
EXPECT_NE(0u, scene->mNumMaterials);
}
}; };
TEST_F(utMDLImporter, importMDLFromFileTest) { TEST_F(utMDLImporter, importMDLFromFileTest) {