Animate specific bones in .fbx-model

364 views Asked by At

I've tried for some time now to find information about how to move specific bones in a fbx-model. I can manage to rotate the "RootNode" by doing it directly on the model

public void Update(GameTime gameTime)
{
    _model.Bones["RootNode"].Transform = Matrix.CreateRotationY(MathHelper.ToRadians(_ANGLE)) * _model.Bones["RootNode"].Transform;
    UpdateModelTransforms();
}

The model should be correct, since it's made by a professional 3D-artist, and in XNA Model Viewer everything is moveable and seems ok. I can select a specific bone and move it as i want, but when it comes to selecting the same bone through code in XNA, I can't make it work. The model is made in Maya, using the default phong-shader. Below is the code I find most suitable to do this, taken from different tutorials all over...

This second approach work with the RootNode, but when selecting specific bones, noting happens! Can anyone notice what I'm doing wrong?

_model = _contentManager.Load<Model>("Models\\kenny_v002");

_originalBoneTransforms = new Matrix[_model.Bones.Count];
_worldTransforms = new Matrix[_model.Bones.Count];
_transforms = new Matrix[_model.Bones.Count];

_model.CopyAbsoluteBoneTransformsTo(_transforms);
_model.CopyAbsoluteBoneTransformsTo(_originalBoneTransforms);

public void Update(GameTime gameTime)
{
    int boneIndex = _model.Bones["RootNode"].Index;

    _transforms[boneIndex] = Matrix.CreateRotationY(_ANGLE) * _originalBoneTransforms[boneIndex];

    //Root bone
    _worldTransforms[0] = _transforms[0];

    //Child bones
    for (int bone = 1; bone < _worldTransforms.Length; bone++)
    {
        int parentBone = _model.Bones[bone].Parent.Index;
        _worldTransforms[bone] = _transforms[bone] * _worldTransforms[parentBone];
    }
}

public void Draw()
{
    foreach (ModelMesh mesh in _model.Meshes)
    {
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();

            effect.World = _worldTransforms[mesh.ParentBone.Index];
            effect.Projection = _projection;
            effect.View = _view;
        }
        mesh.Draw();
    }
}

It it enough to modify the bone? Or do I have to modify meshes aswell?

0

There are 0 answers