few refactoring

This commit is contained in:
Julien Valentin
2017-08-28 14:23:15 +02:00
parent f995c9187e
commit e216833286
6 changed files with 97 additions and 30 deletions

View File

@@ -34,6 +34,46 @@ RigTransformSoftware::RigTransformSoftware(const RigTransformSoftware& rts,const
}
typedef std::vector<RigTransformSoftware::BonePtrWeight> BoneWeightList;
// sort by name and weight
struct SortByNameAndWeight : public std::less<RigTransformSoftware::BonePtrWeight>
{
bool operator()(const RigTransformSoftware::BonePtrWeight& b0,
const RigTransformSoftware::BonePtrWeight& b1) const
{
if (b0.getBoneName() < b1.getBoneName())
return true;
else if (b0.getBoneName() > b1.getBoneName())
return false;
if (b0.getWeight() < b1.getWeight())
return true;
return false;
}
};
struct SortByBoneWeightList : public std::less<BoneWeightList>
{
bool operator()(const BoneWeightList& b0,
const BoneWeightList& b1) const
{
if (b0.size() < b1.size())
return true;
else if (b0.size() > b1.size())
return false;
int size = b0.size();
for (int i = 0; i < size; i++)
{
bool result = SortByNameAndWeight()(b0[i], b1[i]);
if (result)
return true;
else if (SortByNameAndWeight()(b1[i], b0[i]))
return false;
}
return false;
}
};
bool RigTransformSoftware::init(RigGeometry& geom)
{
if (!geom.getSkeleton())
@@ -142,7 +182,7 @@ void RigTransformSoftware::initVertexSetFromBones(const BoneMap& map, const Vert
continue;
}
Bone* bone = it->second.get();
boneList.push_back(BonePtrWeight(bone, weight));
boneList.push_back(BonePtrWeight(bone->getName(), weight, bone));
sumOfWeight += weight;
}
// if a bone referenced by a vertexinfluence is missed it can make the sum less than 1.0

View File

@@ -40,10 +40,10 @@ void VertexInfluenceSet::buildVertex2BoneList(unsigned int numvertices)
IndexWeight viw = vi[i];
int index = viw.first;
float weight = viw.second;
if (vi.getName().empty()){
if (vi.getBoneName().empty()){
OSG_WARN << "VertexInfluenceSet::buildVertex2BoneList warning vertex " << index << " is not assigned to a bone" << std::endl;
}
_vertex2Bones[index].push_back(BoneWeight(vi.getName(), weight));
_vertex2Bones[index].push_back(BoneWeight(vi.getBoneName(), weight));
}
}

View File

@@ -21,7 +21,7 @@ static bool readInfluenceMap( osgDB::InputStream& is, osgAnimation::RigGeometry&
viSize = is.readSize(); is >> is.BEGIN_BRACKET;
osgAnimation::BoneInfluenceList vi;
vi.setName( name );
vi.setBoneName( name );
vi.reserve( viSize );
for ( unsigned int j=0; j<viSize; ++j )
{