diff --git a/code/AssetLib/MDL/HalfLife/HL1ImportSettings.h b/code/AssetLib/MDL/HalfLife/HL1ImportSettings.h index 52f98cb58..a9f3ec120 100644 --- a/code/AssetLib/MDL/HalfLife/HL1ImportSettings.h +++ b/code/AssetLib/MDL/HalfLife/HL1ImportSettings.h @@ -63,7 +63,8 @@ struct HL1ImportSettings { read_bone_controllers(false), read_hitboxes(false), read_textures(false), - read_misc_global_info(false) { + read_misc_global_info(false), + transform_coord_system(false) { } bool read_animations; @@ -76,6 +77,7 @@ struct HL1ImportSettings { bool read_hitboxes; bool read_textures; bool read_misc_global_info; + bool transform_coord_system; }; } // namespace HalfLife diff --git a/code/AssetLib/MDL/MDLLoader.cpp b/code/AssetLib/MDL/MDLLoader.cpp index 498e40b34..fb1635e91 100644 --- a/code/AssetLib/MDL/MDLLoader.cpp +++ b/code/AssetLib/MDL/MDLLoader.cpp @@ -146,6 +146,20 @@ const aiImporterDesc *MDLImporter::GetInfo() const { return &desc; } +// ------------------------------------------------------------------------------------------------ +static void transformCoordinateSystem(const aiScene *pScene) { + if (pScene == nullptr) { + return; + } + + pScene->mRootNode->mTransformation = aiMatrix4x4( + 0.f, -1.f, 0.f, 0.f, + 0.f, 0.f, 1.f, 0.f, + -1.f, 0.f, 0.f, 0.f, + 0.f, 0.f, 0.f, 1.f + ); +} + // ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. void MDLImporter::InternReadFile(const std::string &pFile, @@ -246,18 +260,16 @@ void MDLImporter::InternReadFile(const std::string &pFile, ". Magic word (", ai_str_toprintable((const char *)&iMagicWord, sizeof(iMagicWord)), ") is not known"); } - if (is_half_life){ + if (is_half_life && mHL1ImportSettings.transform_coord_system) { // Now rotate the whole scene 90 degrees around the z and x axes to convert to internal coordinate system - pScene->mRootNode->mTransformation = aiMatrix4x4( - 0.f, -1.f, 0.f, 0.f, - 0.f, 0.f, 1.f, 0.f, - -1.f, 0.f, 0.f, 0.f, - 0.f, 0.f, 0.f, 1.f); - } - else { + transformCoordinateSystem(pScene); + } else { // Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system - pScene->mRootNode->mTransformation = aiMatrix4x4(1.f, 0.f, 0.f, 0.f, - 0.f, 0.f, 1.f, 0.f, 0.f, -1.f, 0.f, 0.f, 0.f, 0.f, 0.f, 1.f); + pScene->mRootNode->mTransformation = aiMatrix4x4( + 1.f, 0.f, 0.f, 0.f, + 0.f, 0.f, 1.f, 0.f, + 0.f, -1.f, 0.f, 0.f, + 0.f, 0.f, 0.f, 1.f); } DeleteBufferAndCleanup();