This is how I iterate all the bones and set weight to 0.
Code: Select all
Ogre::SkeletonInstance* skelIns = item->getSkeletonInstance();
if (skelIns)
{
Ogre::IdString idString = Ogre::IdString(animationName);
if (skelIns->hasAnimation(idString))
{
Ogre::SkeletonAnimation* animation = skelIns->getAnimation(idString);
if (animation)
{
//set bone weights to 0 as default
for (unsigned int i = 0; i < skelIns->getNumBones(); i++)
{
Ogre::Bone* iBone = skelIns->getBone(i);
Ogre::IdString boneIDString = Ogre::IdString(iBone->getName());
animation->setBoneWeight(boneIDString, 0.0f);
}
mAnimationMap.insert(std::pair<std::string, Ogre::SkeletonAnimation*>(animationName, animation));
}
}
}
I tried this with legacy animations and with the new one but same happens on both.
EDIT: Having overloaded function for setBoneWeight that takes Bone pointer as input would be nice also. I could check the source and try to implement that.
EDIT2: It seems that all bones after depth level 2 doesn't get affected by set bone weight.
EDIT3: Okay, I've double checked that all weights are set to 0 now but it is not working yet.
Code: Select all
//Check that all weights are zero
unsigned int numZeroBone = 0;
for (unsigned int i = 0; i < skelIns->getNumBones(); i++)
{
Ogre::Bone* iBone = skelIns->getBone(i);
Ogre::IdString boneIDString = Ogre::IdString(iBone->getName());
float bWeight = animation->getBoneWeight(boneIDString);
if (bWeight == 0)
{
numZeroBone++;
}
}
if (numZeroBone < skelIns->getNumBones())
{
Ogre::LogManager::getSingleton().logMessage("All bone weights were not zero! All animation bone weights should be zero at creation!", Ogre::LogMessageLevel::LML_CRITICAL);
}