Jump to content
  • Advertisement
Sign in to follow this  
intrest86

X File Animations Seperate from Models?

This topic is 4829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone, I'm getting around to adding animated meshes to my game, but I was hoping someone would be able to answer these questions for me before I do something stupid. The general goal is that all characters are going to use the same set of frames in their mesh hierarchy, and then the animations will be generate seperately and then applied to whichever model needs that animation in game. This can't be done to each and every model ahead of time because animations have to be dynamically loaded at runtime, and it seems like a waste of memory. I was planning on using X files. All of the actual models would be saved to seperate files without any animations. Is it then possible to save animations in seperate X files, load them, and then register them with the animation controllers? Is there anything I need to watch out for when creating the models so that they can all have the same animations applied ot them? Or should I just be using a different format in the first place? Thanks for any info!

Share this post


Link to post
Share on other sites
Advertisement
I think you'll be fine using X files. I'm not completely familiar with this area, but I would think it would work something like this (anyone feel free to correct me).

The type of animation data you need should contain data for bone movement, by name. i.e. Arm rotates 1 degree each frame or something. In this case, your X models will have to be framed, i.e. the arm mesh will be a frame and be named Arm.

You can certainly use the X file loading utilities, but it will take some creativity. You'll need to use LoadMeshFromHierarchyX to import the framed data. I think you'll have a default animation, or it would be easiest for that. The function will return your AnimationController.

You can then use the controller to register new animation sets ID3DXAnimationSet. You can either derive your own animation set from ID3DXAnimationSet or you can use the existing ones:
ID3DXCompressedAnimationSet or ID3DXKeyframedAnimationSet.

My guess is you'll want the ID3DXKeyframedAnimationSet. Use D3DXCreateKeyframedAnimationSet to create it. This will only get you started. You'll need to fill the Animation Set with data using the SetRotationKey, SetScaleKey, and SetTranslationKey routines. This part will really be up to you. You'll have to get the Key data from the animation files. You could write your own X File importer for specialized animation data (or there may already exist such a thing), then take the data and transfer it to animation sets. Or you could just store it in a simple text file format and write your own conversion routines.

Sorry if this is not complete or any part is wrong, but it will get you thinking of the ways to approach it I hope.

EDIT: Just looked at the SetRotationKey parameters, and the parameters don't mention the name of the frame that will be rotated (i.e. Arm), so I'm not sure how that will work. You may have to create an animation set for each bone and have each animation within the animation set represent the actual animations (run, walk, etc).

Chris

Share this post


Link to post
Share on other sites
If you've ever looked at a text X file you'll see that the AnimationSet data is at the end.
Maybe you could get rid of the mesh data then see what LoadMeshHierarchy from X does with no mesh data. Hopefully it would return the animation set with no mesh which you can add using Supernat02's method else just have a horrendous error :S

The DirectX Mesh Viewer utility comes with source code and that adds animation. However, it's terribly complicated. Crack vertex declarations?!

Share this post


Link to post
Share on other sites
Thanks guys,

After a bit of thought (and your help) I realized this wasn't as insurmountable as I worried it looked. I've already gone off on a lot of tangents durring this project and definately wasn't looking forward to writing a new mesh file format or importer just to load animations. So I think I have a solution:

1) Create the animations in whatever the package of choice is (looks like Blender). Use anyone of the messhes to do it, doesn't matter which. Export as a .X file.

2) Load the mesh into a utility program, with its animations. Then, using the KeyframeAnimationSet, rip out all of the animation data (name, rotate keys, translation keys, and scale keys) and dump them to some highly simplistic file format. Maybe throw in a little compression there ro write to binary instead of text to help save on size, etc.

3) To load the animations just open up the info dump and use KeyframedAnimationSet.RegisterAnimationKeys() to dump all of that data directly back in to recreate the original animation.


Hopefully by that point it is useable again. As already mentioned, this data doesn;t actually reference the Frames anywhere, which is slightly worrisome, but I don't see any reference anywhere in the animationController's to frames. If this is true, then theoretically this setup would work.

Share this post


Link to post
Share on other sites
Well, looks like I may have jumped the gun. After reading a spec for X files to try to understand what was going on a little better they very obviously store Fram information. I understand now that an AnimationSet is really what I was thinking of when I thought "Animation". Each animation inside the set is really just the animation for each part of the model. But as far as I can tell, that data is not stored anywhere in the AnimationSet's, and the AnimationController's only take AnimationSets, no extra data.

I'm still going ot try dumping the animation data to a file and reloading it, but if anyone has insight please share. Thanks!

Share this post


Link to post
Share on other sites
Wait a min! If you're doing this as a preprocessing step, as long as you don't have 100s of animations, you might as well just use the DirectX Mesh Viewer utility to do it!

I'm afraid I don't know what you mean in your second post, but to show you what I have in my model (it works) I've saved it as text as copied out this for you:

AnimationSet EyesRoll {


Animation {


AnimationKey {
0;
1;
5000;4;1.000000,0.000000,0.000000,0.000000;;;
}

AnimationKey {
2;
1;
5000;3;0.000000,-0.011111,0.006347;;;
}
{ Root }
}

Animation {


AnimationKey {
0;
1;
5000;4;1.000000,0.000000,0.000000,0.000000;;;
}

AnimationKey {
2;
1;
5000;3;-0.461488,1.141649,1.718176;;;
}
{ BrowTR }
}
generally, just more Animation[s]


Hope that helps...
Andrew

Share this post


Link to post
Share on other sites
Oh - and if you are preprocessing them and you don't want to use the DX Mesh Viewer utility, you could always make sure all your models are saved to text them write a simple program to copy the AnimationSet {} groups out and stick them at the end of your main file.

Share this post


Link to post
Share on other sites
The key is making sure that every frame (every joint) in every mesh you want to share animations between is the same. The animations use references to the frames to determine which joints/verts are being transformed.
You have to have at least one file that has the whole hierarchy and all the animation data stored in it... then your models .X files can just have Frame and Mesh info. I have never used the DirectX Animation Controllers before but what you must do is load whatever mesh... then when you are loading animation data instead of loading it from the Meshes file you load it from the file with all the animation data.... and you can do it this way for every mesh.

I am not at all sure this will actually work... but I was considering implimenting this myself since it makes life alot easier for modelling/animation but I never got around to it.... this is how I was gonna do it though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!