IKFK Switch using ScriptJob?


#1

Hi all, I’m sure this question of mine have been asked a lot in forums but unfortunately, I am unable to find posts/ tutorials that cater to my workflow process.

I would really appreciate it if any help/advices could be given.

I am able to generate some MEL scripting/expressions to perform the switch from IK to FK and vice verse, but the problem right now I’m encountering is how am I to incorporate it into the custom attributes I have created in my controllers…

Honestly speaking, I am not very well versed in the MEL Expressions, as such, when I tried to ‘play’ around with some other commands, inevitably it fails. I was aware that SciptJob command is able to perform it, is that true?

Otherwise, could you guys introduce to me any advance rigging tutorials that talked about it?

Thanks a lot in advance!


#2

Hi, its hard to say right now without knowing how you built your IK FK setup.
Ill try to give you some ideas from a setups I have built so far.
To generate IK/FK Arms I use 3 versions of the same arm which consist of a forearm ,an upper arm and a wrist joint each. One version is controled by FK, one is driven by an IK handle and the third one will be used for skinning. To create the IK/FK switch i use a blend node in the hypergraph to match the rotation attributes of the skinning arm to EITHER FK or IK. You can then use any object in the scene (I use a locator or curve Object close to the wrist of the character) to add a custom attribute that controls the blending value of said blend node.

Thats the general Idea of the technique

The part that is a tad more tricky is the script job (I use MEL) utilizing the xform function a lot. You want to create a script that depending on the current state of the IK FK arm (either its in IK or FK mode obviously) switches to the other state and shows/hides current controls.
I split up the script job in two smaller scripts which I can execute from a custom Shelf to make the switch.
One additional thing to watch out for is that you also have a script to keyframe all of the arms (also the hidden ones) so they are always nicely aligned and dont give you any weird animation curves later on once you animate them.

Also one important thing is to have a control object following the plane of the FK arm (a locator will do) to have something to position the IK arm’s pole vector object to on switching.

I hope that all made a little bit of sense. Its a complex thing to get right (for me at least since im not much of a rigger yet). If you have any other questions please feel free to ask. Ill try to help out where I can!

Good luck


#3

hi!
one method I have used in the pas to create an IK/FK switch is to use maya’s blend color node.
This video describes the basic idea of it:
http://lesterbanks.com/2011/11/maya-blend-node-ik-fk-switching/

What you want to do is drive the switching of your skinning joints (when setting up e.g. an IK/FK arm you usually have 1 IK arm, 1 FK arm and 1 skinning arm and you animate the skinning arm between the other two) with the blend color node. This gives you an attribute you can connect to any custom attribute you added to any (control) object and hence creates the connection for you.
Good luck!


#4

Hi FrederikP, thanks a lot for getting back to me.

I shall test it and see how it goes.

Thanks again!


#5

Hi FrederikP, missed out this post of yours.

Well I am also not much of a rigger as of yet and hence would like to know such ‘fundamentals’ right. Nevertheless, upon reading your post, I also have similar workflow to yours.

I have 2 MEL scripts that I have placed it in my shelf that enables to switch between IK and FK. But currently I have no idea how to implement the expressions I have created to incorporate into the controllers.

I do believe it will somewhat be a hassle for every user/animator to install the 2 custome MEL scripts… Perhaps you can enlighten me on this case?


#6

Hi, I may have made some mistakes in this but here it goes anyway.

I think to save mel functions inside the (.ma example) just copy and paste it into a new expression (evaluation on demand). Another way to save mel functions inside the (.ma) is paste it into a new script node (evaluation on demand). Both can be created in Maya’s animation expression editor (name the expression, paste the code, create). Also, one reason for the (evaluation on demand) I think is so the expression isn’t run everytime timeline changes.

After doing above, with global mel procedures the mel functions can be called directly.

I think to get the pasted mel function run automatically when animator attribute selects (fk of an enum for example) is to create a scriptJob with (attributeChange) event. Here is an example:

//
scriptJob -attributeChange “nurbsCircle1.arm_state” “foo( “changed arm state” )”;
//
// Result: 35 //
//foo(string) --global mel function saved in expression or script job
//nurbsCircle1 – transform with state enum attribute
//35 --the scriptJob id number, this is needed to delete this scriptJob see Maya docs under scriptJob.

By typing above once in script editor the scriptJob is in place.(see picture I made for short example: http://flic.kr/p/cHoquW)
To remove scriptJob.
//
scriptJob -kill 35;
//

Hope this was helpful.
Cheers,
Nate


#7

ha, the post you quoted wasnt there earlier because I just created this account and it was one of my first posts which needed to be evaluated before they appeared.
I thought the post was lost and created a new, simpler one.
I know its possible to have scripts start with the scene which makes it easier for the animators but I haven’t managed to do that yet.
I thought it was quite common for rigs to come with a script or two which need to beinstalled before use. Automating it would be nicer of course.


#8

Hi ogbonna, thanks alot for your feedback.

Though I have tried implementing your method, it does not seems to work for me at the moment (most probably I have gotten somewhere wrong or in my hierarchy) Nonetheless, I shall try it again.

Still, I would like to ask, as I am not very sure, can I assume that according to the variable I have chosen (the Enum attribute), it will executes accordingly to the Script Job?


#9

Hi,
yes, when the enum variable is changed because of the attributeChange, the mel code attached to the scriptJob during creation will get executed.

Also, it may be helpful to try a very simple scene first maybe one nurbs circle with one enum attribute and try writing a scriptJob that just prints something when the enum is changed. That way it makes it a little easier to see how the scriptJob is working. I don’t know how the backend works, but basically because of the attributeChange option, we can know when an attribute is changed on the scene and call stuff to do when that happens. By saving the stuff to do in the Maya scene no scripts need to be saved, instead they can just be pasted inside an expression or script node.

Also these posts by Owen and Hamish might be helpful to you:

Check out Owen Burgess’s post http://mayastation.typepad.com/maya-station/2009/06/trigger-an-event-when-you-change-an-attribute.html

And Hamish McKenzie’s posts
http://forums.cgsociety.org/archive/index.php/t-129787.html

Cheers,
Nate


#10

be carefull with the scriptjobs they dont work so well and often mess up .
Usually the simples way is haveign a shelf button or trying to hook it up an expression and use some getAttr in some crucial points in order to force the refresh of the expression.

If only the scirpt jobs worked as well as the API callbacks


#11

Hi Giordi, thanks for getting back to me.

Currently I am trying to find a way to reduce the need for animators to install any shelf button etc. so as to achieve the snapping from ik to fk and vice verse as I thought it will be better to incorporate all into a single maya file.

By the way, could I ask from your post, you have mention about getAttr, can you specify it in more details?


#12

There are dozens of ways to do everything in Maya, scripting something as simple as a FK|IK switch is one of the least useful things you can do in Maya.

Anything you run as a script or an expression has to do an evulation on a per frame basis and can lag your system down pretty hard.

It’s far easier in a lot of cases to write a script to add the attributes in and create a HUD slider for the animators to give them control of the FK|IK switching.

Your post does leave out some essential questions

What are you creating these rigs for: Games or Commercial Video.

Each type will have its own restrictions.
in this thread http://forums.cgsociety.org/showthread.php?f=54&t=1064797
I have attached a FK|IK stretch Blend rig.
This is a pretty clean and simple way to acheive FK|IK switching The control for the switch is built in to the global control, but in reality it can be placed anywhere that it is needed. Such as a HUD slider or a Halo Slider.


#13

Hi Darksuit, thank you for getting back to me.

Well, I am creating it for a school project - short film, and thus I would says it is more for Commercial Video.

Even so, can I ask is there suppose to be subtle differences when doing rigging for Games and commercial videos? Do correct me if I am wrong, but I thought the rigging parts will be the same for either of the two categories.

Additionally, I have just seen your example that you have posted in the thread you have provided. Personally, I do not think IKFK Blend method is the solution I am trying to look for, as I am more to looking for IK FK snapping and vice verse. Till date, I am still trying to find more methods about such snapping, but it will be without the use of any plugins or downloading of any scripts etc.

Should you have any info on the IKFK snapping, please do tell me as I am still in the midst of finding more methods so as to cater to my current rigging and in the future as well :slight_smile:


#14

ikFk blending does not mean you cannot do ikfk snapping you can have both so the blending is pretty easy and yo can start having that working


#15

one of the major distinctions with games in particular is that a lot of times you are restricted in the number of bones/joints that you can use, also your setups can become a lot more restricted as well to work with particular engines. Some game engines are more forgiving than others. In most cases you want to reduce the number of bones that you are using for games to reduce the draw calls that and processor load.

With Comercial and VFX work they also may have particular restrictions based on the project. (working in games I have less information on this).

Getting back to IK snapping. One of the reasons that I find the sample that I provided in the other thread tends to work fairly well for me in a number of situations is that it allows for both a quick snap over 1 frame or a smooth blend over several frames.

Now if we are talking about IK|FK matching thats a slightly different story. Matching FK to IK is fairly easy. In Fact that exactly what the blend rig is doing behind the scenes.

Matching IK to an FK rig is nigh impossible or at least a right pain in the butt. The reason is that you constantly have to reassess the pole vectors to make sure your angles are correct. This is why I say nigh and not completely, as some people out there have done it. But it is a right pain in the butt. It’s one of the things that lead to the sample blend rig that I setup.

Just working with the rig itself once you get used to it after a bit, you can snap the IK pretty cleanly to the FK position then make minor quick adjustments to the pole vector to match it. In a lot of cases you don’t even need to do this. As one of the other options is to just position the IK arm at the start of the IK movement for the animation, then blend from FK to IK and vice versa.

It can keep things clean and simple for both animators and riggers.


#16

Sigh. Clearly these guys know how to blend between FK and IK. The thread is about snapping/matching scripts to match the IK chain to FK or the FK chain to IK. Running scripts based on attribute changes to prevent having to load external scripts and this general realm.

Also, your solution for snapping isn’t a solution, as your only able to manually snap FK to IK. Pole vectors can be easily lined up to match IK to FK. Match your pole vector to the FK lower arms translate and rotate, then just translate it -Z or +Z - whatever make sense.


#17

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.