Browse Source

Merge pull request #998 from johnmaf/bugfix/gltfUVs

Flip UVs in glTFExporter
Kim Kulling 9 years ago
parent
commit
b8950f6d90
1 changed files with 7 additions and 0 deletions
  1. 7 0
      code/glTFExporter.cpp

+ 7 - 0
code/glTFExporter.cpp

@@ -291,6 +291,13 @@ void glTFExporter::ExportMeshes()
         if (n) p.attributes.normal.push_back(n);
         if (n) p.attributes.normal.push_back(n);
 
 
         for (int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
         for (int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
+            // Flip UV y coords
+            if (aim -> mNumUVComponents[i] > 1) {
+                for (unsigned int j = 0; j < aim->mNumVertices; ++j) {
+                    aim->mTextureCoords[i][j].y = 1 - aim->mTextureCoords[i][j].y;
+                }
+            }
+
             if (aim->mNumUVComponents[i] > 0) {
             if (aim->mNumUVComponents[i] > 0) {
                 AttribType::Value type = (aim->mNumUVComponents[i] == 2) ? AttribType::VEC2 : AttribType::VEC3;
                 AttribType::Value type = (aim->mNumUVComponents[i] == 2) ? AttribType::VEC2 : AttribType::VEC3;
                 Ref<Accessor> tc = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mTextureCoords[i], AttribType::VEC3, type, ComponentType_FLOAT, true);
                 Ref<Accessor> tc = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mTextureCoords[i], AttribType::VEC3, type, ComponentType_FLOAT, true);