【问题标题】:How can I use blender animations in XNA 4.0?如何在 XNA 4.0 中使用搅拌机动画?
【发布时间】:2012-01-06 23:54:41
【问题描述】:

我在 Blender (2.6+) 中有一个带有装配动画的模型。我将它导出到 FBX 并将其导入到 XNA。我知道如何在屏幕上绘制它,但是如何运行动画(例如称为“运行”)?

谢谢!

【问题讨论】:

标签: c# xna xna-4.0 blender


【解决方案1】:

您可以使用来自微软的SkinnedModelSample。确保在 Properties 框中将 fbx 文件的 ContentProcessor 属性设置为 SkinnedModelProcessor ,然后你可以这样做(需要优化):

主游戏类:

AnimationPlayer player;// This calculates the Matrices of the animation
AnimationClip clip;// This contains the keyframes of the animation
SkinningData skin;// This contains all the skinning data
Model model;// The actual model

加载内容方法:

model = Content.Load<Model>("path_to_model");
skin = model.Tag as SkinningData;// The SkinnedModelProcessor puts skinning data in the Tag property

player = new AnimationPlayer(skin);
clip = skin.AnimationClips["run"];// The name of the animation

player.StartClip(clip);

绘制方法:

Matrix[] bones = player.GetSkinTransforms();

// Compute camera matrices.
Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, -30), // Change the last number according to the size of your model
                                          new Vector3(0, 0, 0), Vector3.Up);

Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                        device.Viewport.AspectRatio,
                                                        1,
                                                        10000);

// Render the skinned mesh.
foreach (ModelMesh mesh in model.Meshes)
{
    foreach (SkinnedEffect effect in mesh.Effects)
    {
        effect.SetBoneTransforms(bones);

        effect.View = view;
        effect.Projection = projection;

        effect.EnableDefaultLighting();

        effect.SpecularColor = new Vector3(0.25f);
        effect.SpecularPower = 16;
    }

    mesh.Draw();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-24
    • 2021-12-15
    • 2020-03-01
    • 2015-08-16
    • 2019-07-27
    • 2012-06-15
    • 2015-03-05
    • 2018-08-06
    相关资源
    最近更新 更多