View Full Version : IK/FK blending questions
Leffler 07-06-2008, 10:34 AM Hello, i´m kind of stuck here so I need your help. I´m using maya 2008
I can´t figure out how to build an IK/FK blending system the way I want it
I have an IK system with a controllCurve for the arm, and a Pole Vector. The controllCurve is the parent of the ikHandle
For the FK system i have 3 controllCurves(shoulder, elbow,wrist)
What I want to do is when i´m in IK-mode I want the FK curves to snap/jump to the position of the joints when I blend over to FK. And vice versa when i´m in FK-mode.
But I dont understand how to put it up? :hmm:
The FK controlls are orientContrstrained to the joints right now.
But how do I do to get the controllCurves to jump to there right places when I blend without getting a "cycle" in Maya ?
Thanks,
Otto L - sweden
|
|
jsantell
07-06-2008, 02:10 PM
I did something similar in a previous script of mine, but had the snap at the control of a hotbox script.
Could you, when going from IK-to-FK, match the orient controls of the FK system to the bones on the IK skeleton and then turn the blend on FK to full? And for FK-to-IK, snap the controlCurve to the FK wrist, and then snap the pole vector to the FK elbow (or anywhere along that plane) and then turn the IK blend to full?
Leffler
07-06-2008, 02:56 PM
Hello Jordan,
Yes, that is pretty much what I want to do. For the poleV i´m thinking about using a hidden object that is parentC to the shoulder joint and then snap the pv to that object when going back to IK. that should get the poleV in the right place I think.
But ... i don´t know how to set this up. My idea was to use a "bufferGroup" on the FKcontrollCurve, and then parent Constrain them to the joints .... but then it´s a "cycle" and Maya freaks out.
So the other way would be with scripting. So maybe if I use bufferGroups for the controllers and then do a script something like this ....
if(ikHandle.ikBlend<0.001)
{
bufferGroup.rotateX = jointName.rotateX;
}
... but it doesnt work at all. Maya crashes all the time ... I guess you cannot match the rotation of a joint and a curve, right?
Wow, I hope there is an easy solution for this :scream:
// Otto
jsantell
07-06-2008, 03:09 PM
If you have the FK controllers in a group, you should be able to just match the rotations.. parenting shouldn't be necessary, as if the rotations are correct, they'll all be in the correct location.
With the expression driving the location, I'd think a rotation is a rotation is a number and it should work? Not sure on that one. For my FKtoIK snap I have a script in a hotbox with this:
setAttr ($shoulder + "_FK_CNTRL.rx") `getAttr ($shoulder + "_IK.rx")`;
Snapping the FK shoulder controller's X rotation to the current X rotation of the IK shoulder joint, and so forth for other joints and rotations. This is only called when I use the script, as opposed to when the blend is full one way or another, so may not be what you want, but it's what worked for me so hopefully helps you in one way or another! :)
Leffler
07-06-2008, 07:18 PM
Hey man, thanks again
What I´ve come up with now is a system(from rigging101.com) where i can blend between IK and FK and then snap the controllCurve for the IK so it lines up perfectly with the arm animated in FK-mode. I can also move the 3 fk-controllCurves to line up with the IK if i have animated with IK but it´s kind of a pain soooo...
... i guess i need to do some scripting now ;)
But i´m not very comfterble with MEL yet, so my first question is: Where should that code you gave me be inserted? Straight into the script editor or on some of the controllers chanells?
Uploading my testfile if anyone wants to have a look....
// Otto
mlefevre
07-07-2008, 12:37 AM
You can write your script code in the script editor, then go to file > save script.
Sean Nolan has made a great tutorial for ik/fk snapping here --> http://www.snolan.net/
Good luck!
Leffler
07-08-2008, 06:27 PM
Hello guys, still can´t figure it out :twisted: Thanks Matt for the link, it was a good tutorial but still not the awesome autosnapping i´m looking for .... he did it manually.
I´m working on a very small script to I think should work but hey ... my scriptings isn´t superb in MEL
Heres what it looks like very roughly. This is for snapping the 2 IK controllers to the fk arm
float $ikSwitchValue = getAttr(”ikSwitcher.IKFK”);
if($ikSwitchValue <0.001)
{
float $poleVectorFKlocator = getAttr(“poleVectorFKlocator.pos”);
setAttr(“poleVector.pos”, $poleVectorFKlocator);
float $FKwristJoint= getAttr(“FK_wrist.pos”);
setAttr(“ikArmControll.pos”, $ FKwristJoint);
}
What I like the code to do .... check if the IK-blender is less than 0.001 then I know IK is activated and then I want to move my IKpolevector to the FKpolevectorLocater. And also get the translation & rotation values of the fk-wristcontroller and insert those values to the IKarmcontroller. That is all I need to get the arm in the right place.
But the problems are:
# What code should I write to get the translation & rotation of something? I guess .pos is wrong .... ?
# How do I get this code to be activated everytime the IK-blender goes below 0.001 ?
Wow, this is kind of frustrating me right now :D
Cheers, Otto
mlefevre
07-08-2008, 08:02 PM
Hi Otto,
To get the translations and rotations of an object you could use:
float $FKctrlRotation[] = `xform -query -worldSpace -rotation FKWristJoint`;
float $FKctrlTranslation[] = `xform -query -worldSpace -translation FKWristJoint`;
You could then place those values into another object using:
xform -worldSpace -rotation $FKctrlRotation[0] $FKctrlRotation[1] $FKctrlRotation[2] ikArmControl;
xform -worldSpace -translation $FKctrlTranslation[0] $FKctrlTranslation[1] $FKctrlTranslation[2] ikArmControl;
Leffler
07-09-2008, 12:46 PM
Matt, thanks alot for the code! Helped me alot.
So now then blending and snapping works, woho :cool:
Here is my code so far:
//snap FK controllers to IKjoints
float $ikShoulderFloat[] = `xform -query -worldSpace -rotation shoulderIK`;
xform -worldSpace -rotation $ikShoulderFloat[0] $ikShoulderFloat[1] $ikShoulderFloat[2] shoulderFKctrl;
float $ikElbowFloat[] = `xform -query -worldSpace -rotation shoulderIK|elbowInnerIK`;
xform -worldSpace -rotation $ikElbowFloat[0] $ikElbowFloat[1] $ikElbowFloat[2] elbowFKctrl;
float $ikWristFloat[] = `xform -query -worldSpace -rotation shoulderIK|elbowInnerIK|elbowOuterIK|forearmIK|wristIK`;
xform -worldSpace -rotation $ikWristFloat[0] $ikWristFloat[1] $ikWristFloat[2] wristFKctrl;
// snap IK armController + poleVector to the fk controller + locator
//pole vector
float $fkPvRotationFloat[] = `xform -query -worldSpace -rotation fkPoleVector`;
float $fkPvTranslationFloat[] = `xform -query -worldSpace -translation fkPoleVector`;
xform -worldSpace -rotation $fkPvRotationFloat[0] $fkPvRotationFloat[1] $fkPvRotationFloat[2] poleVectorIK_test;
xform -worldSpace -translation $fkPvTranslationFloat[0] $fkPvTranslationFloat[1] $fkPvTranslationFloat[2] poleVectorIK_test;
//armController snap + rotation
float $fkWristLocationFloat[] = `xform -q -ws -t wristFK_test`;
move -ws -rpr $fkWristLocationFloat[0] $fkWristLocationFloat[1] $fkWristLocationFloat[2] armControllerIK_test;
float $getFKshoulderRotationFloat[] = `xform -query -worldSpace -rotation shoulderFK_test`;
xform -worldSpace -rotation $getFKshoulderRotationFloat[0] $getFKshoulderRotationFloat[1] $getFKshoulderRotationFloat[2] armControllerIK_test;
float $getFKelbowRotationFloat[] = `xform -query -worldSpace -rotation elbowInnerFK_test`;
xform -worldSpace -rotation $getFKelbowRotationFloat[0] $getFKelbowRotationFloat[1] $getFKelbowRotationFloat[2] armControllerIK_test;
float $getFKwristRotationFloat[] = `xform -query -worldSpace -rotation wristFK_test`;
xform -worldSpace -rotation $getFKwristRotationFloat[0] $getFKwristRotationFloat[1] $getFKwristRotationFloat[2] armControllerIK_test;
So whats left is to get it to automaticly snap. Any ideas on how to?
What I want is to have snap the FKcontroller to the IK when the blender is less than 0.001 and have it snap the IK controllers to the FKs when its more than 9.999.
Can a have a script driven by a Set Driven Key? Or do I have to include an if-statement? And if so, how do I get Maya to "listen" to that script when the slider is above 9.999 or below 0.001 ??
The script and mayafile is attached if anyone wants to test it out ...
// Otto
CGTalk Moderation
07-09-2008, 12:47 PM
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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.