Advertisement
Sim_Piko

setup_skin_animation.py

Jun 14th, 2014
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.47 KB | None | 0 0
  1. # Skin animation setup script
  2. # Written by DiFFtY (diffty@gmail.com), inspired by Miek's cloaking script (https://github.com/miek/sfm_scripts/tree/master/setup_cloaking)
  3. # This script allows you to create a new channel in an Animation Set to control the skin number of a game model.
  4. #
  5. # Usage : Right click on a model Animation Set, go to Rig -> Load Rig Script, then open this .py
  6. #
  7. # Tested on SFM 0.9.7.6, 10/05/2013
  8.  
  9. import vs
  10.  
  11. def SetupSkin():
  12.     # Get the currently selected animation set and shot, and the corresponding gamemodel
  13.     shot = sfm.GetCurrentShot()
  14.     animSet = sfm.GetCurrentAnimationSet()
  15.     gameModel = animSet.gameModel
  16.    
  17.     # Creating the control group
  18.     controlGroup = animSet.FindOrAddControlGroup(animSet.GetRootControlGroup(), "Skin")
  19.    
  20.     # Creating the control in the animation set
  21.     skinControl, skinValue = sfmUtils.CreateControlledValue("skin", "value", vs.AT_FLOAT, 0.0, animSet, shot)
  22.     controlGroup.AddControl(skinControl)
  23.    
  24.     # 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
  25.     expression = sfmUtils.CreateExpression("skin_rescale", "floor(lerp(value, lo, hi))", animSet)
  26.     expression.AddAttribute("lo", vs.AT_FLOAT)
  27.     expression.AddAttribute("hi", vs.AT_FLOAT)
  28.     expression.SetValue("hi", gameModel.GetSkinCount()-1)
  29.     expression.AddAttribute("value", vs.AT_FLOAT)
  30.  
  31.     # Connecting the normalized slider user-provided info to the expression
  32.     skinControl.channel.SetOutput(expression, "value")
  33.  
  34.     # Creating the second channel, which take the result of the expression and assign it to the gamemodel skin info
  35.     rescaleChannel = sfmUtils.CreateChannel("rescaled_skin_channel", vs.AT_FLOAT, 0., animSet, shot)
  36.     rescaleChannel.SetInput(expression, "result")
  37.     rescaleChannel.SetOutput(gameModel, "skin")
  38.  
  39.     # Removing keyframes from the second channel
  40.     # (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)
  41.     for i in range(0, rescaleChannel.log.GetKeyCount()):
  42.         rescaleChannel.log.RemoveKey(0)
  43.  
  44.     return
  45.    
  46. #==================================================================================================
  47. # Script entry
  48. #==================================================================================================
  49.  
  50. # Setup skin channel for the selected animation set
  51. SetupSkin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement