Accepted: IK support in Ogre's skeletal animation

Threads related to Google Summer of Code
User avatar
jarek108
Halfling
Posts: 72
Joined: Mon Mar 05, 2007 1:11 am

Accepted: IK support in Ogre's skeletal animation

Post by jarek108 »

ok. time to leave underground.
Alexander wrote:IK would be a great addition.
jacmoe wrote:@jarek108:
Looking forward to this summer! Your project is definately most wanted!
Kudos to you for your excellent proposal! :)
Praetor wrote:
I want to play with that so bad!

@jarek your project is certainly a popular one, and with good reason. Good luck for the summer.
yaeh, i know that some of you guys are waiting long for any news about the system. i think i should prove that i`m indeed working on it.

here is some stuff i put on wiki:
http://www.ogre3d.org/wiki/index.php/SoC2007_Animation

this is some summary of what i came up with uptill now. the vision is getting clear in my mind so now it is time to check if this is going anyway you as community want it to go.


i have some remarks on the wiki stuff:
1. this is not clean nor consistent. i tried to put things together so that when you read you get the picture of what is where in the system but some parts were written in a different time than others and some things are called differently in some places than in others etc., please focus on general approach. details will be smoothed and changed significantly. i thought that it is better to give you this now and later make it nicer than to make people wait even longer

2. please comment on what would you change in system structure to manage it general and easy to use.

3. middle and high level were designed to support different types of interfaces and method sets for programmer to use them. one of the most things i hope for most is that you will share with me HOW you want to use the system. use cases. interface proposals. all very wellcome. this is even more true for the high level user interface since i only put some ideas not even a real use case.

4. ask about stuff that is not clear. will try to explain and change wiki to be clearer.


Hope you will like it. Please feel free to comment.
User avatar
lf3thn4d
Orc
Posts: 478
Joined: Mon Apr 10, 2006 9:12 pm
x 12

Post by lf3thn4d »

Cool. Nice stuff. One thing though. Why animation tree? I can't see the connection between animation states and a tree. I would personally go for a state machine based system IMHO. Tree seems kinda hard to imagine.
User avatar
SpannerMan
Gold Sponsor
Gold Sponsor
Posts: 446
Joined: Fri May 02, 2003 10:05 am
Location: UK
Contact:

Post by SpannerMan »

Im very interested in this project, best of luck to you jarek108 :)
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

lf3thn4d wrote:Cool. Nice stuff. One thing though. Why animation tree? I can't see the connection between animation states and a tree. I would personally go for a state machine based system IMHO. Tree seems kinda hard to imagine.
It's based on an article featured at Gamasutra.

I'll try to give you an example so you can envision it ;) Imagine your character is running slowly (faster than walking, slower than sprinting) forward and strafing right (like 45 degrees or something). Okay, you have a main blending (root of the animation tree) that makes a blend between running and walking. Now, both running and walking are the result of a blend between 4 animations each: running/walking forward, backward, left and right.
In this case, the result would look similar to Blend (Run (0.5, 0, 0, 0.5), Walk (0.5, 0, 0, 0.5), 0.5)
Image
User avatar
jarek108
Halfling
Posts: 72
Joined: Mon Mar 05, 2007 1:11 am

Post by jarek108 »

Very true kencho, it is like that, thx for help.

There are also some benefits that are perhaps not so clear to begin with.

1. Logical structure representing animation can be archived. One Subtree will take care of movement other of actions like shooting/grabbig. One subtree will take care of running/walking other of sneaking.

This will let you attach some variable like: speed or degree of sneaking and by that produce nice, powerful and general way of handling the animation parameters much nicer than manually changing the weights of all sub animations in the character.

2. Tree will not only be used to calculate weights but also will direct the order in witch procedural modifications to the animations will occur(i think this one of the things tuan kuranes or kencho pointed out they want to have in the system). So you can have IK animation in a leaf and then blend it with other animations, or you can have some IK solver inside the tree to take some result of previous blending and change the result by IK operation. Also you can have physics engine in a top tree level to use it to apply some forces to the end result of all the blending. This can all be done by using the tree. This was not the part of the gamasutra stuff but seems natural upgrade and a nice feature right?

3. State machine can go together with tree. I DO want some state machine at the top of the tree. It will not be as general. Not so powerful. But may cause using the system to be faster and nicer for some(most?) solutions. My idea is that it will operate on the tree in some predefined(and fully modifiable ofcourse) way to provide even natural control over animations.

Actually this is where i could use most help.
How do you want to control your characters?
How do you want to define states and transitions and the way they influence animation?

I have some ideas but i want the future users, who have mostly more exp. than me in using animations in games etc. to say something about this level of the system.If you could just imagine use case and present how your perfect animation controller work this would be great.

Thx.
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

The more generic, the best is the moto in my opinion. Ogre is pretty generic, and that allows Ogre users to develop a really wide variety of applications/games. The same philosophy should be applied to everything Ogre-related, in terms of core functions.

This isn't intended to be an add-on (is it??) but part of the core functionality itself. Thus, you can't restrict the potential users. Try to make it abstract enough so that it's easy to extend and adapt to one's particular needs. Some people will want a simple states machine, some will want complex predicate-driven decissions...
Image
User avatar
lf3thn4d
Orc
Posts: 478
Joined: Mon Apr 10, 2006 9:12 pm
x 12

Post by lf3thn4d »

Ahh.. ok. If i understood that correctly, the tree is meant for more fine control blending. So it actually sits as the blender for an animation state machine. Graphs pointing to trees. :-) Sounds good :-)
User avatar
DanMD
Gnoblar
Posts: 8
Joined: Fri May 18, 2007 12:31 am
Location: Lisbon or London
Contact:

Post by DanMD »

jarek108 wrote: Actually this is where i could use most help.
How do you want to control your characters?
How do you want to define states and transitions and the way they influence animation?

I have some ideas but i want the future users, who have mostly more exp. than me in using animations in games etc. to say something about this level of the system.If you could just imagine use case and present how your perfect animation controller work this would be great.

Thx.
Ok to give you a use case for my game in particular ParaParaBola ( some info here: http://features.moddb.com/282/paraparabola-interview/ website and svn repository coming in the next weeks), what i would like to have is a physics based animation (for character collision), and a blended mode animation for character transitions (the character is running backwards, input makes character move forwards the animation is blended to make the movement LOOK as realistic as possible).

Use case:

Character A (avatar/character that i control via keyboard/input ) is running backwards, and collides with character B (referee/player), Character A falls into the ground using a Fall controller (as described on mmandel thesis), input forward makes the character blend the getting up animation with the moving forward animation...

pretty much similar to what is illustrated in this video, except the roll-over part, that should be "optional" using mass as a constrain probably: http://www.mmandel.com/movies/masters/f ... 2_edit.avi

Other such events as tackles, air collision, etc... if this is useful i can try to emulate all this in 3ds and send you videos of what i mean, will take some time though because i am still trying to figure out the best model to use as a character, how many joints, etc... also going to use NaturalMotion endorphin to emulate these, and since NM euphoria is probably very $$ to license, your project is my best hope to have a run-time library to do this kind of stuff.

So you have a partner here :)

Also squash and stretch operations would be nice to have!

I particularly have no need for more advanced controllers like equilibrium, or advanced AI controllers like searching the ground with your hands, etc...).

About the animations, i have a set of animation for each character, stuff like walk, run, run-backwards, jump, tackle, etc...

If the player collides with other player i want to have a physics based collision, something like a fall controller to make the collision always look different (simulation) and then i want to blend the (simulation, with one element of the set of animations). If you need me to make it clearer or illustrate it better let me know :)

I also have the need for a jump controller (interaction with dynamic terrain - trampoline effect - and air collisions).

I will try to illustrate this with some video use cases.
User avatar
jarek108
Halfling
Posts: 72
Joined: Mon Mar 05, 2007 1:11 am

Post by jarek108 »

thanks for that. i was beginning to have doubts if someone will write something here.
ok. so for your use case with A and B characters.

1. running direction transitions would be controlled by changing value of a parameter in the tree.

your would do something like that:
a.varGoTo("RunDirection", x);//x - the angle you want to run to

the animation tree would take care of variable value transition in time(with default speed or the one you set up before). the node controlling walking directions would respond to the changing values assigning weights to animations.

this node could behave in different ways depending what you expect. it could have just forward/backward animations to blend. this could work in going from left to front running but would not look well in backward/forward(there is a phase of stand like that is just not half running backward half forward, it is new quality) you could assign
1 forward
0 transition
-1 backward
but you would have to provide the transition behaviour.
you could also do:

a.varGoTo("speed", 0);
...//character stopped
a.varGoTo("RunDirection", x)
a.varGoTo("speed", 1);

this could be the best choice because you do not have to create new animation - transition, and the character will do what you expect.

summary:
for continuous changes like: running back than back+right, right, front+right and front finally, this can be achieved with one varGoTo().

for drastic changes like backward/forward there is just new quality in between and a simple system like the one i create cannot provide you with a new animation here just by blending. you would need advanced bio mechanical simulation for that. ] or a specific ik.

if however someone will create IK controller that takes direction, speed and perhaps speed change to produce general running effect this can be put as a node in a system(i hope the system will grow like that).


2. for the physics:
similar as with IK running controller - the system will support putting physics modifiers at any level to alter the animations but do not expect that i will provide it during GSoC. it is outside of the scope, the main blending system it self is a challenge for that time. what you propose is a natural continuation of the project but I have to be realistic about what i can do in a time given.

once again:
the system is very simple compared to commercial ones you mention, it will be mostly around blending at the beginning, the same time it will be a perfect frame for putting physics and goal oriented IK inside to naturally blend it all to achieve advanced effects like realistic (air?)collisions or natural fall. Hope it is not disappointing.

thanks for your voice.
did you see my ninja example http://www.ogre3d.org/wiki/index.php/So ... ddle_level.? artist`s animations. it would be nice if you make some suggestions on the interface you would like to have for that.
User avatar
jarek108
Halfling
Posts: 72
Joined: Mon Mar 05, 2007 1:11 am

Post by jarek108 »

also:
your animations will help me a lot!!
are you willing to use them to prepare some test & examples when some parts of the system are ready?

this testing would be a great community help.
User avatar
DanMD
Gnoblar
Posts: 8
Joined: Fri May 18, 2007 12:31 am
Location: Lisbon or London
Contact:

Post by DanMD »

Jaroslaw,

Glad i could provide something useful, i will work on some detailed use cases.

Also i don't expect for you to create a full blown system, similar to euphoria, but i hope you can do most of the high-level design work, so that we can have an extensible framework into place, i am off course very much interested in implementing solutions to my problems, and helping you as much as i can, basically help you will in the end help my project ;)

Thanks for the info, it certainly helps we get the system into scope. ATM i am trying to define the problem domain, and be very specific searching for solutions to my particular problem, the approaches to this problem are numerous, and i am considering them all, but now i will try to workaround your framework, see if there are any obvious shortcomings in the design so that we can fix them early on the process.
jarek108 wrote:also:
your animations will help me a lot!!
are you willing to use them to prepare some test & examples when some parts of the system are ready?

this testing would be a great community help.
Give me a couple of weeks, i will do some animations and create some pseudo code illustrating how i would like the framework to work (like your ninja example, that i had no read), i am going over your page trying to absorb your proposed syntax... but i am not a big fan of the varGoTo function call ( i hope you don't mind if i use a diff syntax in my code).

BTW, you can consider PPB your playground application, i will test everything you can throw out at me, any help i can give it's yours, this is a community after all, and if you look at it, it's $4500 that i am saving in hired programming ;)
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Post by KungFooMasta »

Hey jarek108,

I just wanted to post to say that I'm watching this thread, so don't lose any motivation! :wink:

I would try to post some scenarios and help you out, but I'm not far enough in my own project to work with animations on any meaningful level. Honestly, I started reading into your topic, and my eyes starting glazing over, haha. Maybe it's too technical for me. :P

One thing I would suggest is trying to make the wiki example of the ninja using animations a little more reader friendly. I was pretty lost, and the function names, like varGoTo, as DanMD pointed out, are not very intuitive. I know that programmers are the ones who will be using the code, but the easier you make it to analyze and digest, the more people can throw in their input.

Anyhow, I'm only making helpful suggestions. Animation is a very important topic, so I hope your project progresses well!

KungFooMasta
User avatar
Alexander
Gremlin
Posts: 175
Joined: Sat Aug 05, 2006 3:55 am

Post by Alexander »

Keep up the good work!
User avatar
jarek108
Halfling
Posts: 72
Joined: Mon Mar 05, 2007 1:11 am

Post by jarek108 »

KungFooMasta wrote:Hey jarek108,

I just wanted to post to say that I'm watching this thread, so don't lose any motivation! :wink:

I would try to post some scenarios and help you out, but I'm not far enough in my own project to work with animations on any meaningful level. Honestly, I started reading into your topic, and my eyes starting glazing over, haha. Maybe it's too technical for me. :P

One thing I would suggest is trying to make the wiki example of the ninja using animations a little more reader friendly. I was pretty lost, and the function names, like varGoTo, as DanMD pointed out, are not very intuitive. I know that programmers are the ones who will be using the code, but the easier you make it to analyze and digest, the more people can throw in their input.

Anyhow, I'm only making helpful suggestions. Animation is a very important topic, so I hope your project progresses well!

KungFooMasta
KungFooMasta, i think you are 100% right. I will try to make wiki stuff less technical and more clear and intuitive, i started thinking that this may be something that stops people from sharing. I cannot expect that many people will go through that just to post something I guess. I make this my priority before GSoC starts.

Thanks for kind remarks it is wind in my sails... or however you say that;).
User avatar
jarek108
Halfling
Posts: 72
Joined: Mon Mar 05, 2007 1:11 am

Post by jarek108 »

ok, i need practical advice.

I want to access the skeleton joint rotation quaternions in animation in a given time held by some animationstate variable. what is the easiest way?
User avatar
DanMD
Gnoblar
Posts: 8
Joined: Fri May 18, 2007 12:31 am
Location: Lisbon or London
Contact:

Post by DanMD »

jarek108 wrote:ok, i need practical advice.

I want to access the skeleton joint rotation quaternions in animation in a given time held by some animationstate variable. what is the easiest way?
Hum, don't really have a practical answer because i never tried to do that, i would need to see the documentation for the supported format(s) for skeleton animation, how is it implemented... trying to find out if there is any documentation if not i will go to the source and try to figure it out :p hope one of the mentors can give a help.

I am guessing you need to use skeletonInstance _getBoneMatrices() and then extractQuaternion( ) ?

BTW, so that we are all on the same page, is there any physics engine that you plan to support in (i read that you will try to keep it physics engine agnostic, but i think it would be a good idea that we tested with the same "parts"), i am planing on using nxOgre, but if you have more experience with other wrapper library i am willing to change it.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Reading the animations themselves (which are just applied by AnimationState) is best done by getting the Skeleton, then grabbing the Animation, NodeAnimationTrack and TransformKeyframe from that.

If you actually want information on the currently applied state, then grab the skeleton from the Entity and look at the current bone state as suggested above. Be aware that animation is applied only once a frame though, depending on when you retrieve the bone you might need to call Enity::_updateAnimation.
User avatar
jarek108
Halfling
Posts: 72
Joined: Mon Mar 05, 2007 1:11 am

Post by jarek108 »

sinbad wrote:Reading the animations themselves (which are just applied by AnimationState) is best done by getting the Skeleton, then grabbing the Animation, NodeAnimationTrack and TransformKeyframe from that.

If you actually want information on the currently applied state, then grab the skeleton from the Entity and look at the current bone state as suggested above. Be aware that animation is applied only once a frame though, depending on when you retrieve the bone you might need to call Enity::_updateAnimation.
after reading some ogre code and api i suspected something like that.
so far i tried things like:

Skeleton *skel = mEntity->getSkeleton();
Ogre::Animation *a = skel->getAnimation("Walk"); //animation 4 = walking
TimeIndex timeIndex = a->_getTimeIndex(time);
Ogre::Animation::NodeTrackList l = a->_getNodeTrackList();
Ogre::Animation::NodeTrackList::const_iterator i;

int j=0;
for (i = l.begin(); i != l.end(); ++i)
{

TransformKeyFrame kf(i->second, timeIndex.getTimePos());

r[j++] = kf.getRotation()
};


but i think there is some mistakes in that. when i compared r[x] values with:

SkeletonInstance* pSkeleton = mEntity->getSkeleton();
pSkeleton->getBone("Jointx")->_getDerivedOrientation();

they are not the same. can you propose sth?
User avatar
jarek108
Halfling
Posts: 72
Joined: Mon Mar 05, 2007 1:11 am

Post by jarek108 »

i`m working on the wiki page now. try to make it more digestible. appreciate any remarks about what was not so clear/nice.

will try to replace the varGoTo(). what do you propose? the goal it to enable user to call sth to make variable go to certain value over time. system will take care of that transition. this will be used for animation control variables like: speed etc. that will change gradualy to what user wants them to be. i thought that: varGoTo("speed", 1) will be clear, but any other way is also ok. propositions? Dan MD? anyone?
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Post by KungFooMasta »

I guess it would be important to know what properties can be set. From your example, it seems the properties are animation based.

My suggestion would be "integrateAnimationProperty(...)".

I will read your wiki page when I get a chance and post my comments. Been really busy lately. :wink:

KungFooMasta
User avatar
jarek108
Halfling
Posts: 72
Joined: Mon Mar 05, 2007 1:11 am

Post by jarek108 »

added new stuff to wiki to make introdution "softer". will expand it soon.

i do some experiments to take a controll over creating animation in the fly. i would like to do that on a level of node tracks like i posted before, but for now i do not now how so i made that to make idle + walk for 18 joint robot:

Skeleton *skel = mEntity->getSkeleton();
Skeleton::BoneIterator bi = skel->getBoneIterator();
for (int j = 0; j < 9; j++)
{

r[j] = bi.peekNext()->_getDerivedOrientation();

bi.moveNext();
};

skel = mEntity2->getSkeleton();
bi = skel->getBoneIterator();
for (int j = 0; j < 9; j++){bi.moveNext();};
for (int j = 9; j < 18; j++)
{

r[j] = bi.peekNext()->_getDerivedOrientation();

bi.moveNext();
};

skel = mEntity3->getSkeleton();
bi = skel->getBoneIterator();
for (int j = 0; j < 18; j++)
{
bi.peekNext()->setManuallyControlled(true);
bi.peekNext()->setOrientation(r[j]);

bi.moveNext();
};


there are 3 robots as 3 entities. i read lower body from 1(walk), upper from 2(idle) and put it into 3.

this works. almost. for some strange reason there is some annoing difference between the original and a copy(like swinging arms to much etc...). this stays when i copy entire animation from one source. any idea what is wrong?

please also propose code that can be used to stay on a level of nodetracks instead of skeletons. good night.
User avatar
Game_Ender
Ogre Magi
Posts: 1269
Joined: Wed May 25, 2005 2:31 am
Location: Rockville, MD, USA

Post by Game_Ender »

Code: Select all

 tags?
User avatar
jarek108
Halfling
Posts: 72
Joined: Mon Mar 05, 2007 1:11 am

Post by jarek108 »

was wondering how it is done ;)

Code: Select all

		Skeleton *skel = mEntity->getSkeleton();
		Skeleton::BoneIterator bi = skel->getBoneIterator();
		for (int j = 0; j < 18; j++)
		{
	
			r[j] = bi.peekNext()->_getDerivedOrientation();

			bi.moveNext();
		};

		skel = mEntity2->getSkeleton();
		bi = skel->getBoneIterator();
		for (int j = 0; j < 9; j++){bi.moveNext();};
		for (int j = 9; j < 18; j++)
		{
	
			r[j] = bi.peekNext()->_getDerivedOrientation();

			bi.moveNext();
		};

		skel = mEntity3->getSkeleton();
		bi = skel->getBoneIterator();
		for (int j = 0; j < 18; j++)
		{
			bi.peekNext()->setManuallyControlled(true);
			bi.peekNext()->setOrientation(r[j]);
			
			bi.moveNext();
		};
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

@jarek108: imho, r[x] values are local Orientation, rather than derived ones, so you have to compare them with "Bone->getOrientation();". (you'll have to go in Sinbad direction, handling multiple skeleton is the wrong way.)

About orientation problem (your code does not seems to sum them), but anyway you'll have to read NodeAnimationTrack::applyToNode() code to fully see how to apply multiples Transform on a nodes sequentially.

Check how AnimState weighting works in order to enable/disable part of animation (read Skeleton::setAnimationState() for details on reducing/simplifying animation applied to a node using weightsfactor.)

Well be sure to readon all those Ogre::Skeleton code to fully understand how ogre implements skeletal animation joint blending (including how it optimize and handle special cases). (try setting some breakpoint in its metthod while playing with actual Wiki AnimationBlender)
User avatar
DanMD
Gnoblar
Posts: 8
Joined: Fri May 18, 2007 12:31 am
Location: Lisbon or London
Contact:

Post by DanMD »

jarek108 wrote:i`m working on the wiki page now. try to make it more digestible. appreciate any remarks about what was not so clear/nice.

will try to replace the varGoTo(). what do you propose? the goal it to enable user to call sth to make variable go to certain value over time. system will take care of that transition. this will be used for animation control variables like: speed etc. that will change gradualy to what user wants them to be. i thought that: varGoTo("speed", 1) will be clear, but any other way is also ok. propositions? Dan MD? anyone?
I am working on the animations and pseudo code, but i have been using this syntax on my code blendParameter("speed", 1)

so following your ninja code we would have:

Code: Select all

a.registerParameter("speed", n.speed);
a.setParameter("crouch", 2);
a.blendParameter("speed", 1);

Also thought of using blendPropriety(...), are there any guidelines and naming conventions for OGRE API creation? If there are, it is best to follow them.

I have been away from OGRE for over 3 years, so i am really studying the system as we go, please forgive some of my "dumb" questions that i will make along the way, but it would be good to know what constitutes a variable, a parameter, and a propriety in OGRE terminology :)

The rational for the above syntax was that currently the AnimationBlender uses blend(), and since this is a revision of AnimationBlender we will have more control, then blend() and blendPropriety() is easy to use...

If we want to blend whole animations (like the previous AnimationBlender did then use blend(...) if you want to simply adjust a parameter then blendParameter(..) is used, this way you don't break code, and it fells more like an extension than a replacement... does this make sense to you?
KungFooMasta wrote:I guess it would be important to know what properties can be set. From your example, it seems the properties are animation based.

My suggestion would be "integrateAnimationProperty(...)".

I will read your wiki page when I get a chance and post my comments. Been really busy lately. Wink

KungFooMasta
yeah, integrateAnimationPropriety(...) or integratePropriety(...) it's shorter, easier to read IMHO, but intellisense helps allot on that front.

I think "Animation" here is a bit irrelevant, since we will only deal with Animation proprieties/parameters (right?). But i still think blendParameter(...) fits better

Anyway, I should have the animations and code by next Friday.

PS: Found this code snippet useful to undertand how to control indevidual bones: http://www.ogre3d.org/wiki/index.php/Ma ... llingBones :)
Locked