CSkinnedMesh

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
JVr
Posts: 28
Joined: Wed Oct 19, 2011 2:32 pm

CSkinnedMesh

Post by JVr »

I found a bug in CSkinnedMesh source.

The core if problem is the build of LocalAnimatedMatrix from Animatedrotation, Animatedposition, Animatedscale - while theese values may not be filled!

For example the value Animatedposition is not filled for example if there are no PositionKeys (!PositionKeys.size()).

The fix of this issue is usage of position, rotation or scale from LocalMatrix

I've not found this fixed in current trunk so I guess it's not solved yet.

my snippet is not ideal I'm sure, but it solved the issue (however I wasn't solving scale coz my animation does not have scale keys)

Code: Select all

 
void CSkinnedMesh::buildAll_LocalAnimatedMatrices()
{
        for (u32 i=0; i<AllJoints.size(); ++i)
        {
                SJoint *joint = AllJoints[i];
 
                //Could be faster:
 
                if (joint->UseAnimationFrom &&
                        (joint->UseAnimationFrom->PositionKeys.size() ||
                         joint->UseAnimationFrom->ScaleKeys.size() ||
                         joint->UseAnimationFrom->RotationKeys.size() ))
                {
                        joint->GlobalSkinningSpace=false;
                        joint->LocalAnimatedMatrix.makeIdentity();
                        
                        if (joint->UseAnimationFrom->PositionKeys.size())
                                joint->LocalAnimatedMatrix.setTranslation(joint->Animatedposition);
                        else
                                joint->LocalAnimatedMatrix.setTranslation(joint->LocalMatrix.getTranslation());
                        
                        if (joint->UseAnimationFrom->RotationKeys.size())
                                joint->LocalAnimatedMatrix = joint->LocalAnimatedMatrix * joint->Animatedrotation.getMatrix();
                        else
                        {
                                core::quaternion rot (joint->LocalMatrix);
                                joint->LocalAnimatedMatrix = joint->LocalAnimatedMatrix * rot.getMatrix();
                        }
                }
                else
                {
                        joint->LocalAnimatedMatrix=joint->LocalMatrix;
                }
        }
} 
 
This code isn't ideal! Just to make a picture what's goin on. - I was just making hotfix. :P
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: CSkinnedMesh

Post by hybrid »

Is there a way to easily reproduce this bug somehow? What is the purpose of LocalAnimatedMatrix and LocalMatrix anyway, and why do we need the three different spearate values and the matrix? Not to scare you off, but as I stated several times already, I don't have a full understanding of the skinned mesh system so far. So it would be good to know what is broken here (besides a general non-initialization which might occur - or not).
JVr
Posts: 28
Joined: Wed Oct 19, 2011 2:32 pm

Re: CSkinnedMesh

Post by JVr »

Actually to reproduce this bug just made a joint (SJoint class) of model (ISkinnedMesh) with only rotation keys. It will rotate during animation however its postion will stay at 0;0;0 (X;Y;Z).
JVr
Posts: 28
Joined: Wed Oct 19, 2011 2:32 pm

Re: CSkinnedMesh

Post by JVr »

Oki how it works now:
Once engine demands position in some frame of SJoint there are computed values AnimatedPositon, AnimatedRotation, AnimatedScale from PositonKeys, RotationKeys, ScaleKeys (there may be interpolation) however ONLY IF there are any PositonKeys, RotationKeys, ScaleKeys. So for example if there are no RotationKeys value of AnimatedRotation is not filled.

LocalAnimatedMatrix is there only to save result of animation (AnimatedPositon, AnimatedRotation, AnimatedScale) and is actually later used to animate joint (mesh of joint).

The value LocalMatrix is just an initial (static) state of SJoint.
Post Reply