Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Skin animation setup script
- # Written by DiFFtY (diffty@gmail.com), inspired by Miek's cloaking script (https://github.com/miek/sfm_scripts/tree/master/setup_cloaking)
- # This script allows you to create a new channel in an Animation Set to control the skin number of a game model.
- #
- # Usage : Right click on a model Animation Set, go to Rig -> Load Rig Script, then open this .py
- #
- # Tested on SFM 0.9.7.6, 10/05/2013
- import vs
- def SetupSkin():
- # Get the currently selected animation set and shot, and the corresponding gamemodel
- shot = sfm.GetCurrentShot()
- animSet = sfm.GetCurrentAnimationSet()
- gameModel = animSet.gameModel
- # Creating the control group
- controlGroup = animSet.FindOrAddControlGroup(animSet.GetRootControlGroup(), "Skin")
- # Creating the control in the animation set
- skinControl, skinValue = sfmUtils.CreateControlledValue("skin", "value", vs.AT_FLOAT, 0.0, animSet, shot)
- controlGroup.AddControl(skinControl)
- # Creating an operator/expression, to adapt the 0.0 -> 1.0 float information provided by the slider to a 0 -> number of skins in the gamemodel
- expression = sfmUtils.CreateExpression("skin_rescale", "floor(lerp(value, lo, hi))", animSet)
- expression.AddAttribute("lo", vs.AT_FLOAT)
- expression.AddAttribute("hi", vs.AT_FLOAT)
- expression.SetValue("hi", gameModel.GetSkinCount()-1)
- expression.AddAttribute("value", vs.AT_FLOAT)
- # Connecting the normalized slider user-provided info to the expression
- skinControl.channel.SetOutput(expression, "value")
- # Creating the second channel, which take the result of the expression and assign it to the gamemodel skin info
- rescaleChannel = sfmUtils.CreateChannel("rescaled_skin_channel", vs.AT_FLOAT, 0., animSet, shot)
- rescaleChannel.SetInput(expression, "result")
- rescaleChannel.SetOutput(gameModel, "skin")
- # Removing keyframes from the second channel
- # (to avoid the default blank key (added in the CreateChannel() function) to override ones from the first channel, which are the ones set by the user)
- for i in range(0, rescaleChannel.log.GetKeyCount()):
- rescaleChannel.log.RemoveKey(0)
- return
- #==================================================================================================
- # Script entry
- #==================================================================================================
- # Setup skin channel for the selected animation set
- SetupSkin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement