2
0
Эх сурвалжийг харах

Make coord transfor for hs1 files optional (#5687)

* Make coord transfor for hs1 files optional

* Add config switch for HS1 transformation transformation
Kim Kulling 1 жил өмнө
parent
commit
e63d3ed8e7

+ 3 - 1
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(true) {
     }
 
     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

+ 24 - 11
code/AssetLib/MDL/MDLLoader.cpp

@@ -99,7 +99,7 @@ MDLImporter::MDLImporter() :
 // ------------------------------------------------------------------------------------------------
 // Returns whether the class can handle the format of the given file.
 bool MDLImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
-    static const uint32_t tokens[] = {
+    static constexpr uint32_t tokens[] = {
         AI_MDL_MAGIC_NUMBER_LE_HL2a,
         AI_MDL_MAGIC_NUMBER_LE_HL2b,
         AI_MDL_MAGIC_NUMBER_LE_GS7,
@@ -138,6 +138,7 @@ void MDLImporter::SetupProperties(const Importer *pImp) {
     mHL1ImportSettings.read_bone_controllers = pImp->GetPropertyBool(AI_CONFIG_IMPORT_MDL_HL1_READ_BONE_CONTROLLERS, true);
     mHL1ImportSettings.read_hitboxes = pImp->GetPropertyBool(AI_CONFIG_IMPORT_MDL_HL1_READ_HITBOXES, true);
     mHL1ImportSettings.read_misc_global_info = pImp->GetPropertyBool(AI_CONFIG_IMPORT_MDL_HL1_READ_MISC_GLOBAL_INFO, true);
+    mHL1ImportSettings.transform_coord_system = pImp->GetPropertyBool(AI_CONFIG_IMPORT_MDL_HL1_TRANSFORM_COORD_SYSTEM);
 }
 
 // ------------------------------------------------------------------------------------------------
@@ -146,6 +147,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 +261,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();

+ 6 - 0
include/assimp/config.h.in

@@ -724,6 +724,12 @@ enum aiComponent
  */
 #define AI_CONFIG_IMPORT_MDL_HL1_READ_ANIMATION_EVENTS "IMPORT_MDL_HL1_READ_ANIMATION_EVENTS"
 
+// ---------------------------------------------------------------------------
+/** @brief Set whether you want to convert the HS1 coordinate system in a special way.
+ * The default value is true (S1)
+ * Property type: bool
+ */
+#define AI_CONFIG_IMPORT_MDL_HL1_TRANSFORM_COORD_SYSTEM "TRANSFORM COORDSYSTEM FOR HS! MODELS"
 // ---------------------------------------------------------------------------
 /** @brief Set whether the MDL (HL1) importer will read blend controllers.
  * \note This property requires AI_CONFIG_IMPORT_MDL_HL1_READ_ANIMATIONS to be set to true.