From 13ae0a0ac3a1f464158b24e341fe2a889ce48904 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 22 Mar 2018 22:14:10 +0100 Subject: [PATCH] FBX: fix parse error for uv-coordinates. --- code/FBXMeshGeometry.cpp | 25 ++++++++++---------- code/FBXMeshGeometry.h | 5 ++-- include/assimp/IOStreamBuffer.h | 41 +++++++++++++++++---------------- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/code/FBXMeshGeometry.cpp b/code/FBXMeshGeometry.cpp index 6f7b84d96..12001f76c 100644 --- a/code/FBXMeshGeometry.cpp +++ b/code/FBXMeshGeometry.cpp @@ -79,14 +79,13 @@ Geometry::Geometry(uint64_t id, const Element& element, const std::string& name, // ------------------------------------------------------------------------------------------------ Geometry::~Geometry() { - + // empty } const Skin* Geometry::DeformerSkin() const { return skin; } - // ------------------------------------------------------------------------------------------------ MeshGeometry::MeshGeometry(uint64_t id, const Element& element, const std::string& name, const Document& doc) : Geometry(id, element,name, doc) @@ -186,9 +185,8 @@ MeshGeometry::MeshGeometry(uint64_t id, const Element& element, const std::strin } // ------------------------------------------------------------------------------------------------ -MeshGeometry::~MeshGeometry() -{ - +MeshGeometry::~MeshGeometry() { + // empty } // ------------------------------------------------------------------------------------------------ @@ -218,7 +216,7 @@ const std::vector& MeshGeometry::GetFaceIndexCounts() const { // ------------------------------------------------------------------------------------------------ const std::vector& MeshGeometry::GetTextureCoords( unsigned int index ) const { - static const std::vector empty; + const std::vector empty; return index >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? empty : m_uvs[ index ]; } @@ -227,7 +225,7 @@ std::string MeshGeometry::GetTextureCoordChannelName( unsigned int index ) const } const std::vector& MeshGeometry::GetVertexColors( unsigned int index ) const { - static const std::vector empty; + const std::vector empty; return index >= AI_MAX_NUMBER_OF_COLOR_SETS ? empty : m_colors[ index ]; } @@ -308,7 +306,6 @@ void MeshGeometry::ReadLayerElement(const Scope& layerElement) << type << ", index: " << typedIndex); } - // ------------------------------------------------------------------------------------------------ void MeshGeometry::ReadVertexData(const std::string& type, int index, const Scope& source) { @@ -412,7 +409,6 @@ void MeshGeometry::ReadVertexData(const std::string& type, int index, const Scop } } - // ------------------------------------------------------------------------------------------------ // Lengthy utility function to read and resolve a FBX vertex data array - that is, the // output is in polygon vertex order. This logic is used for reading normals, UVs, colors, @@ -431,7 +427,7 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, bool isDirect = ReferenceInformationType == "Direct"; bool isIndexToDirect = ReferenceInformationType == "IndexToDirect"; - // fallback to direct data if there is no index data element + // fall-back to direct data if there is no index data element if ( isIndexToDirect && !HasElement( source, indexDataElementName ) ) { isDirect = true; isIndexToDirect = false; @@ -499,9 +495,14 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, return; } + const T empty; unsigned int next = 0; for(int i : uvIndices) { - if (static_cast(i) >= tempData.size()) { + if ( -1 == i ) { + data_out[ next++ ] = empty; + continue; + } + if (static_cast(i) >= tempData.size()) { DOMError("index out of range",&GetRequiredElement(source,indexDataElementName)); } @@ -528,7 +529,6 @@ void MeshGeometry::ReadVertexDataNormals(std::vector& normals_out, c m_mappings); } - // ------------------------------------------------------------------------------------------------ void MeshGeometry::ReadVertexDataUV(std::vector& uv_out, const Scope& source, const std::string& MappingInformationType, @@ -543,7 +543,6 @@ void MeshGeometry::ReadVertexDataUV(std::vector& uv_out, const Scope m_mappings); } - // ------------------------------------------------------------------------------------------------ void MeshGeometry::ReadVertexDataColors(std::vector& colors_out, const Scope& source, const std::string& MappingInformationType, diff --git a/code/FBXMeshGeometry.h b/code/FBXMeshGeometry.h index 5dbf6f491..acd44668a 100644 --- a/code/FBXMeshGeometry.h +++ b/code/FBXMeshGeometry.h @@ -68,7 +68,6 @@ private: const Skin* skin; }; - typedef std::vector MatIndexArray; @@ -95,8 +94,8 @@ public: * if no tangents are specified */ const std::vector& GetTangents() const; - /** Get a list of all vertex binormals or an empty array - * if no binormals are specified */ + /** Get a list of all vertex bi-normals or an empty array + * if no bi-normals are specified */ const std::vector& GetBinormals() const; /** Return list of faces - each entry denotes a face and specifies diff --git a/include/assimp/IOStreamBuffer.h b/include/assimp/IOStreamBuffer.h index fdc339062..c93a191df 100644 --- a/include/assimp/IOStreamBuffer.h +++ b/include/assimp/IOStreamBuffer.h @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include + #include "ParsingUtils.h" #include @@ -270,8 +271,8 @@ bool IOStreamBuffer::getNextDataLine( std::vector &buffer, T continuationT } buffer[ i ] = m_cache[ m_cachePos ]; - m_cachePos++; - i++; + ++m_cachePos; + ++i; if ( m_cachePos >= m_cacheSize ) { if ( !readNextBlock() ) { return false; @@ -280,13 +281,12 @@ bool IOStreamBuffer::getNextDataLine( std::vector &buffer, T continuationT } buffer[ i ] = '\n'; - m_cachePos++; + ++m_cachePos; return true; } -static -inline +static inline bool isEndOfCache( size_t pos, size_t cacheSize ) { return ( pos == cacheSize ); } @@ -314,11 +314,11 @@ bool IOStreamBuffer::getNextLine(std::vector &buffer) { } } - size_t i = 0; + size_t i( 0 ); while (!IsLineEnd(m_cache[ m_cachePos ])) { buffer[i] = m_cache[ m_cachePos ]; - m_cachePos++; - i++; + ++m_cachePos; + ++i; if (m_cachePos >= m_cacheSize) { if (!readNextBlock()) { return false; @@ -326,7 +326,7 @@ bool IOStreamBuffer::getNextLine(std::vector &buffer) { } } buffer[i] = '\n'; - m_cachePos++; + ++m_cachePos; return true; } @@ -334,18 +334,19 @@ bool IOStreamBuffer::getNextLine(std::vector &buffer) { template inline bool IOStreamBuffer::getNextBlock( std::vector &buffer) { - //just return the last blockvalue if getNextLine was used before - if ( m_cachePos != 0) { - buffer = std::vector(m_cache.begin() + m_cachePos, m_cache.end()); - m_cachePos = 0; - } - else { - if ( !readNextBlock() ) - return false; + // Return the last block-value if getNextLine was used before + if ( 0 != m_cachePos ) { + buffer = std::vector( m_cache.begin() + m_cachePos, m_cache.end() ); + m_cachePos = 0; + } else { + if ( !readNextBlock() ) { + return false; + } - buffer = std::vector(m_cache.begin(), m_cache.end()); - } - return true; + buffer = std::vector(m_cache.begin(), m_cache.end()); + } + + return true; } } // !ns Assimp