#1 09-27-2017 12:18 pm

pempa
Registered: 09-05-2017
Posts: 14

ik to fk snap.

its my first post so, sorry if its the wrong forum. i know its a much asked question but it'll be very helpul if anybody answers. i am a fresher in animation, need a practical way to snap from fk to ik or vice versa. i've already google it and it a has not been much of an help.

Offline

 

#2 09-27-2017 2:49 pm

zethicus
Celebrity
From: Mexico
Registered: 04-25-2011
Posts: 116
Karmojo: 66

Re: ik to fk snap.

I did two quick MEL scripts back in the day for ik/fk match, you just have to replace the names of my controls to yours, see if it works, here's fk to ik:

-------------------------------------------------------

Code:

//Creando locators

spaceLocator -n ikLocElbow01;
spaceLocator -n ikLocWrist01;

//Parenteando locators a joints

select -r bn_l_elbow01 ;
select -add ikLocElbow01 ;
doCreateParentConstraintArgList 1 { "0","0","0","0","0","0","0","1","","1" };
parentConstraint -weight 1;

select -r bn_l_wrist01 ;
select -add ikLocWrist01 ;
doCreateParentConstraintArgList 1 { "0","0","0","0","0","0","0","1","","1" };
parentConstraint -weight 1;

//Borrando parentConstrains

select -r ikLocElbow01_parentConstraint1 ;
doDelete;

select -r ikLocWrist01_parentConstraint1 ;
doDelete;

//Nesteando ikLocElbow01

select -r ikLocElbow01;
duplicate -rr;
parent ikLocElbow02 ikLocElbow01 ;

//Moviendo ikLocElbow01 translateZ - 7

float $elbowRot = `getAttr cc_l_fk_elbow01.rotateY`;

if ($elbowRot <= 0) {
    float $elbowTrans = `getAttr ikLocElbow02.translateZ`;
    float $newElbowTrans = $elbowTrans - 7;
    setAttr ikLocElbow02.translateZ $newElbowTrans;
} else {
    
    float $elbowTrans = `getAttr ikLocElbow02.translateZ`;
    float $newElbowTrans = $elbowTrans + 7;
    setAttr ikLocElbow02.translateZ $newElbowTrans;
}

//Parenteando controles a locators

select -r ikLocElbow02 ;
select -add cc_l_ik_elbow01 ;
doCreateParentConstraintArgList 1 { "0","0","0","0","0","0","0","1","","1" };
parentConstraint -weight 1;

select -r ikLocWrist01 ;
select -add cc_l_ik_hand01 ;
doCreateParentConstraintArgList 1 { "0","0","0","0","0","0","0","1","","1" };
parentConstraint -weight 1;

//Borrando parentConstrains y locators

select -r cc_l_ik_elbow01_parentConstraint1 ;
doDelete;

select -r cc_l_ik_hand01_parentConstraint1 ;
doDelete;

select -r ikLocElbow01;
doDelete;

select -r ikLocWrist01;
doDelete;

//Switcheando a IK

setAttr cc_ikfkSwitch01.IKFK 0;

------------------------------------------

And here's ik to fk:

----------------------------------------------

Code:

//Match IK a FK

//Declarando variables de valores de rotaciones de IK

float $ikrX01 = `getAttr bn_l_arm01.rotateX`;
float $ikrY01 = `getAttr bn_l_arm01.rotateY`;
float $ikrZ01 = `getAttr bn_l_arm01.rotateZ`;

float $ikrX02 = `getAttr bn_l_elbow01.rotateX`;
float $ikrY02 = `getAttr bn_l_elbow01.rotateY`;
float $ikrZ02 = `getAttr bn_l_elbow01.rotateZ`;

float $ikrX03 = `getAttr bn_l_wrist01.rotateX`;
float $ikrY03 = `getAttr bn_l_wrist01.rotateY`;
float $ikrZ03 = `getAttr bn_l_wrist01.rotateZ`;

//Metiendo esas variables en los valores de traslacion de IK

setAttr cc_l_fk_arm01.rotateX $ikrX01;
setAttr cc_l_fk_arm01.rotateY $ikrY01;
setAttr cc_l_fk_arm01.rotateZ $ikrZ01;

setAttr cc_l_fk_elbow01.rotateY $ikrY02;

setAttr cc_l_fk_wrist01.rotateX $ikrX03;
setAttr cc_l_fk_wrist01.rotateY $ikrY03;
setAttr cc_l_fk_wrist01.rotateZ $ikrZ03;

//Prendiendo FK

setAttr cc_ikfkSwitch01.IKFK 10;

----------------------------------------------

Some notes:

cc_ikfkSwitch01.IKFK is my control to blend between ik and fk on my arm

In the fk to ik part, if it doesn't work, try changing the 7 to something higher in this section (It depends on your scene size):

Code:

//Moviendo ikLocElbow01 translateZ - 7

float $elbowRot = `getAttr cc_l_fk_elbow01.rotateY`;

if ($elbowRot <= 0) {
    float $elbowTrans = `getAttr ikLocElbow02.translateZ`;
    float $newElbowTrans = $elbowTrans - 7;
    setAttr ikLocElbow02.translateZ $newElbowTrans;
} else {
    
    float $elbowTrans = `getAttr ikLocElbow02.translateZ`;
    float $newElbowTrans = $elbowTrans + 7;
    setAttr ikLocElbow02.translateZ $newElbowTrans;
}

Hope it works!


-Zeth

Offline

 

#3 09-27-2017 2:55 pm

zethicus
Celebrity
From: Mexico
Registered: 04-25-2011
Posts: 116
Karmojo: 66

Re: ik to fk snap.

I just wanted to add that while premium rigs have fk and ik matching, most animators out there have to make do with what they're given, and matching it by hand isn't that hard to do.

Oh, if you're using the script, don't forget to set keys after matching or you will go back to square 1 lol.


-Zeth

Offline

 

#4 09-27-2017 3:12 pm

RyanHagen
Upright Citizen
Registered: 06-16-2007
Posts: 1110
Karmojo: 48
Moderator

Re: ik to fk snap.

Typically it's built into the rig, if it's not already built in, it will be quite an endeavor for you to get it working as it requires some scripting.  I believe there are some scripts that help you set it up, but on a rig that you're not familiar with, in terms of what's going on "under the hood", it could be destructive.  I would check highend3d.com for some scripts to see if there are any available there.

I see zeth beat me to the punch, perhaps I should hit submit after I type something:D  I would also echo what he/she said about "making it work", before switching was available, it was done all of the time and it really isn't that difficult to solve.


Ryan
Animator
"Frustration is the handmaiden of creativity" ~ Chuck Jones

Offline

 

#5 09-28-2017 5:52 am

pempa
Registered: 09-05-2017
Posts: 14

Re: ik to fk snap.

Thanks very much zeth, ryan. Can you please add a link of a toutorial on how to import or install the mel script cause this is totally new to me.

Offline

 

#6 09-28-2017 1:23 pm

RyanHagen
Upright Citizen
Registered: 06-16-2007
Posts: 1110
Karmojo: 48
Moderator

Re: ik to fk snap.

The scripts that Zeth provided would simply live on it's own as a button on your shelf. 

You would need to change the names in his code in order for you to get them to work on you character.  So for instance "cc_l_fk_elbow01.rotateY" might be "pempa_L_fk_elbow_jnt.rotateY". Simply replace all of the naming conventions he/she has in their script to match your rig.

Open the script editor, past the script, make your changes and save the script as a button to your desired shelf and when you want the switch to happen, hit the button. As Zeth stated, make sure you key your controls after you make the switch as there isn't a setKey function in that script.  I hope that helps, it may or may not work, again, it depends on what's going on "under the hood" of the rig you're using.


Ryan
Animator
"Frustration is the handmaiden of creativity" ~ Chuck Jones

Offline

 

#7 09-28-2017 3:39 pm

zethicus
Celebrity
From: Mexico
Registered: 04-25-2011
Posts: 116
Karmojo: 66

Re: ik to fk snap.

Thanks Ryan! I hope it works!


-Zeth

Offline

 

#8 10-03-2017 9:18 am

pempa
Registered: 09-05-2017
Posts: 14

Re: ik to fk snap.

thanks a lot, is very helpfull, saved me from a lot of trouble... smile

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson