Search Unity

Flat facial animation on 3D character

Discussion in 'Formats & External Tools' started by Hakimo, Dec 27, 2010.

  1. Hakimo

    Hakimo

    Joined:
    Apr 29, 2010
    Posts:
    316
    Hi,

    This general question is not limited to only Maya, but other 3D modelling tools. I'm trying to create a 3D character that has a flat facial animation look and to use it inside Unity. The problem is I'm not sure how to do it.
    1. Do I have to make shapes for the face expressions or can I use textures?
    2. Should the facial animations be controlled by script in Unity or?
    Here's an example what I like to do:


    Notice how the facial animation changes according to dialogue.

    Hope someone can help me with this. Thanks in advace.
    -Hakimo
     
  2. Hakimo

    Hakimo

    Joined:
    Apr 29, 2010
    Posts:
    316
    Bump. If I'm posting this in the wrong forum please let me know :)
     
  3. Paulius-Liekis

    Paulius-Liekis

    Joined:
    Aug 31, 2009
    Posts:
    672
    Unity doesn't support BlendShape animation, although I have seen some user based scripts for that. If you want to go with what's built-in in unity, you have to do bone-based facial animations.
     
  4. ron333

    ron333

    Joined:
    Jan 3, 2009
    Posts:
    47
  5. Hakimo

    Hakimo

    Joined:
    Apr 29, 2010
    Posts:
    316
    Thanks very much. Sorry for the late reply. I didn't get any notification about it. I'll take a look at the animation view :)
    -Hakimo
     
  6. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    For this type of effect I think a texture atlas of the different facial expressions might work best. Then just change the UV offset parameter of the texture to get the desired expression to show up. There would be no blending, but it didn't look like there was any in the video you linked either.
     
  7. Hakimo

    Hakimo

    Joined:
    Apr 29, 2010
    Posts:
    316
    Hi, thanks for the reply. I have a new question. I've looked at the animation view tutorial and I'm finally able to make facial expressions and have it animated on a 3D character. Here's a snippet of code:
    Code (csharp):
    1.  
    2. if (currentSpeed > 0.1) {
    3.         print("test");
    4.         }
    5.     else
    6.         animation.CrossFade("idle"); //Physical animation
    7.         meExpression.animation.CrossFade("MeIdle"); //Facial animation
    8.        
    9.     if (Input.GetButton ("Fire1")) {
    10.         animation.CrossFade("search2"); //Physical animation
    11.         meExpression.animation.CrossFade("MeSad"); //Facial animation
    12.     }
    13.  
    Is there a way to manage animations? E.g When character jumps, play the facial animation and after jumping, stop the animation? I can't use the !animation.IsPlaying for some reason. And from my example code above, everytime I press the fire1 button, it plays the search2 and sad animation but I can also see the MeIdle animations.

    Hope someone can help.

    Thanks very much
    -Hakimo
     
    Last edited: Mar 17, 2011
  8. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    You need to use animation Layers.
     
  9. Hakimo

    Hakimo

    Joined:
    Apr 29, 2010
    Posts:
    316
    Thanks for the reply Fishman92. I've looked at animation layers and even animation.synclayer but I can't seem to grasp on how to use animation layers. I have two game objects, each with an animation attached. One is for character body and the other one if for facial animations. Here's a small snippet of what I've made:

    Code (csharp):
    1.  
    2. var charExpression : GameObject;
    3.  
    4. function Start ()
    5. {
    6.     // We are in full control here - don't let any other animations play when we start
    7. //  animation.Stop();
    8.  
    9.     // By default loop all animations
    10.     animation.wrapMode = WrapMode.Loop;
    11.     animation["walk"].layer = 3;
    12.     animation["idle"].layer = 3;
    13.     charExpression.animation["faceJump"].layer = 2;
    14.     charExpression.animation["faceJump"].wrapMode = WrapMode.Clamp;
    15.    
    16.  
    17.     // The jump animation is clamped and overrides all others
    18.     var jump = animation["jump"];
    19.     jump.layer = 2;
    20.     jump.enabled = false;
    21.     jump.wrapMode = WrapMode.Clamp;
    22.         animation.SyncLayer(2);
    23. }
    24.  
    25. function Update() {
    26.         if (marioController.IsJumping())
    27.     {
    28.                 charExpression.animation.CrossFade("faceJump");
    29.         if (lastJump.time > landBounceTime) {
    30.             lastJump.speed = 0;
    31.         }
    32.     }
    33. }
    34.  
    35.  
    The animations I should get is the jumping animation and facial animation to play at the same time. For now the facial works but it's not playing the animated jumping of the character's body. I'm a bit confused about how animation layer works but from I understand, what it does is basically grouping the animations yea?

    Hope someone could help.

    Thanks very much.
    -Hakimo
     
  10. Hakimo

    Hakimo

    Joined:
    Apr 29, 2010
    Posts:
    316
    Scrap that, again I've seen to have complicated things. This might be an easier solution, since I have the facial animations on another gameobject inside the character's hierarchy, is it possible to call an animation event from another game object?

    - Hakimo
     
  11. Hakimo

    Hakimo

    Joined:
    Apr 29, 2010
    Posts:
    316
    Discussed this with a Unity Evangelist. At the moment, I can't call on a function of an animation of a another game object from the animation view editor. For now, scripting it is the only solution.
     
  12. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,755
    I saw blendshapes mentioned, but I don't think the video you linked was using blend shapes, it just changed the texture. So you should make a texture atlas with different facial expressions in it and then move the UVs around to the ones you want, when you want them.
     
  13. Hakimo

    Hakimo

    Joined:
    Apr 29, 2010
    Posts:
    316
    Yep already done that :) I'm using the facial animation script from the Animation tutorial at unity3D. For now I can call the animation from script but I can't call the animation in the view editor since it's on another game object.
    -Hakimo
     
  14. goshujin

    goshujin

    Joined:
    Mar 29, 2011
    Posts:
    1
    How did you do it in the end?
    Do you mind sharing your solution?

    And did you do texture swapping?
    As in have an eye texture, mouth texture etc that you replace

    I am also looking to do something similar, so my thanks in advance!
     
  15. makan

    makan

    Joined:
    Jan 8, 2011
    Posts:
    342
    In Max Maps are animate able like noise, but for a flat shape animation hmm ... maybe morph modifier can help, in your 3d application make a face with different face textures then add them to your morph it and make them animate able, it should work imo
     
  16. Hakimo

    Hakimo

    Joined:
    Apr 29, 2010
    Posts:
    316
    Hey Goshujin,

    Welcome to the Unity Forums. Here's a link that I use to start with. I used the C# version of the facialanimation code. In the vimeo video it shows how it works. Once it's done it's called like any other animations i.e.
    Code (csharp):
    1. animation.Play("HappyFace");
    Don't forget to download the unity file from unity3d and watch the videos.

    If you any more questions, feel free to ask :)

    -Hakimo
     
    Last edited: Mar 30, 2011
  17. Hakimo

    Hakimo

    Joined:
    Apr 29, 2010
    Posts:
    316
    Hi Makan,

    Umm I don't think there's any support yet for morph targets in Unity. Unless you know something I don't know ;) If yes, could you share me that link etc?

    -Hakimo
     
  18. makan

    makan

    Joined:
    Jan 8, 2011
    Posts:
    342
    Well i think we can make animations with morph then collapse it so that it change to editable poly or mesh in case unity don't support it, then exported to fbx and bake the animations, and run it to unity....:)
     
  19. Hakimo

    Hakimo

    Joined:
    Apr 29, 2010
    Posts:
    316
    Awesome. Sorry for the late reply. I'll try and see if it works :) Have you tried it before?
     
  20. owaris@post.com

    owaris@post.com

    Joined:
    Dec 18, 2012
    Posts:
    4
    Sir I have a 3d max fbx file.But i try animation 3d chracter but is no working in animation plz you are help me.
     
  21. AleksLA

    AleksLA

    Joined:
    May 7, 2013
    Posts:
    22
    the links for animation view are not working, I also want to do a game where I use this technology, but can't find the way to animate it lie this, any ideas ?
     
  22. Laokoon

    Laokoon

    Joined:
    Apr 2, 2014
    Posts:
    1
    Same thing here! No clips, no videos.
     
  23. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    This shouldn't be so unsupported.


    Too many games do this! -- Why can't Unity?
     
  24. AndreiKubyshkin

    AndreiKubyshkin

    Joined:
    Nov 14, 2013
    Posts:
    213
    I don't get it. This "flat animation" is just a simple manipilation with uv's, that can be easily done with scripting. Basic tool can be written in few hours probably. And this kind of tools is very specific in my opinion to implement it to unity by default.

    The example from the first post has nothing to do with morphs / blendshapes.

    Dead thread btw.
     
  25. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Animating uvs or changing mesh topologies in unity creates lots of back end issues that can drastically impact performance, and these issues cannot be solved with scripting alone.

    The issue I have is this should already be supported deep in the core engine by now, and issues with GC and such should be handled automatically for things like this. Additionally, this can be used for more than facial animation. Take a look at runtime modeling tools like Archimatix for an example of other uses. No need for an interface, just backend engine support. Facial animation alone is a common enough use case to support this optimization from the backend natively, which is why I wanted to leave my two cents here.

    Also, why reply to something you deem a dead thread just to bring it back to life?

    At the risk of feeding trolls, I personally think the subject of mesh and uv manipulation needs more attention, which is the reason I replied, and really, have you noticed the lack of attention new threads get in the forums in general? I'd rather post to something with some history behind it than to something brand new in hopes others will see the bigger issue. Hopefully I've highlighted this issue well enough in my response to you that if Unity happens upon this, they'll get the issue.
     
    Last edited: Jul 18, 2017
  26. AndreiKubyshkin

    AndreiKubyshkin

    Joined:
    Nov 14, 2013
    Posts:
    213
    I use UV scrolling a lot in my mobile game and haven't expirienced a single issue. Could you please provide some examples?

    I had no attention to touch your feelings, just pointed out the fact that the tread is 3 years old in case you didn't noticed.
     
  27. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    No worries. I just wasn't sure how to take your commentary.

    It's been a while since I've done my research, but I guess one of the biggest backend issues with meshes has apparently been dealt with using the new Set/Get methods taking a list as a parameter, making updating existing meshes loads more fast and reliable since it no longer requires copying to a separate list or array in between. This comment by bunny83 explains the current workaround to this in more detail if anyone's interested:

    http://answers.unity3d.com/questions/1215847/mesh-setvertices-vs-vertices.html

    The only other issue I have is that it's really lame that UV/vert animation as well as texture-swapping or blendshape animation can't be done in the native Unity Animator window directly. This is pretty lame because it really does require a separate tool to be written for something everyone is already doing for various effects, and to have a solid design for a tool that incorporates keyframing everything, you'd think they'd make it able to keyframe stuff like that too.

    Just my opinion though.