How can I use blender animation in XNA 4.0?

I have a model in Blender (2.6+) with fake animations. I exported it to FBX and imported it to XNA. I know ho to draw it on the screen, but how can I start an animation (called, for example, "run")?

Thanks!

+4
source share
1 answer

You can use SkinnedModelSample from microsoft. Make sure you set the ContentProcessor property of the fbx file to SkinnedModelProcessor in the Properties field. Then you can execute (optimization is required):

The main class of the game:

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 Method:

 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); 

Drawing method:

 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(); } 
+7
source

Source: https://habr.com/ru/post/1383210/


All Articles