Home Technical Talk

[Maya] cloth rig for export to Unity?

Elie
polycounter lvl 7
Offline / Send Message
Elie polycounter lvl 7
Hey everybody,
this time I have to make a rig of a game-ready templar character with some kind of long jacket (or skirt). I would like to test a dynamic to see how it works. Any inspirations or reference for technical solutions that I could use? I'm working with Maya and Unity. The goal is to animate in Maya actions like walks, runs, fight... I will also need to take care of the jaw for dialogue, although it's hidden in the beard, luckily.

Replies

  • Eric Chadwick
    Options
    Offline / Send Message
    What hardware do you need it to run on eventually?

    Mobile requires optimization, you likely won't want the performance cost of a fully dynamic cloth sim, so you would bake sim anims down into bones and use skin weights. Or else bake the vertex animation into cache files.

    Unity has addons for cloth, what have you checked out so far?

    Jaw can be done with regular skinning. You could see if there's an automated lipsync tool that will convert sound files into jaw motion. Could save a ton of time. 
  • Yerus
    Options
    Offline / Send Message
    Yerus polycounter lvl 4
    In a nutshell how can u bake the sim into the bones? What will happen when u do that? 
    And is there such automated lipsync u mentioned?
  • Eric Chadwick
    Options
    Offline / Send Message
    Search it.
    Performance gain.
    Yes (search).
  • Elie
    Options
    Offline / Send Message
    Elie polycounter lvl 7
    Thanks a lot Eric, I will search. I'm having a hard time trying to bake ncloth deformations to bones. I'm not sure I can make it. But I did it on a single vertex from a cube. Keys on vertex, copy/paste the curves from the graph editor on a locator, scaled them to 20, then constrain parent on the joint. Quite a lot to do if there's joints everywhere. And, as I said, I failed to do it with the object that has ncloth applied. When I key-bake the animation, the keys the vertices on the graph editor are real flat, it's like they don't even move.  
  • Elie
    Options
    Offline / Send Message
    Elie polycounter lvl 7
    And it's a pain to manage the ncloth parameters.
  • Eric Chadwick
    Options
    Offline / Send Message
    I've renamed your subject line from "cloth rig", this should help draw people in who are familiar with (or interested in!) this workflow. 
  • Elie
    Options
    Offline / Send Message
    Elie polycounter lvl 7
    Thanks again Eric, I've just noticed I forgot to answer your question about the hardware, we're working on VR. Unfortunately I don't have with me the spec of the backpack the game will be running on but I can tell I need to optimize like hell. I've heard about deleting the joints in the hands of some characters cause they're "just" holding their weapons.

    By the way, cloth component directly in Unity has been clearly rejected because it's to expensive in ressources. 
  • Elie
    Options
    Offline / Send Message
    Elie polycounter lvl 7
    It's frustrating for me to not be able to get this work, especially when I see some good results of talented people out there with the use of dynamics-for secondary motion. It seems they are scripting. I think someone posted a script somewhere but I wouldn't even know how to use it nor what it really does.
  • Elie
    Options
    Offline / Send Message
    Elie polycounter lvl 7
    I also tryied to use the bonus tool's make joints dynamic, with hair system or ncloth based, which is nice, but I can't manage my skirt to work with the legs moving as a passive collider for great interaction.
  • Eric Chadwick
    Options
    Offline / Send Message
    The last time I saw someone baking cloth like this, it was for a MMORPG I worked on for PC. They ended up writing their own scripts to work with our sim data in 3ds Max. The basic workflow IIRC:

    1. import the lowpoly model with its animations,
    2. align the bones to the T-pose cloth, 
    3. bind the bones so they stick to the cloth, 
    4. sim the cloth, 
    5. bake the bone positions/rotations, 
    6. unbind them from the cloth, 
    7. un-sim the cloth, 
    8. skin the cloth to the bones, 
    9. export.

    This had to be repeated for hundreds of animations. And if there were animation tweaks, the sims had to be re-done. Only way to make this sane was to script it.

    There might be something comparable for Maya. Have you checked the usual Melscript websites?
  • Eric Chadwick
    Options
    Offline / Send Message
    You can see some of the results of that work here. The female character's dress, the black-caped monsters, the pennant flag props, etc.

    https://www.youtube.com/watch?v=qklBjGf-Arc&t=200
  • Hito
    Options
    Offline / Send Message
    Hito interpolator
    you could try Unity recorder to export simulated joints as FBX, then reimport that back as baked animation.

    Rig your cloth with joints
    Animate the character
    Import to Unity, setup cloth joints for simulation
    sim the animation, for several loops if it's a cycle, make it easier to loop the sim later
    Export the Sim to FBX
    Fix up in Maya,
    Export final anim with baked sim to Unity
  • Elie
    Options
    Offline / Send Message
    Elie polycounter lvl 7
    Again thanks a lot guys for the inspiration. Congrats Eric for the nice work on that link. Hito, I didn't understand because it seems the unity recorder is there only to record movie/video files?

    I can't believe how hard it is. After a few tests, for me, here's what seems to work best for now:

    I have some joint chains "falling" around the skirt. This is parented to the root in the deformation group. I use them as hair with the "make joint chain dynamic" under the bonus tool tab.

    So now I can have simulation directly on joints that I can bake. I think I'll apply it after the classic keyframe animation done on the character.
    I guess it will be still hard to manage when I will need to redo some keyframe after that.

    The bad news now, unfortunately the rigid body on the skinned legs doesn't seem to apply no matter what, so I plan on keeping controllers on the joints of the skirt, at the top of the chain to avoid penetrations with some rotate/translate.
    And I can't reduce the effects of this nucleus simulation nicely. It wobbles too much. My guess is a scale tweak or friction maybe, but whatever value I put in, nothing changes a lot. If you have some good tutorials on the subject, don't hesitate to share.

    I also grabbed a script on some site, for overlaps. I think it will be usefull if I put some secondary motions on the accessories carried by the character. I hope I can use that on the skirt itself, in some cases, if nothing else work, as a backup plan.

  • Hito
    Options
    Offline / Send Message
    Hito interpolator
    It's fair bit of a hassle to sim in Unity and bake out to FBX.

    You need Recorder and FBX Exporter packages in the project

    add rigidbody and joint components in unity for Simulation, then record the sim to an animation clip; apply the recorded clip back to the character and then export the character as an FBX animation. then you need to clean up the baked sim so it loops properly and all that. The result is okay, but quite a lot of work.

    To record animation clip, create a timeline and loop your animation on it several times, add a recorder track and clip. Assign a game object, the Root joint in most cases, set Timeline to Autoplay. Enter playmode and let the timeline play through, and you get a unity animation clip with the simulation baked in.

    Attached gif is side by side. Left to Right: 1st is No Sim; 2nd is Recorded Sim over 4 cycles; 3rd is actual Sim with colliders visible; 4th is Exported animation in Maya.

    Different setups works better for different things. This is best suited for strips or chains/ropes that is attached on one end. 

    For things like capes/skirts/long coats nCloth is better, albeit very slow and bit tedious to set up. Surface constraint a series of proxy joints or locators on a piece of mesh approximately the same size and shape of the part you want to sim, rig the part with joints as normal. the proxy joints/locators should be in the roughly same location and rotation as the joints that is bound to your model. nCloth sim drive the proxy joints and proxy joints drive the export joints. see attached gif. Make sure passive colliders are assigned to the same nucleus as the nCloth meshes for them to collide. Also set the values based on your scene units. if your scene units is centimeters, the nCloth values for gravity etc should be *100 or the sim will feel very light and slow.

  • Elie
    Options
    Offline / Send Message
    Elie polycounter lvl 7
    Thanks Hito, your methods seem great, but I can't get a surface constraint to work? Under nconstrain I can see point, slide or tearable, but none of them work. I'm kind of lost here
  • Hito
    Options
    Offline / Send Message
    Hito interpolator
    it's under Rigging menu set Constraint -> Point On Poly constraint. Attaches a transform to a poly mesh or nurbs surface, the surface must have UV data I believe.

    nConstraints are for simulation objects. you do need one of those to attach the vertices of sim fabric mesh to the character. Don't remember exactly which one, but there are plenty walkthroughs on nCloth setup online.
  • Elie
    Options
    Offline / Send Message
    Elie polycounter lvl 7
    Thanks again, this helped me a lot!
  • Elie
    Options
    Offline / Send Message
    Elie polycounter lvl 7
    Hi Hito, I'm back in this topic, you talked about using the Unity recorder above. I'm testing this to export some animations from a nice animation pack I bought in the Unity asset store. The work here would be to refine the skirt of my character in Maya, because it seems the animations I apply from the pack don't take care of it.

    But, I can't export to .fbx from Unity a clean file. I used a timeline, the fbx recorder, and the fbx exporter. Once in Maya, I have the hands and the head all broken, the mesh going away from its joints, keys everywhere even on the locked skinned mesh. It's a hell to understand... Did you have good results with this? During the process it's hard to know what's recommended or not to get a decent export file.
Sign In or Register to comment.