A few animation-related questions

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
Hrenli
Halfling
Posts: 73
Joined: Tue Jun 14, 2016 12:26 pm
x 19

A few animation-related questions

Post by Hrenli »

Hi,

It's not really 2.0+ exclusive stuff, but that's the version I use and some of the questions are threading-specific (and here 2.0+ differs from the predecessors), so I decided to put it all here.

So, till now I was using animations "as is" (i.e. I juts move scene nodes and run/blend skeletal animations for items) and everything works like a charm, thanks for the awesome Ogre engine. But recently I started to play with the idea of fiddling with animations in the code (sort of IK, accurate collisions for animated characters, that kind of silly stuff) and a few things still make me scratching my head. Here they are:

1. Do I understand it right that during frame update I can get only already calculated (i.e from the previous frame) bone position? I've tried to call SkeletonAnimation::addTime() followed by SkeletonInstance::update() but it seems to affect only bone orientations, positions are still the same (I guess because the results of all the bones chain transforms is not calculated yet). Have to admit I've experimented on that regard only with the new animation system, not with the old one. What I would like to do is to get bones from the animation as they should be in the ongoing frame and change some of the positions if necessary. Am I doing it wrong? Is there a place in the frame lifetime where the animated skeletons are updated already but it's not too late to move some of the bones? Or is there a way to say to a skeleton "just fucking calculate it already without waiting"? :)

2. I am also fiddling both with single-thread and multi-thread scenarios. Ideally I would like character animation to be processed by the logic thread, as I have all the physics/collisions there. What are my options to get animated bone positions for the given logic frame? As I see it:
2a. Animate a separate "ghost" skeleton in the graphics thread, which is calculated for the time of the "next logic frame after the nearest one" and either send it to logic as a skeleton pointer directly (seems to be thread-safe enough?) or actual bone transforms to the logic thread. Should work and even give me actual (not from the past) positions, but the whole setup feels overcomplicated a bit.
2b. Implement my own skeleton animation calculation in the logic thread. Should be double but feels wasteful as Ogre already have not one but two sets of code which deals with it already.
2c. If there was a way to run a separate Ogre instance with NULL render system in the physics thread or if it was possible to just run animations for a single skeleton without render system/scene manager etc - I would just have Ogre animations separately in the logic thread. But it's not possible atm, am I right?
2d. Anything else?

And, generally, if some of you guys implemented IK which is based on skeletal animations, how you deal with the problems above? I still feel a bit stupid about it, like I am missing something very simple but elusive...

Thanks in advance for any info and sorry for bother if it really is something stupid I am missing. :)
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: A few animation-related questions

Post by al2950 »

Just come across your post. I am reaching similar issues. Did you find any solutions?

Ogre is really not built, yet, to allow easy separation of rendering from logic. I think Ogre itself should do the separation and things like updating scene graph and animations stay in the logic thread and ogre deals with the synchronisation.

In the mean time, separating out things like scene graph, material updates, particle updates etc are a pain but not impossible. However as you said animations are proving difficult because the animations can affect physics and then there is things like IK. So the animation updates really need to be done in the logic loop.

I am half tempted to use a third part lib for animations like Ozz-animation
https://github.com/guillaumeblanc/ozz-animation

Anyway anyone else had any issues separating logic and rendering in Ogre, got any solutions!?
Hrenli
Halfling
Posts: 73
Joined: Tue Jun 14, 2016 12:26 pm
x 19

Re: A few animation-related questions

Post by Hrenli »

al2950 wrote: Sat Nov 11, 2017 4:44 pm Just come across your post. I am reaching similar issues. Did you find any solutions?
Not really. For now I am "fine" with skeleton info lagging 1 logic frame behind (I just run animations in graphics thread as they are and only check for collisions, no real IK).

Also there is a slightly connected problem - https://ogre3d.atlassian.net/browse/OGRE-531 with low prio and no clear way to fix it. Considering all things together it seems like we are reaching Ogre's limits in these areas...
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: A few animation-related questions

Post by dark_sylinc »

Hrenli wrote: Sun Nov 12, 2017 3:55 pmNot really. For now I am "fine" with skeleton info lagging 1 logic frame behind (I just run animations in graphics thread as they are and only check for collisions, no real IK).

Also there is a slightly connected problem - https://ogre3d.atlassian.net/browse/OGRE-531 with low prio and no clear way to fix it. Considering all things together it seems like we are reaching Ogre's limits in these areas...
Yup.

I haven't gotten the time to integrate these systems to my own game engine which would point out the pitfalls more obviously.
There's two thing to this:

1. Getting up to date info:
The Skeleton system is prepared for batch update, rather than individual update. Therefore updating a single bone/skeleton -> immediately retrieving the results is not straighforward. Even if possible, it wouldn't be efficient.

The involved calls are:
  • SceneManager::updateAllAnimations (which ends up distributing work in worker threads, actual code is in updateAllAnimationsThread and updateAnimationTransforms)
  • SceneManager::updateAllTagPoints (idem, updateAllTransformsBoneToTagThread then updateAllTransformsTagOnTagThread)
Calling these functions directly will ensure all bones are updated before calling SceneManager::updateSceneGraph. Though it's quite possible updateSceneGraph will then perform the update again, which would result in redundant work. Perhaps flags could be introduced as arguments to the function to tell Ogre what not to update and assume it was updated externally.

2. Logic vs Graphics separation. In the case of skeletal animations, having a deterministic simulation vs graphics simulation means having two skeletons. There's no way around that (for performance reasons I'd suggest your engine should distinguish between "needs skeleton for physics simulation" and "skeleton is just a graphics pretty thing, do not simulate, just animate").
To that exent, your engine should do what SceneManager does for creating, destroying and updating skeletons.
That means having your own SkeletonAnimManager to keep logic/physics copy. Admitedly Ogre could be criticized in this regard in not providing these functions for you so you don't have to duplicate its code.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: A few animation-related questions

Post by al2950 »

Thanks for your replies. I have already started pulling the Ogre skeleton code out for use in my logic thread, so its good to know that is a sensible direction for now.

I have started another thread here about the possible future for splitting logic and rendering. I honestly believe its a rendering engine's job and should be done at a lower level for both ease and memory use. Anyway I would appreciate any thoughts/opinions you have :D
Hrenli
Halfling
Posts: 73
Joined: Tue Jun 14, 2016 12:26 pm
x 19

Re: A few animation-related questions

Post by Hrenli »

al2950 wrote: Mon Nov 13, 2017 5:26 pm I have already started pulling the Ogre skeleton code out for use in my logic thread
How did it go? Any hints for someone who is about to approach the same task? :)
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: A few animation-related questions

Post by al2950 »

Not really. I realised I could simplify my use case, and so in the end only needed to sync TagPoints. I will at some point need to do something more complicated, not I will worry about that when I really need to!
Post Reply