But before submitting my changes as a patch, I would like to know whether what I did can be considered the "correct" way to do it from a design standpoint, or if there are some things I missed that have to changed/added before this can be accepted as a patch, so here goes:
Additional methods/data in OgreAnimationState.h:
Code: Select all
/// create a new blend mask with the given number of entries
void createBlendMask(ushort p_BlendMaskSize, bool p_Fill = true);
/// destroy the currently set blend mask
void destroyBlendMask();
/// set the blend mask (allowing for per bone weights)
void setBlendMask(const Real* p_BlendMask, ushort p_BlendMaskSize);
/// get the current blend mask (const version, may be 0)
const Real* getBlendMask() const {return mBlendMask;}
/// get the current blend mask (may be 0)
Real* getBlendMask() {return mBlendMask;}
/// return whether there is currently a valid blend mask set
bool hasBlendMask() const {return mBlendMask != 0;}
/// set the weight for the bone identified by the given handle
inline void setBoneWeight(ushort p_BoneHandle, Real p_Weight)
{
assert(mBlendMaskSize > p_BoneHandle);
mBlendMask[p_BoneHandle] = p_Weight;
}
/// get the weight for the bone identified by the given handle
inline Real getBoneWeight(ushort p_BoneHandle) const
{
assert(mBlendMaskSize > p_BoneHandle);
return mBlendMask[p_BoneHandle];
}
protected:
/// the blend mask (containing per bone weights)
Real* mBlendMask;
/// the size of the blend mask (array size)
ushort mBlendMaskSize;
Code: Select all
void apply(Skeleton* skeleton, Real timePos, float weight,
const float* blendMask, Real scale);
Code: Select all
void Animation::apply(Skeleton* skel, Real timePos, float weight,
const float* blendMask, Real scale)
{
// Calculate time index for fast keyframe search
TimeIndex timeIndex = _getTimeIndex(timePos);
NodeTrackList::iterator i;
unsigned short handle = 0;
for (i = mNodeTrackList.begin(); i != mNodeTrackList.end(); ++i)
{
// get bone to apply to
Bone* b = skel->getBone(i->first);
i->second->applyToNode(b, timeIndex, blendMask[handle++] * weight, scale);
}
}
Code: Select all
// tolerate state entries for animations we're not aware of
if (anim)
{
if(animState->hasBlendMask())
{
anim->apply(this, animState->getTimePosition(), animState->getWeight() * weightFactor,
animState->getBlendMask(), linked ? linked->scale : 1.0f);
}
else
{
anim->apply(this, animState->getTimePosition(),
animState->getWeight() * weightFactor, linked ? linked->scale : 1.0f);
}
}
Please let me know what you think.