Skip to content

Commit

Permalink
Fixed various bugs with adding a bone through the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ousnius committed Jan 7, 2016
1 parent 1ef8634 commit 317ddde
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 35 deletions.
25 changes: 11 additions & 14 deletions Anim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
37 changes: 17 additions & 20 deletions OutfitProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,11 +1284,6 @@ bool OutfitProject::HasUnweighted() {
}

void OutfitProject::ApplyBoneScale(const string& bone, int sliderPos, bool clear) {
vector<string> bones;
vector<Vector3> boneRot;
Vector3 boneTranslation;
float boneScale;

ClearBoneScale(false);

vector<string> shapes;
Expand All @@ -1310,20 +1305,21 @@ void OutfitProject::ApplyBoneScale(const string& bone, int sliderPos, bool clear
boneScaleOffsets.emplace(s, vector<Vector3>(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;
}
}

Expand Down Expand Up @@ -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<string> 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) {
Expand Down
1 change: 0 additions & 1 deletion OutfitStudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3472,7 +3472,6 @@ void OutfitStudio::OnAddBone(wxCommandEvent& WXUNUSED(event)) {

project->AddBoneRef(bone);
outfitBones->AppendItem(bonesRoot, bone);
/* TODO: Insert bone into outfit */
}
}
}
Expand Down

0 comments on commit 317ddde

Please sign in to comment.