Skip to content

Using The Model Animation Library

JoshuaKlaser edited this page Jun 5, 2014 · 1 revision

Content

The first thing we will explain is how to organise your content (You can't have a project using 3D models without 3D models).

Add your .fbx file to the content project as if this were any other XNA project and change the 'Processor' and 'Importer' options to the 'ModelAnimationImporter' and ModelAnimationProcessor' selection. If you cannot find these options, press 'alt + enter' while your .fbx is highlighted to go to it.

The ModelAnimationImporter has a drop down menu in which you can tell it if you want blend shapes to be loaded into your ANSKModel. You have 3 options for blend shapes:

  • None - Don't load in blend shapes.
  • All - Load in all blend shapes.
  • Keyworded - Only load in blend shapes that have been given the keyword "ansk" in the name.

This by default is set to not load in blend shapes.

You will also need the effect file that the model will be rendering with. This file is supplied by the user as this file can be customized to suit the users needs. The user is provided with the base effect file, which they to place wherever they feel they should place it in the content project.

Now that your content is handled we can move on to the loading of the model.

Loading The Content

Before we write any code, we have to add the using line to our file so that we have access to the libraries contents.

using ModelAnimationLibrary;

When wanting to use a model from the ANSK libraries, you have to load and access it's contents through the class 'ANSKModel'. This is basically a replacement for the class 'Model' and is used in similar ways to it.

So we declare our ANSKModel type:

private ANSKModel _model;

Now we load the model from the content:

_model = new ANSKModel(Content.Load<ANSKModelContent>("CubeTest3"));

_model.ManualInitialise(GraphicsDevice, Content.Load<Effect>("Effects/AnimatableModel"), this);

As you can see, you don't simply load an ANSKModel from the content, but the ANSKModelContent and pass that into the constructor of the ANSKModel. You then need to perform a 'manual initialilise' and pass the graphics device, effect and the Game to it.

Using ANSKModel

At this point, it is recommended you call the following function:

_model.MeshRenderer.CenterModelToOrigin();

This moves the vertices so that the model's midpoint lays on it's local origin. This will make rotation and scaling much easier and less confusing to perform.

During the update you will need to call the function:

_model.Update(GameTime gameTime, Matrix transform);

This will update animations that are running. The gametime parameter is the passed gametime, however the matrix is a movement matrix which you wish the ANSKModel to abide by.

During the draw you will need to call the function:

_model.Draw(GameTime gameTime, Matrix transform, Matrix view, Matrix projection);

This will draw the model. The first 2 parameters are the same as the Update parameters, while the third parameter is the view matrix of the camera, and the last parameter is the projection matrix of the camera.

This is basically all that you need to get your model working in your project.

Clone this wiki locally