Browse Source

fix hl1 mdl orientation, tex coords, face windings order

Garux 4 years ago
parent
commit
4798ff3882
2 changed files with 18 additions and 6 deletions
  1. 3 3
      code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp
  2. 15 3
      code/AssetLib/MDL/MDLLoader.cpp

+ 3 - 3
code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp

@@ -868,7 +868,7 @@ void HL1MDLLoader::read_meshes() {
                         scene_mesh->mNormals[v] = bind_pose_normals[pTrivert->normindex];
                         scene_mesh->mTextureCoords[0][v] = aiVector3D(
                                 pTrivert->s * texcoords_s_scale,
-                                pTrivert->t * texcoords_t_scale, 0);
+                                pTrivert->t * -texcoords_t_scale, 0);
                     }
 
                     // Add face and indices.
@@ -879,9 +879,9 @@ void HL1MDLLoader::read_meshes() {
                         aiFace *face = &scene_mesh->mFaces[f];
                         face->mNumIndices = 3;
                         face->mIndices = new unsigned int[3];
-                        face->mIndices[0] = mesh_faces[f].v0;
+                        face->mIndices[0] = mesh_faces[f].v2;
                         face->mIndices[1] = mesh_faces[f].v1;
-                        face->mIndices[2] = mesh_faces[f].v2;
+                        face->mIndices[2] = mesh_faces[f].v0;
                     }
 
                     // Add mesh bones.

+ 15 - 3
code/AssetLib/MDL/MDLLoader.cpp

@@ -199,6 +199,7 @@ void MDLImporter::InternReadFile(const std::string &pFile,
         const uint32_t iMagicWord = *((uint32_t *)mBuffer);
 
         // Determine the file subtype and call the appropriate member function
+        bool is_half_life = false;
 
         // Original Quake1 format
         if (AI_MDL_MAGIC_NUMBER_BE == iMagicWord || AI_MDL_MAGIC_NUMBER_LE == iMagicWord) {
@@ -240,6 +241,7 @@ void MDLImporter::InternReadFile(const std::string &pFile,
         else if (AI_MDL_MAGIC_NUMBER_BE_HL2a == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_HL2a == iMagicWord ||
                  AI_MDL_MAGIC_NUMBER_BE_HL2b == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_HL2b == iMagicWord) {
             iGSFileVersion = 0;
+            is_half_life = true;
 
             HalfLife::HalfLifeMDLBaseHeader *pHeader = (HalfLife::HalfLifeMDLBaseHeader *)mBuffer;
             if (pHeader->version == AI_MDL_HL1_VERSION) {
@@ -255,9 +257,19 @@ void MDLImporter::InternReadFile(const std::string &pFile,
                                     ". Magic word (", std::string((char *)&iMagicWord, 4), ") is not known");
         }
 
-        // 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);
+        if (is_half_life){
+            // 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 {
+            // 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);
+        }
 
         DeleteBufferAndCleanup();
     } catch (...) {