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

closes https://github.com/assimp/assimp/issues/1460: skip uv- and color-components if these are not defined.

Kim Kulling 7 жил өмнө
parent
commit
9efa4282fe

+ 8 - 1
code/FBXMeshGeometry.cpp

@@ -433,7 +433,11 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
     // deal with this more elegantly and with less redundancy, but right
     // now it seems unavoidable.
     if (MappingInformationType == "ByVertice" && ReferenceInformationType == "Direct") {
-		std::vector<T> tempData;
+        if ( !HasElement( source, indexDataElementName ) ) {
+            return;
+        }
+
+        std::vector<T> tempData;
 		ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
 
         data_out.resize(vertex_count);
@@ -452,6 +456,9 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
         data_out.resize(vertex_count);
 
         std::vector<int> uvIndices;
+        if ( !HasElement( source, indexDataElementName ) ) {
+            return;
+        }
         ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
 
         for (size_t i = 0, e = uvIndices.size(); i < e; ++i) {

+ 8 - 0
code/FBXParser.cpp

@@ -1197,6 +1197,14 @@ std::string ParseTokenAsString(const Token& t)
     return i;
 }
 
+bool HasElement( const Scope& sc, const std::string& index ) {
+    const Element* el = sc[ index ];
+    if ( nullptr == el ) {
+        return false;
+    }
+
+    return true;
+}
 
 // ------------------------------------------------------------------------------------------------
 // extract a required element from a scope, abort if the element cannot be found

+ 2 - 0
code/FBXParser.h

@@ -218,6 +218,8 @@ void ParseVectorDataArray(std::vector<unsigned int>& out, const Element& el);
 void ParseVectorDataArray(std::vector<uint64_t>& out, const Element& e);
 void ParseVectorDataArray(std::vector<int64_t>& out, const Element& el);
 
+bool HasElement( const Scope& sc, const std::string& index );
+
 // extract a required element from a scope, abort if the element cannot be found
 const Element& GetRequiredElement(const Scope& sc, const std::string& index, const Element* element = NULL);