我如何在XNA 4.0中使用搅拌机动画
本文关键字:搅拌机 动画 XNA | 更新日期: 2023-09-27 18:15:53
我有一个模型在Blender(2.6+)与操纵动画。我把它导出到FBX,再导入到XNA。我知道如何在屏幕上绘制它,但我如何运行动画(例如称为"运行")?
谢谢!
您可以使用来自microsoft的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
LoadContent方法:
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();
}