c# - 我如何在 XNA 4.0 中使用搅拌器动画?

标签 c# xna xna-4.0 blender

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

谢谢!

最佳答案

您可以使用 SkinnedModelSample来自微软。确保在属性框中将 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();
}

关于c# - 我如何在 XNA 4.0 中使用搅拌器动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8280328/

相关文章:

c# - 如何检查字符串是否是 WPF 中 FrameworkElement 的有效名称?

c# - 我怎么能在int上执行方法?在没有 NullReferenceException 的情况下设置为 null?

javascript - 将 javascript 变量 “11:00 AM” 转换为 c# 等效项,其中 SQL 为时间格式

c# - 如何创建用于访问 XNA 内容项目中文件的强类型结构?

c# - XNA:防止方法返回

visual-studio-2010 - 构建时被另一个进程锁定的输出文件

c# - XNA 柏林噪音星球

c# - GridView 行中的动态复选框在 ASP.NET 中未正确显示

c# - 编译器错误1 : constructor contains more than 0 args

c# - XNA - Mouse.Left Button 在 Update 中执行了不止一次