Search Unity

How to apply mocap from fbx to character?

Discussion in 'Animation' started by Arcull, Mar 17, 2015.

  1. Arcull

    Arcull

    Joined:
    Mar 17, 2015
    Posts:
    17
    Hi everyone.

    I've just started to use Unity and I'm trying to create a very simple game for the start. I currently have a rigged character imported from Blender from fbx format. When running the game my character shows up ok, but now I have to give some life to it ;) So I got a trial license for Brekel Pro Body from the author and have already recorded some mocap with Kinect . Brekel outputs both, the bvh and fbx format, but as far as I know Unity knows just fbx. So ok, I can import this fbx to unity, but don't know how to apply the motion from this fbx to my existing character.I can see the imported animation in project explorer and if I select it I can see the preview window in inspector, but when I try to play that preview nothing happens, I think it is because the imported fbx has just motion and no character.....Exploring a little bit more, I found out that Brekel offers a C# script to stream the Kinnect sensor data directly to Unity. I tried to attach that script to my character and I can see the public variables of the class changing values in Inspector window when playing game...so streaming works. However I have no clue how to use this data to make an animation in Unity. I guess I can save this mocap stream to some files, but how the heck do I create an animation with that in Unity and append it to my existing character? Much thanks in advance for your help guys.
     
  2. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    If there is no mesh to display in the file then yes you won't see anything. You can drag and drop your character file on the preview to use a different model for preview. It will only work if both file are set as humanoid rig or if both are set as generic and both rig match.

    I guess you have a file that define your character with his mesh and all the transforms.
    And then probably a few file for all the animation.

    Depending on your setup you can have a few options:

    If both rig doesn't match, each file doesn't share the same transform hierarchy for the skeleton or some name doesn't match. You would need to import both file as humanoid rig. A Humanoid rig allow you to reuse animation from difference skeleton on your character.

    If both rig match, each character skeleton share the same transform hierarchy with the same name for each transform. then you can import your file either as a generic rig or humanoid rig. In both case you should first import your character file and create an avatar for this file and then on your animation file make sure that Avatar definition is set to Copy From Other Avatar and choose the avatar from your character file.

    An Humanoid rig allow you to use more advanced stuff like retargeting, IK and Match target but at a higher cost for performance.

    best regards
     
    Purpleshine84 and theANMATOR2b like this.
  3. Arcull

    Arcull

    Joined:
    Mar 17, 2015
    Posts:
    17
    Thanks Mecanim.Dev, the rigs don't match because, the character was made in MakeHuman, exported/imported as mxh in Blender, edited there and exported as fbx and imported to Unity. While rig that Brekel creates is different. I didn't search for all differences in rigs but can clearly see that number of bones/joins do not match.

    So I tried to select and apply the "Humanoid" type for both fbx-es in inspector window, but afterwards I can not see the preview of animation at right bottom corner, I mean it is still there, but won't play. Is there an option to select "Humanoid" on fbx import action?

    I'm new to Unity and this animation stuff, so I guess I need to learn some basic things... I don't know what Avatar is for instance, or at least what is it for. Is that like a picture one has on forums? I see, avatar is already created for my character, it obviously was created on fbx import. I will try once again, reimport everything and pay more attention to things you stated. Thanks.
     
  4. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Then in this case you should read carefuly this blog post that explain all the detail of the humanoid rig.
    http://blogs.unity3d.com/2014/05/26/mecanim-humanoids/
    Since both rig doesn't match you're only option is to use a humanoid rig. Maybe in blender you could retarget your mocap animation on your rig.

    I know that blender can be hard to setup correctly to export a rig that is supported by mecanim, take a look at some post that @medhue did anwser, he got the secret recipe to make it work perfectly.

    Simply drag and drop your character file asset on the previewer to use another model to preview your animation.

    An avatar in Unity is a special object that contain the rig definition for you character.
    which transform is mapped to which human bone, what are the transform limit, etc ...
     
  5. punkouter2019

    punkouter2019

    Joined:
    Jul 28, 2013
    Posts:
    170
    There any app that does this automatically.. that is create the rig in the exact way unity wants it ? Poser ? iClone? Autodesk character generator ? I am just looking for the simplest workflow to mess around with custom animations in unity
     
  6. medhue

    medhue

    Joined:
    Aug 24, 2014
    Posts:
    176
    I really don't have a secret recipe. For me, I might be a special case, because I sell tens of thousands of animations and motion capture inside the virtual world of Secondlife. The default SL rig is just a basic human rig, not much different than any other. What is generally the hard part, is getting motion capture data onto a rig, more so to edit them, or retarget them onto a rig. I use a specific addon in Blender called Avastar, created by Machinimatrix. They have taken the default SL avatar and recreated it inside of Blender with various tools to more easily use the rig for human characters. Now, of course, the SL avatar has issues, but what Machinimatrix has done is essentially created a human rig and system to easily create humaniod characters with, and easily retarget and edit motion capture data, as well as a fully IK rig to animate in that way.

    Now, I would dispute that it is in anyway difficult to make a compatible Unity rig. IMHO, Unity has somehow made it incredibly easy, but it can't do magic, which is what alot of people want it to do. I just use the Avastar rig because it also makes everything else easier for me. As far as motion capture data, I use a IPIsoft Desktop mocap system, which I can use 2 Kinect cameras that give me a full 360 degrees around me or the actor. The software allows me to import whatever rig I want to use, in whatever format I want to use. It also allows me to export to any format. So, technically, I could bypass Blender entirely, and import an fbx of the mocap directly into Unity, for a specific rig, or just to convert to humanoid. Of course, I'd rather bring them into Blender where I have full control over doing any corrections or adding finger motion or whatever.

    My advice to the thread creator ......... keep learning, watching tutorials, and testing. Your best bet is to configure both mocap and character rig to Humanoid, and utilizing Unity. If it is possible to apply the mocap data to your rig inside of Blender, I would attempt that first, and then you can import them both together, and convert both to the humanoid rig in 1 shot. I will likely do some videos specifically on mocaps, the humanoid rig, and Unity.
     
    Last edited: Mar 18, 2015
    Purpleshine84 and Mecanim-Dev like this.
  7. punkouter2019

    punkouter2019

    Joined:
    Jul 28, 2013
    Posts:
    170
    finny you mention that.. I did a ipisoft with two Kinect v2 in 360 configuration and I have the FBX motion files and wondering how to learn the basics of getting them into unity.. Id be happy to just figure out how to push different buttons and have it play different animations.. I guess I need to export different takes from ipisoft into separate FBX files right?
     
  8. medhue

    medhue

    Joined:
    Aug 24, 2014
    Posts:
    176
    Yep. You could even use Unity's humanoid rig as the rig you import into IPI and export to fbx.
     
  9. Arcull

    Arcull

    Joined:
    Mar 17, 2015
    Posts:
    17
    Thanks all. From what has been written, I guess it is better to do the whole character with rigging and animations in Blender and them import it as a single fbx to Unity. If I see correctly Avastar is a commercial Blender addon and right now I don't fee like buying a lot of tools, before I learn the essential things of animation and produce some results. I'll try to retarget my bvh to character with makehuman plugin for Blender which is free.

    But here's another thing I'd like to clear. I tried to import a sample fbx (with character and motion) to Unity and I can access that animation from C# script easily like this:

    MyCharacter.animation.play("clipname")

    however the problem here is, that my animation must be marked as "Legacy" otherwise it wont play. But from what you suggested, I should be using "Humanoid" option instead. How do I get then my animation to play?
    Thanks for your help guys.
     
  10. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    When you import your file in the inspector you have a rig tab, just switch Animation Type to Humanoid
     
  11. medhue

    medhue

    Joined:
    Aug 24, 2014
    Posts:
    176
    Good thinking! I'm in no way advocating for anyone to buy Avastar. Although it is an AWESOME add on, it is not specifically for Unity. That said, I recently had an issue with using too many bones for weighting, and Avastar has a feature to highlight all the vertex with more than 4 bone weights, which made it super easy to find and correct the issue.

    As far as retargeting that bvh, Blender does have some really good retargeting tools, but it can be a very complicated and confusing process. My advice is to utilize Unity for it's inherit retargeting capabilities first. Of course, you'll probably want to get everything in Blender anyways, just because Blender is probably 1 of the best animation editors out there.

    Of course, I'm not a coder. At best I fumble through it. lol

    The easiest way to play your animation in the scene is to use the Animator Controller. All you really have to do is create a Animator Controller in your project folders, double click it, drag in the animation, and then drag the Animator Controller into the appropriate slot in the inspector, while selecting the character in the scene.
     
  12. punkouter2019

    punkouter2019

    Joined:
    Jul 28, 2013
    Posts:
    170
    Where is the 'unity huminoid rig' located at? This is a fbx file that installs with unity ?
     
  13. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    No this a built in feature of Unity, when you import a file you can choose how you would like to import your file: Either no animation, legacy, generic or Humanoid.

    You should take a look a some tutorial first to understand the basic animation concept in Unity
    http://unity3d.com/learn/tutorials/modules/beginner/animation/avatars
    http://unity3d.com/learn/tutorials/modules/beginner/animation/animation-properties


    importer.png
     
    theANMATOR2b likes this.
  14. Arcull

    Arcull

    Joined:
    Mar 17, 2015
    Posts:
    17
    Thanks all. As already said, I don't want to play the animation automatically when the game starts, I want it to be triggered. Something like this: in a simple FPS game player comes near the enemy and the enemy hits the player. So the enemy in my case has animation with hitting action recorded and this must be played when certain event occures. So I have to run the animation from code somehow. If my animation is marked as "legacy" I can play the animation from code like this:
    in class I have defined:

    public GameObject EnemyObject;

    this gives me the slot in Inspector as medhue described, so I can connect the EnemyObject with my concrete enemy model. In my case slot is of type GameObject and not Animation, but the principle is the same. Then when appropriate time, I execute the following statement to play the animation:

    EnemyOjbect.animation.play("hit");

    However this "legacy" mode sounds like some old method which is likely to be dropped in the near future, so I should use "humanoid" option. But when trying to run the game, I get error that my animation "hit" can not be found. Grrrrr...

    Ok so I tried the other way: in my class I add:

    public Animation EnemyAnimation;

    to get the right slot type and then in the inspector window just drag and drop my animation from enemy to it. Now I get instant message that my animation "hit" must be marked as legacy, or some similar message ;(

    Ok I go and read the docs, cause I must be doing something the very wrong way, or try to accomplish mission impossible. Thank for all the support till now, will come back.
     
  15. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
  16. medhue

    medhue

    Joined:
    Aug 24, 2014
    Posts:
    176
    It's also worth noting that if you use an Animator Controller, you can set up the system to trigger animations thru parameters.
     
  17. Arcull

    Arcull

    Joined:
    Mar 17, 2015
    Posts:
    17
    Thanks Mecanim.Dev and medhue. It was really my fault...mixing both systems. Now I created new Animator and added the animation clips I want to play and can make them play through C# script via

    MyAnimator.play("hit");

    or by setting a parameter "PlayHit" of type bool in Animator and making a transition from Idle to "Hit" state when "PlayHit" is true. So this system works ok. However I have problem checking if certain animation clip ended playing. From what I googled around something like this should work:

    hitplaying = MyAnimator.GetCurrentAnimatorStateInfo(0).IsName("hit");

    but this behaves weird. Before I fire my "hit" animation, the value really is "false". After I fire it, I'm getting value "true", which is ok. But I'm getting value "true" even when the clip stops playing. For testing purposes I'm checking "hitplaying" in function Update i.e. on every frame. Any idea how can I fix this. Thanks for your help.
     
  18. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
  19. Arcull

    Arcull

    Joined:
    Mar 17, 2015
    Posts:
    17
    theANMATOR2b thanks I've solved most of my "newbie" problems. But I'm still stuck at getting the animation state. As I wrote earlier, I can't recognize when the animation ends playing. I must be able to do that from script. Could you turn me in right direction for this one? Thanks again.
     
  20. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
  21. Arcull

    Arcull

    Joined:
    Mar 17, 2015
    Posts:
    17
    The problem was, that I didn't make the transition from the animation that gets triggered back to Idle state (in the animator window). Case solved.
     
    theANMATOR2b likes this.
  22. idduland

    idduland

    Joined:
    Sep 14, 2018
    Posts:
    3
    I hired this great guy from Fiverr dot com He retargeted truebones mocap to my 3d model. In the end I paid 25$ but was well worth it.

    http://www.fiverr.com/idduland
     
unityunity