few refactoring
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user