It is possible to iterate through all bones and set it one by one, but it requires one string lookup for each bone that is quite slow. The bone weights seem to be saved one after another in an array, so they could be changed all pretty fast.
I'd make a Pull Request for it, but I can't quite make sense of the pointer magic used there. Iterating through the bones and editing on the addresses as that function calculates is an easy, but not the optimal solution. Something like this:
Code: Select all
void SkeletonAnimation::setWeight( Real weight )
{
for (map<IdString, size_t>::type::const_iterator itor = mDefinition->mBoneWeights.begin(); itor != mDefinition->mBoneWeights.end(); ++itor)
{
size_t level = itor->second >> 24;
size_t offset = itor->second & 0x00FFFFFF;
Real *aliasedBoneWeights = reinterpret_cast<Real*>( mBoneWeights.get() ) +
offset + (*mSlotStarts)[level];
*aliasedBoneWeights = weight;
}
}
//-----------------------------------------------------------------------------------
Real SkeletonAnimation::getWeight()
{
Real total = 0;
int divisor = 0;
for (map<IdString, size_t>::type::const_iterator itor = mDefinition->mBoneWeights.begin(); itor != mDefinition->mBoneWeights.end(); ++itor)
{
size_t level = itor->second >> 24;
size_t offset = itor->second & 0x00FFFFFF;
Real *aliasedBoneWeights = reinterpret_cast<Real*>( mBoneWeights.get() ) +
offset + (*mSlotStarts)[level];
total += *aliasedBoneWeights;
divisor++;
}
return total / divisor;
}