From 9efa4282fedfc71a12b72105a0cbc5c2f3c8532e Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 4 Jan 2018 12:37:35 +0100 Subject: [PATCH] closes https://github.com/assimp/assimp/issues/1460: skip uv- and color-components if these are not defined. --- code/FBXMeshGeometry.cpp | 9 ++++++++- code/FBXParser.cpp | 8 ++++++++ code/FBXParser.h | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/code/FBXMeshGeometry.cpp b/code/FBXMeshGeometry.cpp index 8d43a2436..ad0ffcf55 100644 --- a/code/FBXMeshGeometry.cpp +++ b/code/FBXMeshGeometry.cpp @@ -433,7 +433,11 @@ void ResolveVertexDataArray(std::vector& 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 tempData; + if ( !HasElement( source, indexDataElementName ) ) { + return; + } + + std::vector tempData; ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); data_out.resize(vertex_count); @@ -452,6 +456,9 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, data_out.resize(vertex_count); std::vector uvIndices; + if ( !HasElement( source, indexDataElementName ) ) { + return; + } ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName)); for (size_t i = 0, e = uvIndices.size(); i < e; ++i) { diff --git a/code/FBXParser.cpp b/code/FBXParser.cpp index d4d06567b..935fe5b08 100644 --- a/code/FBXParser.cpp +++ b/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 diff --git a/code/FBXParser.h b/code/FBXParser.h index 4d3766d70..736adcea0 100644 --- a/code/FBXParser.h +++ b/code/FBXParser.h @@ -218,6 +218,8 @@ void ParseVectorDataArray(std::vector& out, const Element& el); void ParseVectorDataArray(std::vector& out, const Element& e); void ParseVectorDataArray(std::vector& 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);