From b3c44857b8a6b9eb0268d3db3917e14e97ccd582 Mon Sep 17 00:00:00 2001 From: ousnius Date: Mon, 27 Nov 2017 23:50:20 +0100 Subject: [PATCH] Make FBX import use bone transforms of current ref shape --- src/components/Anim.cpp | 9 +++++++++ src/components/Anim.h | 1 + src/program/OutfitProject.cpp | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/src/components/Anim.cpp b/src/components/Anim.cpp index 7d6b22df..f64c2e65 100644 --- a/src/components/Anim.cpp +++ b/src/components/Anim.cpp @@ -201,6 +201,15 @@ void AnimInfo::GetWeights(const std::string& shape, const std::string& boneName, outVertWeights = *weights; } +bool AnimInfo::GetShapeBoneXForm(const std::string& shape, const std::string& boneName, MatTransform& stransform) { + int b = GetShapeBoneIndex(shape, boneName); + if (b < 0) + return false; + + stransform = shapeSkinning[shape].boneWeights[b].xform; + return true; +} + void AnimInfo::SetShapeBoneXForm(const std::string& shape, const std::string& boneName, MatTransform& stransform) { int b = GetShapeBoneIndex(shape, boneName); if (b < 0) diff --git a/src/components/Anim.h b/src/components/Anim.h index 2ca97747..bf885dc9 100644 --- a/src/components/Anim.h +++ b/src/components/Anim.h @@ -145,6 +145,7 @@ class AnimInfo { void GetWeights(const std::string& shape, const std::string& boneName, std::unordered_map& outVertWeights); void GetBoneXForm(const std::string& boneName, MatTransform& stransform); void SetWeights(const std::string& shape, const std::string& boneName, std::unordered_map& inVertWeights); + bool GetShapeBoneXForm(const std::string& shape, const std::string& boneName, MatTransform& stransform); void SetShapeBoneXForm(const std::string& shape, const std::string& boneName, MatTransform& stransform); bool CalcShapeSkinBounds(const std::string& shape, const int& boneIndex); void WriteToNif(NifFile* nif, const std::string& shapeException = ""); diff --git a/src/program/OutfitProject.cpp b/src/program/OutfitProject.cpp index c77fa56b..fb9b6952 100644 --- a/src/program/OutfitProject.cpp +++ b/src/program/OutfitProject.cpp @@ -2292,6 +2292,13 @@ int OutfitProject::ImportFBX(const std::string& fileName, const std::string& sha workAnim.shapeBones[useShapeName].push_back(bn); workAnim.shapeSkinning[useShapeName].boneNames[bn] = slot; workAnim.SetWeights(useShapeName, bn, shape->boneSkin[bn].GetWeights()); + + if (!baseShape.empty()) { + MatTransform xform; + if (workAnim.GetShapeBoneXForm(baseShape, bn, xform)) + workAnim.SetShapeBoneXForm(useShapeName, bn, xform); + } + boneIndices.push_back(slot++); }