diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 667e86755..fae11b32f 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -594,6 +594,11 @@ private: } ConvertMaterialForMesh(out_mesh,model,mesh,index); + + if(doc.Settings().readWeights && mesh.DeformerSkin() != NULL) { + ConvertWeights(out_mesh, model, mesh, index); + } + return static_cast(meshes.size() - 1); } @@ -654,6 +659,7 @@ private: if (index_out_indices.back() == no_index_sentinel) { index_out_indices.back() = out_indices.size(); + count_out_indices.push_back(0); } out_indices.push_back(out_idx[i]); @@ -699,6 +705,8 @@ private: bones.push_back(bone); bone->mName = FixNodeName(cl.TargetNode()->Name()); + bone->mOffsetMatrix = cl.TransformLink(); + bone->mOffsetMatrix.Inverse(); bone->mNumWeights = static_cast(out_indices.size()); aiVertexWeight* cursor = bone->mWeights = new aiVertexWeight[out_indices.size()]; diff --git a/code/FBXDocument.cpp b/code/FBXDocument.cpp index d02931bbb..d20b3b536 100644 --- a/code/FBXDocument.cpp +++ b/code/FBXDocument.cpp @@ -388,7 +388,7 @@ aiMatrix4x4 ReadMatrix(const Element& element) aiMatrix4x4 result; - // XXX transposed or not, this is the question :-) + result.a1 = values[0]; result.a2 = values[1]; result.a3 = values[2]; @@ -409,6 +409,7 @@ aiMatrix4x4 ReadMatrix(const Element& element) result.d3 = values[14]; result.d4 = values[15]; + result.Transpose(); return result; } diff --git a/code/FBXDocument.h b/code/FBXDocument.h index e736ce1c4..805b6e162 100644 --- a/code/FBXDocument.h +++ b/code/FBXDocument.h @@ -484,9 +484,10 @@ public: // in the current conversion pattern this will only be needed if // weights are present, so no need to always pre-compute this table if (facesVertexStartIndices.empty()) { - facesVertexStartIndices.resize(faces.size()); + facesVertexStartIndices.resize(faces.size() + 1, 0); - std::partial_sum(faces.begin(), faces.end(), facesVertexStartIndices.begin()); + std::partial_sum(faces.begin(), faces.end(), facesVertexStartIndices.begin() + 1); + facesVertexStartIndices.pop_back(); } ai_assert(facesVertexStartIndices.size() == faces.size()); diff --git a/code/FBXMeshGeometry.cpp b/code/FBXMeshGeometry.cpp index 0586ab46c..f828b89b7 100644 --- a/code/FBXMeshGeometry.cpp +++ b/code/FBXMeshGeometry.cpp @@ -154,7 +154,7 @@ MeshGeometry::MeshGeometry(uint64_t id, const Element& element, const std::strin cursor = 0; BOOST_FOREACH(int index, tempFaces) { const int absi = index < 0 ? (-index - 1) : index; - mappings[mapping_offsets[absi] + mapping_counts[absi]++] = cursor; + mappings[mapping_offsets[absi] + mapping_counts[absi]++] = cursor++; } // if settings.readAllLayers is true: