From 2f3c47cab631193af21b3b6fe2dea71d64854e22 Mon Sep 17 00:00:00 2001 From: "lutz.hoeren" Date: Tue, 8 Dec 2015 12:26:41 +0100 Subject: [PATCH 1/2] Only read Element Data when there is a valid Mapping Information --- code/FBXMeshGeometry.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/code/FBXMeshGeometry.cpp b/code/FBXMeshGeometry.cpp index 45476d8c1..e0a25cd9c 100644 --- a/code/FBXMeshGeometry.cpp +++ b/code/FBXMeshGeometry.cpp @@ -347,23 +347,28 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, const std::vector& mapping_offsets, const std::vector& mappings) { - std::vector tempUV; - ParseVectorDataArray(tempUV,GetRequiredElement(source,dataElementName)); + // handle permutations of Mapping and Reference type - it would be nice to // deal with this more elegantly and with less redundancy, but right // now it seems unavoidable. if (MappingInformationType == "ByVertice" && ReferenceInformationType == "Direct") { + std::vector tempData; + ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); + data_out.resize(vertex_count); - for (size_t i = 0, e = tempUV.size(); i < e; ++i) { + for (size_t i = 0, e = tempData.size(); i < e; ++i) { const unsigned int istart = mapping_offsets[i], iend = istart + mapping_counts[i]; for (unsigned int j = istart; j < iend; ++j) { - data_out[mappings[j]] = tempUV[i]; + data_out[mappings[j]] = tempData[i]; } } } else if (MappingInformationType == "ByVertice" && ReferenceInformationType == "IndexToDirect") { + std::vector tempData; + ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); + data_out.resize(vertex_count); std::vector uvIndices; @@ -373,24 +378,30 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, const unsigned int istart = mapping_offsets[i], iend = istart + mapping_counts[i]; for (unsigned int j = istart; j < iend; ++j) { - if(static_cast(uvIndices[i]) >= tempUV.size()) { + if (static_cast(uvIndices[i]) >= tempData.size()) { DOMError("index out of range",&GetRequiredElement(source,indexDataElementName)); } - data_out[mappings[j]] = tempUV[uvIndices[i]]; + data_out[mappings[j]] = tempData[uvIndices[i]]; } } } else if (MappingInformationType == "ByPolygonVertex" && ReferenceInformationType == "Direct") { - if (tempUV.size() != vertex_count) { + std::vector tempData; + ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); + + if (tempData.size() != vertex_count) { FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygon mapping: ") - << tempUV.size() << ", expected " << vertex_count + << tempData.size() << ", expected " << vertex_count ); return; } - data_out.swap(tempUV); + data_out.swap(tempData); } else if (MappingInformationType == "ByPolygonVertex" && ReferenceInformationType == "IndexToDirect") { + std::vector tempData; + ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); + data_out.resize(vertex_count); std::vector uvIndices; @@ -403,11 +414,11 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, unsigned int next = 0; BOOST_FOREACH(int i, uvIndices) { - if(static_cast(i) >= tempUV.size()) { + if (static_cast(i) >= tempData.size()) { DOMError("index out of range",&GetRequiredElement(source,indexDataElementName)); } - data_out[next++] = tempUV[i]; + data_out[next++] = tempData[i]; } } else { From e8a02ef890d9ce772a9429c62adaedf7c6d2c427 Mon Sep 17 00:00:00 2001 From: "lutz.hoeren" Date: Tue, 8 Dec 2015 12:26:41 +0100 Subject: [PATCH 2/2] Only read Element Data when there is a valid Mapping Information --- code/FBXMeshGeometry.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/code/FBXMeshGeometry.cpp b/code/FBXMeshGeometry.cpp index 45476d8c1..e0a25cd9c 100644 --- a/code/FBXMeshGeometry.cpp +++ b/code/FBXMeshGeometry.cpp @@ -347,23 +347,28 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, const std::vector& mapping_offsets, const std::vector& mappings) { - std::vector tempUV; - ParseVectorDataArray(tempUV,GetRequiredElement(source,dataElementName)); + // handle permutations of Mapping and Reference type - it would be nice to // deal with this more elegantly and with less redundancy, but right // now it seems unavoidable. if (MappingInformationType == "ByVertice" && ReferenceInformationType == "Direct") { + std::vector tempData; + ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); + data_out.resize(vertex_count); - for (size_t i = 0, e = tempUV.size(); i < e; ++i) { + for (size_t i = 0, e = tempData.size(); i < e; ++i) { const unsigned int istart = mapping_offsets[i], iend = istart + mapping_counts[i]; for (unsigned int j = istart; j < iend; ++j) { - data_out[mappings[j]] = tempUV[i]; + data_out[mappings[j]] = tempData[i]; } } } else if (MappingInformationType == "ByVertice" && ReferenceInformationType == "IndexToDirect") { + std::vector tempData; + ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); + data_out.resize(vertex_count); std::vector uvIndices; @@ -373,24 +378,30 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, const unsigned int istart = mapping_offsets[i], iend = istart + mapping_counts[i]; for (unsigned int j = istart; j < iend; ++j) { - if(static_cast(uvIndices[i]) >= tempUV.size()) { + if (static_cast(uvIndices[i]) >= tempData.size()) { DOMError("index out of range",&GetRequiredElement(source,indexDataElementName)); } - data_out[mappings[j]] = tempUV[uvIndices[i]]; + data_out[mappings[j]] = tempData[uvIndices[i]]; } } } else if (MappingInformationType == "ByPolygonVertex" && ReferenceInformationType == "Direct") { - if (tempUV.size() != vertex_count) { + std::vector tempData; + ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); + + if (tempData.size() != vertex_count) { FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygon mapping: ") - << tempUV.size() << ", expected " << vertex_count + << tempData.size() << ", expected " << vertex_count ); return; } - data_out.swap(tempUV); + data_out.swap(tempData); } else if (MappingInformationType == "ByPolygonVertex" && ReferenceInformationType == "IndexToDirect") { + std::vector tempData; + ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); + data_out.resize(vertex_count); std::vector uvIndices; @@ -403,11 +414,11 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, unsigned int next = 0; BOOST_FOREACH(int i, uvIndices) { - if(static_cast(i) >= tempUV.size()) { + if (static_cast(i) >= tempData.size()) { DOMError("index out of range",&GetRequiredElement(source,indexDataElementName)); } - data_out[next++] = tempUV[i]; + data_out[next++] = tempData[i]; } } else {