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

Refix export fbx PolygonVertexIndex (#6240)

Co-authored-by: Kim Kulling <[email protected]>
sSsA01 2 сар өмнө
parent
commit
4c61ca3af5

+ 12 - 3
code/AssetLib/FBX/FBXExporter.cpp

@@ -1098,6 +1098,7 @@ void FBXExporter::WriteObjects () {
     bool bJoinIdenticalVertices = mProperties->GetPropertyBool("bJoinIdenticalVertices", true);
     bool bJoinIdenticalVertices = mProperties->GetPropertyBool("bJoinIdenticalVertices", true);
     // save vertex_indices as it is needed later
     // save vertex_indices as it is needed later
     std::vector<std::vector<int32_t>> vVertexIndice(mScene->mNumMeshes);
     std::vector<std::vector<int32_t>> vVertexIndice(mScene->mNumMeshes);
+    std::vector<uint32_t> uniq_v_before_mi;
 
 
     const auto bTransparencyFactorReferencedToOpacity = mProperties->GetPropertyBool(AI_CONFIG_EXPORT_FBX_TRANSPARENCY_FACTOR_REFER_TO_OPACITY, false);
     const auto bTransparencyFactorReferencedToOpacity = mProperties->GetPropertyBool(AI_CONFIG_EXPORT_FBX_TRANSPARENCY_FACTOR_REFER_TO_OPACITY, false);
 
 
@@ -1144,6 +1145,7 @@ void FBXExporter::WriteObjects () {
           const aiMesh *m = mScene->mMeshes[mi];
           const aiMesh *m = mScene->mMeshes[mi];
 
 
           size_t v_offset = vertex_indices.size();
           size_t v_offset = vertex_indices.size();
+          size_t uniq_v_before = flattened_vertices.size() / 3;
 
 
           // map of vertex value to its index in the data vector
           // map of vertex value to its index in the data vector
           std::map<aiVector3D,size_t> index_by_vertex_value;
           std::map<aiVector3D,size_t> index_by_vertex_value;
@@ -1186,11 +1188,17 @@ void FBXExporter::WriteObjects () {
             if (f.mNumIndices == 0) continue;
             if (f.mNumIndices == 0) continue;
             size_t pvi = 0;
             size_t pvi = 0;
             for (; pvi < f.mNumIndices - 1; pvi++) {
             for (; pvi < f.mNumIndices - 1; pvi++) {
-              polygon_data.push_back(vertex_indices[v_offset + f.mIndices[pvi]]);
+              polygon_data.push_back(
+                static_cast<int32_t>(uniq_v_before + vertex_indices[v_offset + f.mIndices[pvi]])
+              );
             }
             }
-            polygon_data.push_back(-1 - vertex_indices[v_offset+f.mIndices[pvi]]);
+            polygon_data.push_back(
+              static_cast<int32_t>(-1 ^ (uniq_v_before + vertex_indices[v_offset+f.mIndices[pvi]]))
+            );
           }
           }
 
 
+          uniq_v_before_mi.push_back(static_cast<uint32_t>(uniq_v_before));
+
           if (m->HasNormals()) {
           if (m->HasNormals()) {
             normal_data.reserve(3 * polygon_data.size());
             normal_data.reserve(3 * polygon_data.size());
             for (size_t fi = 0; fi < m->mNumFaces; fi++) {
             for (size_t fi = 0; fi < m->mNumFaces; fi++) {
@@ -2062,7 +2070,8 @@ void FBXExporter::WriteObjects () {
                   			ASSIMP_LOG_ERROR("UNREAL: Skipping vertex index to prevent buffer overflow.");
                   			ASSIMP_LOG_ERROR("UNREAL: Skipping vertex index to prevent buffer overflow.");
                         continue;
                         continue;
                     }
                     }
-                    int32_t vi = vVertexIndice[mi][b->mWeights[wi].mVertexId];
+                    int32_t vi = vVertexIndice[mi][b->mWeights[wi].mVertexId]
+                      + uniq_v_before_mi[mi];
                     bool bIsWeightedAlready = (setWeightedVertex.find(vi) != setWeightedVertex.end());
                     bool bIsWeightedAlready = (setWeightedVertex.find(vi) != setWeightedVertex.end());
                     if (vi == last_index || bIsWeightedAlready) {
                     if (vi == last_index || bIsWeightedAlready) {
                         // only for vertices we exported to fbx
                         // only for vertices we exported to fbx