瀏覽代碼

Interpret IndexAToDirect as Direct when the index element is missing
Paint3D exports FBX like this, which is wrong, but could still support it

Rohan Singh 7 年之前
父節點
當前提交
b28bcc365c
共有 1 個文件被更改,包括 11 次插入11 次删除
  1. 11 11
      code/FBXMeshGeometry.cpp

+ 11 - 11
code/FBXMeshGeometry.cpp

@@ -427,16 +427,19 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
     const std::vector<unsigned int>& mapping_offsets,
     const std::vector<unsigned int>& mapping_offsets,
     const std::vector<unsigned int>& mappings)
     const std::vector<unsigned int>& mappings)
 {
 {
+    bool isDirect = ReferenceInformationType == "Direct";
+    bool isIndexToDirect = ReferenceInformationType == "IndexToDirect";
 
 
+    // fallback to direct data if there is no index data element
+    if ( isIndexToDirect && !HasElement( source, indexDataElementName ) ) {
+        isDirect = true;
+        isIndexToDirect = false;
+    }
 
 
     // handle permutations of Mapping and Reference type - it would be nice to
     // handle permutations of Mapping and Reference type - it would be nice to
     // deal with this more elegantly and with less redundancy, but right
     // deal with this more elegantly and with less redundancy, but right
     // now it seems unavoidable.
     // now it seems unavoidable.
-    if (MappingInformationType == "ByVertice" && ReferenceInformationType == "Direct") {
-        if ( !HasElement( source, indexDataElementName ) ) {
-            return;
-        }
-
+    if (MappingInformationType == "ByVertice" && isDirect) {
         std::vector<T> tempData;
         std::vector<T> tempData;
 		ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
 		ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
 
 
@@ -449,14 +452,11 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
             }
             }
         }
         }
     }
     }
-    else if (MappingInformationType == "ByVertice" && ReferenceInformationType == "IndexToDirect") {
+    else if (MappingInformationType == "ByVertice" && isIndexToDirect) {
 		std::vector<T> tempData;
 		std::vector<T> tempData;
 		ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
 		ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
 
 
         data_out.resize(vertex_count);
         data_out.resize(vertex_count);
-        if ( !HasElement( source, indexDataElementName ) ) {
-            return;
-        }
 
 
         std::vector<int> uvIndices;
         std::vector<int> uvIndices;
         ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
         ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
@@ -471,7 +471,7 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
             }
             }
         }
         }
     }
     }
-    else if (MappingInformationType == "ByPolygonVertex" && ReferenceInformationType == "Direct") {
+    else if (MappingInformationType == "ByPolygonVertex" && isDirect) {
 		std::vector<T> tempData;
 		std::vector<T> tempData;
 		ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
 		ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
 
 
@@ -484,7 +484,7 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
 
 
 		data_out.swap(tempData);
 		data_out.swap(tempData);
     }
     }
-    else if (MappingInformationType == "ByPolygonVertex" && ReferenceInformationType == "IndexToDirect") {
+    else if (MappingInformationType == "ByPolygonVertex" && isIndexToDirect) {
 		std::vector<T> tempData;
 		std::vector<T> tempData;
 		ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
 		ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));