Posts Tagged ‘softimage

21
Jan
12

FCurves Interpolation

Hi, for our next tool, we’ll learn how to change the interpolation style on FCurves. This can be really useful when you want to move from blocking to first pass, I use it all the time when working on shots. We’ll need to build a list of the transform parameters (if you’re wondering where you can find those or how to properly write them, just select any object in your scene and go through the sdk explorer View–Scripting–SDK Explorer / Ctrl+Shift+4, once there go into the Parameters section, find the parameters you want and look in the scriptname column). We’ll also need to lock the current selection so that no matter what we do, the script will remember which items were selected when we pressed the button, to do that we’ll use a tuple to store the list permanently (Application.Selection is dynamic, so the script could forget what was used in the beginning).

xsi = Application
parameters = ["posX", "posY", "posZ", "rotX", "rotY", "rotZ", "sclX", "sclY", "sclZ"]
selection = tuple(xsi.Selection)

Next, we’ll go through each of our selected items, loop through their parameters and check if they’re keyable. If they are we’ll grab their FCurves (if they exist) and change the interpolation type

1 = Constant (step)
2 = Linear
3 = Spline

for item in selection:
	for param in parameters:
		parameter = item.kinematics.local.Parameters(param)
		if parameter.Keyable:
			fcurve = parameter.Source
			if fcurve != None:
				fcurve.Interpolation = 1

Now, we could replicate the script and change the value and have one button for each type of interpolation OR, we could add a little trick to change the behavior of the button depending on what key (shift, ctrl, alt) the user is pressing when he clicks the button.

To be able to do that, you’ll need to know what is pressed and the way to do that is through the GetKeyboardState function. Look for it in the manual, experiment with it, try out different combos, have fun with it.

ks = xsi.GetKeyboardState()

shift = 1
ctrl = 2

if ks(1) == shift:
	interpolation = 1
elif ks(1) == ctrl:
	interpolation = 2
else:
	interpolation = 3

So in the end, our code could look something like this:

## This script switches the interpolation of the selected object's transformation FCurves.
## Hold Shift while running the script to switch the FCurves to constant
## Hold Ctrl while running the script to switch the FCurves to linear
## Hold anything else or nothing at all while running the script to switch the FCurves to spline

xsi = Application
parameters = ["posX", "posY", "posZ", "rotX", "rotY", "rotZ", "sclX", "sclY", "sclZ"]
selection = tuple(xsi.Selection)
ks = xsi.GetKeyboardState()

shift = 1
ctrl = 2

if ks(1) == shift:
	ipl = 1
elif ks(1) == ctrl:
	ipl = 2
else:
	ipl = 3

for item in selection:
	for param in parameters:
		parameter = item.kinematics.local.Parameters(param)
		if parameter.Keyable:
			fcurve = parameter.Source
			if fcurve != None:
				fcurve.Interpolation = ipl

In this example, the default interpolation will be Spline. If you run the script while pressing shift, it will switch the keys to constant interpolation, ctrl will switch it to linear, anything else (including nothing) will give you splines.




Enter your email address to follow this blog and receive notifications of new posts by email.

Join 5 other subscribers