Soft IK in XSI, Part II – Stretchy bones

August 16th, 2006 by Andy Nicholas - Viewed 78881 times -




When I wrote the first article, I hadn’t planned on writing a sequel, but a couple of people on XSIBase asked me to look into how I could extend the Soft IK system to work with a stretchy bone chain.

Initially, figuring out how this could work seems like a pretty tricky problem. The bone chain needs to stretch intuitively to give the impression that it’s stuck to the IK effector. But we also need it to flatten gradually to avoid the snap effect. Unfortunately, the only thing we have available to us to control these two effects, is the ability to change the length of the bones, since the end position of the chain must always be located at the effector.

So we need to scale the bones to allow them to stretch, but at a specific rate to make sure we avoid the snap. Like this:

Stretchy Soft IK

The first thing to do is to look at how we solved the problem for the non-stretchy bone chain. When we look at what happens when we move the Soft Effector past the point where it starts to leave the original IK effector behind, all we want to do for the stretchy bone chain system is make sure that the bone chain gets longer so that the original IK effector is at the same position as the Soft Effector. But we need to do this while also keeping the bones angles the same, this avoids the snap effect since the bone angles would change at exactly the same rate as in the non-stretchy bone chain system.

A diagram should make things a bit clearer. Basically, given a non-stretchy chain, we want to match the position of the two effectors by scaling the chain length, but without changing the bone angles, like this:

Scaling the Soft IK chain

Okay, so that doesn’t seem too hard. We just need to figure out how much to move the IK Effector to match the position of the soft effector.

The only way we can do this is by changing the length of the bone chain. Again, this initially looks like quite a tricky problem, until you realize that scaling the length of each bone by some value X, also scales the distance of the original IK effector from the IK root by a factor of X as well. A simple test proves it (and it can be easily shown with a little math too):

Scaling bone lengths

This diagram shows a bone chain with bones of different lengths, before and after I scaled each individual bone length by a factor of 2. It can be seen that the IK effector has traveled directly away from the IK root and has doubled it’s distance from it. Not only that, but the bone angles have remained unchanged. This is exactly what we need!

Now, all we need to do is to figure out the amount we need to scale each bone length to make the original IK effector match the position of the soft effector. That scale factor is just the ratio of the distances of the two effectors:

Scale Factor = EvalDistance(IK root, Soft Effector) / EvalDistance(IK root, original IK effector)

Where EvalDistance() is just a function that measure the distance between the two objects.

Finally, we need to position constrain the original IK effector to the soft effector, so that it follows it. Otherwise, all that would happen is that the length of the chain would change.

So that’s it, we’re there. All that remains is to package it all up into a plugin with a handy custom property to drive it all. This is what the new property page looks like:

Stretchy Soft IK PPG

The bone lengths can be adjusted (and even animated) from this PPG, as well as the Soft Distance parameter, which behaves in exactly the same way as in the non-stretchy Soft IK. The bone lengths are all driven from this PPG using expressions. Note, that for extra performance we only have one Scripted Operator here which operates on the BoneScale parameter of the PPG.

I’ve updated the original Soft Effector script to include a new menu item to apply the Stretchy Bone Soft IK system to any chain you select.

Soft Effector Download (3Kb)

Incidentally, if you ever want to remove the Soft IK (stretchy or otherwise) from a bone chain. All you have to do is delete the Soft Effector object. All the expressions and operators will be automatically deleted since they will have lost their connections. Nice and tidy!

P.S. Thanks to Daniele Niero for suggesting I cache the math objects inside the operator user data!

49 Responses to “Soft IK in XSI, Part II – Stretchy bones”

  1. [...] thoughts behind XSI in production…

    « Mapping Lights Soft IK in XSI, Part II – Stretchy bones » Soft IK in XSI August 14th, 2006 by Andy Nichola [...]

  2. Markus Daum says:

    “Nice and tidy!”

    That”s exactly what it is! ;-) Thanks for this, I”m sure this will find its way into many rigs soon… (am I right Simon…? ;-) ) I also really like your way of explaining your thoughts, makes it a breeze to follow along.

    Cheers!
    Markus

  3. Daniele Niero says:

    No problem Andy! This tool is great and it fixes an annoing problem too often ignored, I can”t wait to introduce it in my rigs, I”m really sure the animators will love it.

    BTW my surname is Niero :)

  4. Hi Dan, name correction noted and changed (just to make it look like you”re complaining about nothing! :) ).

  5. Helge Mathee says:

    This is fantastic. Simple and easy to use, great results!

  6. Kris says:

    Awesome, thanks Andy. I saw this type stuff demoed last year at Siggraph during the Madagascar making of sketch and thought how great it would be to do it in XSI. Thanks again.

  7. Mario Reitbauer says:

    Excellent !
    This will be included in my next project.

    It”s so simply to use and works perfect. Really nice work !

  8. Leonardo says:

    Thanks a lot Andy! Even for a beginner like myself, this tool is extremely helpful.

  9. luz says:

    Listen do you have idea how to create rolls divison for a bone chain of
    4 bones ? and lets says I need 4 rolls division for each bone.
    If you know how to to do that, can you describe it step by step ?

  10. Mario Reitbauer says:

    I have a question too. Would it be possible to apply this stretchy effector scope on the chain effector instead of the controller object ? Because at the moment FK isnt working anymore.

  11. Mario Reitbauer says:

    Sorry there was an failure in my thinking. The object is needed to calculate the soft IK. So this is something completly different. Hmm I need a stretchy eff without soft IK ;) Should be possible to write this on my own ;)

  12. Thanks for your comments everyone.

    Hi Mario, yes it should be easy to add in stretchy bones to a basic chain. You just need to set an expression on each bone length parameter to modify it with the distance of the effector from the root.

    If you download the soft IK tool, have a look at the scripted operator that I put on the bone scale parameter of the custom property. It should be trivial to remove the SoftIK part of it and to change the calculation of the stretchyness to work with the IK effector instead of the controller object. Using a single scripted operator on this parameter is a handy thing to do, since you only have to calculate the bone scaling for the chain once (as opposed to having to set up similar expressions on each bone length parameter). You then just need to apply expressions to each bone to scale it”s original length.

    Hi Luz, yes, from what you”ve described I have a basic idea, but I”d have to give it a go. Maybe I”ll post a blog up here if I have time to figure something out.

  13. kidult one says:

    Any reason why I can”t scale my rig once the stretchy-soft-effector is applied? I scale it on the global srt but the soft-bones scale unevenly? I tried to 1st scale it and then apply the effector but it seems to take the original bone size/scale and I get the same effect as before. I tried re-adjusting the bones with the joint tool, even the kinematics don”t help?

  14. I”m afraid that the Soft IK system wasn”t originally written to take into account a scaled rig. I”m sure it could be modified to work though, but I just don”t have time to look at it at the moment. Off the top of my head, you”d probably need to divide the bone scale parameter by your rig scaling factor, but there are probably other side effects that I haven”t thought of.

    All the operators and expressions are fully editable, so you should be able to make any modifications yourself.

  15. kidult one says:

    Well sadly I”m a beginner with XSI so my scripting / expression knowledge is such that I could not work it out. Thank you though for the great plug!

  16. George says:

    Is there any reason i get this error message when trying to use this script?:
    //ERROR : Object doesn”t support this property or method – [line 192]
    //ERROR : 2006-ApplyStretchySoftEffector – Unexpected failure.
    ApplyStretchySoftEffector();
    I”m using XSI version 4.2 is that makes any difference?

  17. Yes it does make a difference I”m afraid. I”m using several methods and enums that weren”t around in the old 4.2 SDK. Luckily, it”s easy enough to make it work.

    You need to do the following:

    Comment out lines 192 through to (and including) line number 196, and also comment out line number 209. These lines are just about error checking and making the soft effector null into a particular shape.

    You also need to delete every occurance of the text “|siKeyable”. Make sure you delete the “OR” operator in front of it too, otherwise you”ll get another error.

    If you want to get the non-stretchy soft IK to work too, then you”ll need to do a similar operation. This time, you need to comment lines 57 – 61 and line 84.

    Failing all of that, drop me an email and I”ll send it to you. Can”t say fairer than that :-)

  18. George says:

    Wow, thanks for the help! Worked a treat I must say, bloody brilliant! 100 thank you”s :D

  19. Newbie says:

    how do i get the PPG to display ?
    don”t seem to get the Bone scale and bone length setting in my display ?

    when i select the Orange C under the Softeffector all i get is chain length and Soft distance ?

    I double checked I”m sure i have Part 2”s script not part one …

  20. Just to clear up any confusion…. Part 2”s script is actually an updated version of part 1”s. The links from both articles point to the same file which contains two plugins for Soft IK – one which is stretchy, and one that”s not.

    It sounds like you”re selecting the non-stretchy version from the menu. Have you noticed that there are two Soft IK menu options? It sounds like you”re after the stretchy version.

  21. Newbie says:

    sorry i feel dumb

    I drop the script into the XSI interface Where does the 2 soft IK menu options appear ?

    at the moment I dropped the script to a Custom shelf when i select the bone chain and run the script
    I only get 2 options and no strechy options.

    Missing something simple Sorry =(

  22. Newbie says:

    Sorry worked it out =)
    I must say there afew different ways to install and uses plugin in XSI
    any doc”s to explain all the different systems in there ?

  23. Glad you got it working. :)

    I don”t think there”s any article that gives a good overview of the different ways to install and use plugins in XSI. But it”s not a bad idea for a future blog.

    You can always take a look at the SDK docs, but they give a lot of detail that you probably don”t want to know about.

  24. Newbie says:

    I noticed when i started up today the plugin needed to be installed again ?
    coming from Lightwave a simple explaination of the XSI plugin system would be nice
    there”s alot more to it in XSI then LW =)

    but I”ll read the SDK doc”s when i hit something else i don”t understand

    Ok THanks big time for the time taken and the great plugin,. this is really COOL =)

  25. LUZ says:

    Hi again..listen I don”t have idea how to install the addon ( script )
    Im try to animate a whale fish fin, and I think It coulb be interesting try your SOFT IK script, but I don”t have idea how to install it.

    Remember my friends somes users like me don”t have idea how to use SDK or whatever, we ”re only ” mortal ” users, and we need PPG for all, because we ”re artist, not programmers :)
    Well thank you for all..and I wait for a possitive answer and solution

  26. I”ve noticed there is a bit of confusion about how to install this script. If you read Soft IK Part 1, you can find installation instructions at the bottom, but I”ll repeat them here too for your convenience. If I get a chance, I”ll go back and modify this blog too.

    - – - –

    To install the plugin, just download the zip file, unzip the script, and copy it to a “Plugins” folder. So for example, you can use your “C:\ users \ \ Softimage \ XSI \ Application \ Plugins” folder, or one in your workgroup.

    To use the Soft Effector, create a 2D or 3D Skeleton Chain, select any part of the chain, and go to “Model->Create->Skeleton->Apply Soft Effector”. To use the Stretchy version of Soft IK, you should use the “Apply Stretchy Soft Effector” menu option instead.

  27. kay says:

    sorry, why can”t scale?

  28. You can”t scale because the bone length is controlled by the soft effector. You could always try constraining the position of the soft effector to another object which you then scale to get the effect you”re after.

  29. Kay says:

    i make a BoneScale , but . i can”t Scale root / (all Scale) . because no stay in shape, can you help pls. thank you

  30. Erklaerbar says:

    haha this is sweet. Having a lot of fun with it! Many thanks!

  31. 'stoph says:

    Hi Andy!
    Really love your tool, have been waiting for something like this since the good old Soft 3.x days. :-)
    There’s one problem though, as soon as I turn on motion blur (XSI 6), I get the following error message:

    ‘ ERROR : ‘rootpos’ is null or not an object- [ line 11 ]
    ‘ ERROR : 2190 – The scripted operator connected to StretchySoftEffector.StretchySoftEffector.BoneScale produced a runtime error during its evaluation and will no longer be evaluated.

    From then on, the bones don’t stretch properly anymore, and the scene is pretty much screwed.
    When I set the motion steps transform to 2 and then back to 1, it sometimes renders correctly (but the geometry in the viewport is still screwed up.

    Can you please help me with that?
    Thanks & keep up the great work!
    ‘stoph

  32. RichV says:

    Hi,

    Great plugin. I just have the same problem as ‘stoph.

    Im using 6.01 and motion blur doesnt seem to work with the soft ik.

    Cheers :)

  33. EricTRocks says:

    Hey,

    I know how to do a bit of simple scripting and setting up custom parameters but, how would I make it so I could setup a slider where if set to 1 I could stretch the chain, when set to 0 I could only stretch it to the normal max distance from the root when it was first created?

    Thanks,
    Eric T.

  34. Norv Maples says:

    small discusion on a XSI 6.0.1 fix here…

    http://www.xsibase.com/forum/index.php?board=11;action=display;threadid=31156;start=5

    with “Squid” comming up with this code that seems to address the problem if not a complete fix of it…

    var obj; // = In_UpdateContext.UserData;
    // if(obj==null)
    // {
    obj = new Object();
    obj.rootpos = XSIMath.CreateVector3();
    obj.effpos = XSIMath.CreateVector3();
    obj.targetpos = XSIMath.CreateVector3();
    obj.diffpos = XSIMath.CreateVector3();
    obj.xform = XSIMath.CreateTransform();
    //In_UpdateContext.UserData=obj;
    // }

    Anyway I thought It might be good to have this posted directly here….

    Norv

  35. Sorry, I replied to ‘stoph’s query via email instead of posting here. Basically, the solution is to plot everything if you ever have a problem rendering with motion blur. It seems to be an issue introduced with XSI 6 as far as I can tell.

    Eric, I’ll have to have a think about that one! I’ll get back to you. Apologies for not responding earlier, I haven’t checked the comments on this post for a while.

    Cheers

    Andy

  36. Oh, and don’t forget to plot the bone length parameters too!

  37. Michal says:

    Fantastic – solved all my “pop” problems in a horse rig I made – I retrofitted it to all the rigs I currently use.

    Thank you!

  38. Pete says:

    Hi there Andy, I have just been checking out your soft ik stuff and it is great :) thankyou!

    I was just wondering though, if you had looked at Erics issue at all? It would be great if you could ad a slider that stopped the stretchy bone from being stretchy, I don’t know if that would be way too much of a mission but it’s something I think is pretty handy in a stretchy rig.

  39. Pete says:

    Oh, weird, if you put both the ‘soft effector’ and the ‘stretchy soft effector’ on the same bone chain you can blend from one to the other by adjusting the blend wieght on the end effecters position constraint. The only issue (which is a slightly large one) is that the bone length is still adjusted bu the ‘soft stretchy’ effectors distance from the root.
    hmm, getting closer though. maybe?

  40. hy andy, thanx a lot. this is really an amazing tool.
    we (http://www.xsibase.com/forum/index.php?board=11;action=display;threadid=34367;start=0#lastPost) have been trying to compensate the scaling by a Global_SRT, in other to have it working on a scalable rig. from a first glance i believe the “boneScale” should be divided by (1 / Global_SRT.(scale)Value ), but i am not being able to access it from the scoop. does it seem like a right way to go? any other ideas?
    thanx again!

  41. Hi guys. Don’t know if you solved your various problems but from now on could you send any inquiries to me directly via http://www.andynicholas.com. I don’t seem to get any alerts to new posts here.

    Thanks :-)

    Andy

  42. Matt says:

    I hope somebody still checks this thread from time to time. this looks really cool but Ive managed to screw up the installation somehow; when I install the plug-in (and after that if I try to look at its properties or anything) I get an error saying it causes conflict with a plug-in with the same name and of the same type. which sounds like Im trying to install it twice or two different versions. but there is only the one, its the only one showing up in the plug-in manager. I tried deleting it and doing it over but it doesnt help. every time I install it I get this message. anyone had a similar experience and how do you fix it??
    I’m using 6.5.
    thanks for all your good work andy! cheers /matt

    (didnt want to bother you with an e-mail)

  43. sebastien says:

    Hi !
    I’ve been using this plugin for a long time now, very useful !!
    But i’m still trying to disable the stretchy effect with a slider whenever i don’t need it.
    Anybody managed to do that ?

    Thanks

  44. faerton says:

    Sebastian:

    “But i’m still trying to disable the stretchy effect with a slider whenever i don’t need it.
    Anybody managed to do that ?

    Thanks”

    I need that too ! Please can anyone manage that ?

    best regards!

  45. baris says:

    Hi anyone
    I want to ask something
    I am trying to use Strechy Soft Effector plug in but it doesnt work very vell or I am wrong….

    I parented object to bone ( bone is parent, object is child ) then When I change to StretchySoftEffector z position bone is scaling but object isnt scaling

    check links:
    http://www.shortcutdesign.com/1.JPG
    http://www.shortcutdesign.com/2.JPG

    when bone streching I want to object streching like bone

    how can I do that
    sorry my english

    best regards….

  46. david says:

    Is it possible tu turn these functions on and off for a FK chain?

  47. Sias says:

    Awesome tool. Why isn’t this intergrated in Softimage?

  48. efecte speciale…

    [...]Softimage Blog » Blog Archive » Soft IK in XSI, Part II – Stretchy bones[...]…

  49. [...] the speed of that joint non-linearly increases as we are close to straight. Good sources here and here (softimage blog). My solution for non stretchy is exactly the same as that blog post- plugging the [...]