diff --git a/Anim.cpp b/Anim.cpp index c7e3ffd5..66ad7e29 100644 --- a/Anim.cpp +++ b/Anim.cpp @@ -12,7 +12,8 @@ bool AnimInfo::AddShapeBone(const string& shape, AnimBone& boneDataRef) { if (!bone.compare(boneDataRef.boneName)) return false; - shapeSkinning[shape].boneNames[boneDataRef.boneName] = shapeBones.size(); + shapeSkinning[shape].boneNames[boneDataRef.boneName] = shapeBones[shape].size(); + shapeSkinning[shape].bNeedsBoundsCalc = true; shapeBones[shape].push_back(boneDataRef.boneName); AnimSkeleton::getInstance().RefBone(boneDataRef.boneName); return true; @@ -165,7 +166,6 @@ void AnimInfo::SetShapeBoneXForm(const string& shape, const string& boneName, Sk return; shapeSkinning[shape].boneWeights[b].xform = stransform; - } bool AnimInfo::CalcShapeSkinBounds(const string& shape) { @@ -203,24 +203,21 @@ bool AnimInfo::CalcShapeSkinBounds(const string& shape) { d = max(d, tot.DistanceTo(v)); } - Matrix4 mat; - Vector3 trans; + Matrix4 mat; + Vector3 trans; - AnimBone* xformRef = AnimSkeleton::getInstance().GetBonePtr(bn.first); - if (xformRef->hasSkinXform) { - mat = xformRef->skinRot; - trans = xformRef->skinTrans; - } - else { - // Just FYI, I have no idea if the transform here is even slightly appropriate. - mat = shapeSkinning[shape].boneWeights[bn.second].xform.ToMatrix(); - } + AnimBone* xformRef = AnimSkeleton::getInstance().GetBonePtr(bn.first); + if (xformRef->hasSkinXform) { + mat = xformRef->skinRot; + trans = xformRef->skinTrans; + } + else + mat = shapeSkinning[shape].boneWeights[bn.second].xform.ToMatrix(); tot = mat * tot; tot = tot + trans; shapeSkinning[shape].boneWeights[bn.second].bSphereOffset = tot; shapeSkinning[shape].boneWeights[bn.second].bSphereRadius = d; - } return true; } diff --git a/OutfitProject.cpp b/OutfitProject.cpp index 9dbf23ec..af1d5c20 100644 --- a/OutfitProject.cpp +++ b/OutfitProject.cpp @@ -1284,11 +1284,6 @@ bool OutfitProject::HasUnweighted() { } void OutfitProject::ApplyBoneScale(const string& bone, int sliderPos, bool clear) { - vector bones; - vector boneRot; - Vector3 boneTranslation; - float boneScale; - ClearBoneScale(false); vector shapes; @@ -1310,20 +1305,21 @@ void OutfitProject::ApplyBoneScale(const string& bone, int sliderPos, bool clear boneScaleOffsets.emplace(s, vector(verts->size())); it = boneScaleOffsets.find(s); - workNif.GetShapeBoneList(s, bones); - for (auto &b : bones) { + for (auto &b : workAnim.shapeBones[s]) { if (b == bone) { - workNif.GetNodeTransform(b, boneRot, boneTranslation, boneScale); + SkinTransform xForm; + workAnim.GetBoneXForm(b, xForm); if (workWeights[s].empty()) workAnim.GetWeights(s, b, workWeights[s]); for (auto &w : workWeights[s]) { - Vector3 dir = (*verts)[w.first] - boneTranslation; + Vector3 dir = (*verts)[w.first] - xForm.translation; dir.Normalize(); Vector3 offset = dir * w.second * sliderPos / 5.0f; (*verts)[w.first] += offset; it->second[w.first] += offset; } + break; } } @@ -1366,21 +1362,22 @@ void OutfitProject::ClearBoneScale(bool clear) { } void OutfitProject::AddBoneRef(const string& boneName) { - AnimBone boneRef; - AnimSkeleton::getInstance().GetBone(boneName, boneRef); + AnimBone *boneRef = AnimSkeleton::getInstance().GetBonePtr(boneName); + if (!boneRef) + return; + + SkinTransform xForm; + workAnim.GetBoneXForm(boneName, xForm); + + boneRef->skinRot.Set(xForm.rotation); + boneRef->skinTrans = xForm.translation; + boneRef->hasSkinXform = true; vector shapes; GetShapes(shapes); - for (auto &s : shapes) { - if (IsBaseShape(s)) - continue; - - if (workAnim.AddShapeBone(s, boneRef)) { - SkinTransform xForm; - workAnim.GetBoneXForm(boneName, xForm); + for (auto &s : shapes) + if (workAnim.AddShapeBone(s, *boneRef)) workAnim.SetShapeBoneXForm(s, boneName, xForm); - } - } } void OutfitProject::BuildShapeSkinPartions(const string& destShape) { diff --git a/OutfitStudio.cpp b/OutfitStudio.cpp index 52fb4f2d..5d12e24a 100644 --- a/OutfitStudio.cpp +++ b/OutfitStudio.cpp @@ -3472,7 +3472,6 @@ void OutfitStudio::OnAddBone(wxCommandEvent& WXUNUSED(event)) { project->AddBoneRef(bone); outfitBones->AppendItem(bonesRoot, bone); - /* TODO: Insert bone into outfit */ } } }