Archived

This topic is now archived and is closed to further replies.

apanjocko

animating .x WITHOUT bones

Recommended Posts

everywhere i search about animating meshes in directx (even this forum) it''s always about bones. if the question is not about bones, the answer is. i have a regular simple animation with keyframes in 3ds and have exported it to a .x file. how do you animate it using directx9? where can i read about it? thanks!

Share this post


Link to post
Share on other sites
The only keyframe animation tutorial I beleive I have seen is the dolphin demo from the SDK. You might wanna check that out.

Isn't a boneless animation the same as an animation with 1 bone? EDIT: No, now that I think about it, it's not the same.

[edited by - SiliconMunky on October 23, 2003 7:25:42 PM]

Share this post


Link to post
Share on other sites
you don''t have to add a bone in 3ds to make an animation.
the dolphin example uses vertex shaders to tween between 3 .x files that is loded separately. that is really really complicatied for me right now. is''t there an example somewhere how to animate .x files like .md2 files? a whole separate set of vertices for every part of the animation... and NO tweening i''d like that...

Share this post


Link to post
Share on other sites
How would you smoothly display a key framed animation without tweening?


EDIT: I suppose you could display teh first mesh for 20 frames and then the next mesh for 20 frames and so on until you loop back to the first mesh again. But that wouldn't be all that smooth.

[edited by - SiliconMunky on October 23, 2003 6:59:56 PM]

Share this post


Link to post
Share on other sites
as an amateur that don''t know anything about vertex shaders, except that they are complicated, would simply create more frames. that didn''t cross your mind?? now i see why there are som little information about it. everyone wants to make it extremely complicated (bones, tweening etc)

Share this post


Link to post
Share on other sites
Actually, creating lots of frames did cross my mind, that''s the way I was going to implement animations in my code about 4 months ago. But unfortunatly there is no smooth and decent way of implementing animations without bones or tweening. So I decided to use bones.

I suppose you could make it smooth by using a tonne of key frames, and just switch from one to another with no tweening. The problem with that is that it will take a lot of memory to store all that mesh information.

Share this post


Link to post
Share on other sites
aaah,
i suddenly see the light
now i get why there is so little information about that...

so, more or less, you use vertex shaders to animate stuff like dolphins, wheels and such, and bones for characters?

Share this post


Link to post
Share on other sites
You don''t have to have every single frame for that...It''s called "keyframe" animation for a reason. The idea is to present enough frames so that each motion is kinda believeable....i.e. Major parts of the movement, places where something changes direction, etc. Each animation, run, jump, crouch, or whatever, represents a change from one pose to another, usually standing.

You should only need around 7-10 keyframes to make a believable animation. Instead of instantly displaying the next keyframe, you create a function that produces a *transition* from one keyframe to the next. Basically that just (incrementally) alters the vertexes to match the next keyframe. You can easily adjust your framerate by changing how many frames are in-between each keyframe. Get my drift?


An excellent book over this is "3D Character Animation", "Tips and Tricks of the 3D programming Gurus", And almost any of LaMothe''s Direct3D Books. You can prolly read them at your local Borders bookstore by just spending some time there.

Share this post


Link to post
Share on other sites
You don''t have to use bones - you can use Transform Animation; that is rotation, translation and scaling. These are all done by modifying an object''s Local to World matrix, the matrix that positions the object into the 3D space.

If you are using Direct3D, take a look at the D3DXVec3Lerp function. It takes two vectors and interpolates linearly (hence LERP, spherical interpolation is SLERP) based on a factor from [0..1].

If, for example, you have a bunch of boxes that are animated moving around (forget rotation for now). If you export the animation at 30 frames a second, but play it back at 60 frames a second, obviously ever second frame of display will be a duplicate of the previous frame''s animation data.

If, instead of simply displaying the object at the given location, you draw it at the half way point between LAST frame''s locatio and NEXT frame''s location, you have ''interpolated'' a position relative to the two frame''s of animation.


D3DXVECTOR3 vecPos0 = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 vecPos1 = D3DXVECTOR3(100.0f, 0.0f, 0.0f);

D3DXVECTOR3 vecResultFrame0, vecResultFrame1, vecResultFrame2;


D3DXVec3Lerp(&vecResultFrame0, &vecPos0, &vecPos1, 0.0f);
// vecResultFrame0 == { 0.0f, 0.0f, 0.0f }

D3DXVec3Lerp(&vecResultFrame1, &vecPos0, &vecPos1, 0.5f);
// vecResultFrame1 == { 50.0f, 0.0f, 0.0f }

D3DXVec3Lerp(&vecResultFrame2, &vecPos0, &vecPos1, 1.0f);
// vecResultFrame2 == { 100.0f, 0.0f, 0.0f }


This is all using the Direct3D helper stuff, but the code is all available on the internet. This can also be extended to rotations. If you have the rotation components stored in a quaternion, you can SLERP between the twho using D3DXQuaternionSlerp(). Take the interpolated position and interpolated rotation, concatenate them into a matrix and you have the new interpolated world matrix for your animated object, based at some value t between frame (n) and frame (n+1).

I have to admit to not knowing how to get this data from .X files, but I hope it can help you a bit.

Hope that''s some food for thought.


Share this post


Link to post
Share on other sites
quote:
Original post by zarthrag
Instead of instantly displaying the next keyframe, you create a function that produces a *transition* from one keyframe to the next. Basically that just (incrementally) alters the vertexes to match the next keyframe. You can easily adjust your framerate by changing how many frames are in-between each keyframe. Get my drift?



yeah, that''s called vertex tweening
apanjocko didn''t want to do that

Share this post


Link to post
Share on other sites
quote:
Original post by Sphet
If you are using Direct3D, take a look at the D3DXVec3Lerp function. It takes two vectors and interpolates linearly (hence LERP, spherical interpolation is SLERP) based on a factor from [0..1].

If, for example, you have a bunch of boxes that are animated moving around (forget rotation for now). If you export the animation at 30 frames a second, but play it back at 60 frames a second, obviously ever second frame of display will be a duplicate of the previous frame''s animation data.


yeah, that''s called vertex tweening
apanjocko didn''t want to do that

Share this post


Link to post
Share on other sites
quote:
Original post by apanjocko
aaah,
i suddenly see the light
now i get why there is so little information about that...

so, more or less, you use vertex shaders to animate stuff like dolphins, wheels and such, and bones for characters?


as Pipo DeClown said, no you don''t have to use vertex shaders. It''s just normally faster to do the vertex manipulation in the hardware with the shader, rather than using up the cpu.

Doing the animation with bones isn''t something different than using vertex shaders. The vertex shader is just used to manipulate the verticies in hardware. Whether you are doing key frames with tweening, or using bones, you still have to manipulate verticies and it is helpful to be able to do this in the hardware with vertex shaders.

I''m fairly new to shaders, so please correct me if i''m wrong.

Share this post


Link to post
Share on other sites
there are occasions where bones are not applicable, i think.

for example, i'm doing this tank animation in 3ds, where the caterpillars (the moving carpet around the wheels of the tank) are moving around... i can't see how bones fit into the picture, but I see how vertex shaders can help.

so i think it may be wrong what silliconmunky said: "Doing the animation with bones isn't something different than using vertex shaders.". please correct me if i'm wrong.

anyway, thanks everyone for the input!

thank you sphet

[edited by - apanjocko on October 25, 2003 5:57:37 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by apanjocko
there are occasions where bones are not applicable, i think.

for example, i''m doing this tank animation in 3ds, where the caterpillars (the moving carpet around the wheels of the tank) are moving around... i can''t see how bones fit into the picture, but I see how vertex shaders can help.

so i think it may be wrong what silliconmunky said: "Doing the animation with bones isn''t something different than using vertex shaders.". please correct me if i''m wrong.

anyway, thanks everyone for the input!

thank you sphet

[edited by - apanjocko on October 25, 2003 5:57:37 AM]



I think you misread what I was trying to say. Vertex shaders are a way to manipulate verticies. Bones and tweening are two different ways of defining how the verticies should be manipulated. So it doesn''t matter if you are using bones or keyframes with tweening, you can still do the vertex manipulations with a vertex shader or not.

Yes, there are definetly situations where bones are not applicable. Bones are normally just used for creatures or characters. But that has nothing to do with vertex shaders.

Share this post


Link to post
Share on other sites