Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
- const
- Anim class
  • Loading branch information
ousnius committed Oct 30, 2016
1 parent 9a31fb2 commit 9557a80
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 135 deletions.
10 changes: 7 additions & 3 deletions src/components/Anim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,21 @@ void AnimInfo::WriteToNif(NifFile* nif, bool synchBoneIDs, const string& shapeEx
}

bool incomplete = false;
SkinTransform xForm;
bool isFO4 = (nif->GetHeader().GetUserVersion() >= 12 && nif->GetHeader().GetUserVersion2() == 130);

for (auto &shapeBoneList : shapeBones) {
if (shapeBoneList.first == shapeException)
continue;

int stype = nif->GetShapeType(shapeBoneList.first);
if (stype == NIUNKNOWN)
continue;

bool isBSShape = (stype == BSTRISHAPE || stype == BSSUBINDEXTRISHAPE || stype == BSMESHLODTRISHAPE || stype == BSDYNAMICTRISHAPE);
bool isFO4 = (nif->GetHeader().GetUserVersion() >= 12 && nif->GetHeader().GetUserVersion2() == 130);

unordered_map<ushort, VertexBoneWeights> vertWeights;
for (auto &boneName : shapeBoneList.second) {
SkinTransform xForm;
if (AnimSkeleton::getInstance().GetBoneTransform(boneName, xForm))
nif->SetNodeTransform(boneName, xForm, true);

Expand Down Expand Up @@ -311,7 +315,7 @@ void AnimInfo::WriteToNif(NifFile* nif, bool synchBoneIDs, const string& shapeEx
}

if (isBSShape)
for (auto vid : vertWeights)
for (auto &vid : vertWeights)
nif->SetShapeVertWeights(shapeBoneList.first, vid.first, vid.second.boneIds, vid.second.weights);
}

Expand Down
49 changes: 16 additions & 33 deletions src/components/Anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@ struct VertexBoneWeights {
vector<byte> boneIds;
vector<float> weights;

VertexBoneWeights() {
}
VertexBoneWeights() { }

void Add(byte inboneid, float inweight) {
if (inweight == 0)
void Add(const byte& inBoneId, const float& inWeight) {
if (inWeight == 0.0f)
return;

for (int i = 0; i < weights.size(); ++i) {
if (inweight < weights[i])
if (inWeight < weights[i])
continue;

weights.insert(weights.begin() + i, inweight);
boneIds.insert(boneIds.begin() + i, inboneid);
weights.insert(weights.begin() + i, inWeight);
boneIds.insert(boneIds.begin() + i, inBoneId);
return;
}

weights.push_back(inweight);
boneIds.push_back(inboneid);
weights.push_back(inWeight);
boneIds.push_back(inBoneId);
}
};

Expand Down Expand Up @@ -76,19 +75,11 @@ class AnimWeight {
BoundingSphere bounds;

AnimWeight() {}
AnimWeight(NifFile* loadFromFile, const string& shape, int index) {
AnimWeight(NifFile* loadFromFile, const string& shape, const int& index) {
loadFromFile->GetShapeBoneWeights(shape, index, weights);
loadFromFile->GetShapeBoneTransform(shape, index, xform);
loadFromFile->GetShapeBoneBounds(shape, index, bounds);
}

bool VertWeight(ushort queryVert, float& weight) {
if (weights.find(queryVert) != weights.end()) {
weight = weights[queryVert];
return true;
}
return false;
}
};

// Bone to weight list association.
Expand All @@ -113,26 +104,18 @@ class AnimSkin {
}
}

void VertexBones(ushort queryvert, vector<int>& outbones, vector<float>& outWeights) {
float wresult;
for (auto &bw : boneWeights) {
if (bw.second.VertWeight(queryvert, wresult)) {
outbones.push_back(bw.first);
outWeights.push_back(wresult);
}
}
}

void RemoveBone(int boneOrder) {
unordered_map<int, AnimWeight> bwtemp;
void RemoveBone(const int& boneOrder) {
unordered_map<int, AnimWeight> bwTemp;
for (auto &bw : boneWeights) {
if (bw.first > boneOrder)
bwtemp[bw.first - 1] = move(bw.second);
bwTemp[bw.first - 1] = move(bw.second);
else if (bw.first < boneOrder)
bwtemp[bw.first] = move(bw.second);
bwTemp[bw.first] = move(bw.second);
}

boneWeights.clear();
for (auto &bw : bwtemp)

for (auto &bw : bwTemp)
boneWeights[bw.first] = move(bw.second);
}
};
Expand Down
Loading

0 comments on commit 9557a80

Please sign in to comment.