Guest User

TweenFaceStretchFeature.JS

a guest
May 27th, 2018
141
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // TweenFaceStretchFeature.js
  2. // Version: 0.0.1
  3. // Event: Any Event
  4. // Description: Runs a tween on a Lens Studio face stretch feature
  5.  
  6. //@input SceneObject sceneObject
  7. //@input string featureName
  8. //@input string tweenName
  9. //@input bool playAutomatically = true
  10. //@input int loopType = 0 {"widget":"combobox", "values":[{"label":"None", "value":0}, {"label":"Loop", "value":1}, {"label":"Ping Pong", "value":2}]}
  11.  
  12. //@ui {"widget":"separator"}
  13. //@input float start = 0.0 {"widget":"slider", "min":0.0, "max":1.0, "step":0.01}
  14. //@input float end = 1.0 {"widget":"slider", "min":0.0, "max":1.0, "step":0.01}
  15. //@input bool recursive = false
  16. //@input float time = 1.0
  17. //@input float delay = 0.0
  18. //@input bool isLocal = true
  19.  
  20. //@ui {"widget":"separator"}
  21. //@input string easingFunction = "Quadratic" {"widget":"combobox", "values":[{"label":"Linear", "value":"Linear"}, {"label":"Quadratic", "value":"Quadratic"}, {"label":"Cubic", "value":"Cubic"}, {"label":"Quartic", "value":"Quartic"}, {"label":"Quintic", "value":"Quintic"}, {"label":"Sinusoidal", "value":"Sinusoidal"}, {"label":"Exponential", "value":"Exponential"}, {"label":"Circular", "value":"Circular"}, {"label":"Elastic", "value":"Elastic"}, {"label":"Back", "value":"Back"}, {"label":"Bounce", "value":"Bounce"}]}
  22. //@input string easingType = "Out" {"widget":"combobox", "values":[{"label":"In", "value":"In"}, {"label":"Out", "value":"Out"}, {"label":"In / Out", "value":"InOut"}]}
  23.  
  24. // If no scene object is specified, use object the script is attached to
  25. if( !script.sceneObject )
  26. {
  27.     script.sceneObject = script.getSceneObject();
  28. }
  29.  
  30. // Setup the external API
  31. script.api.tweenName = script.tweenName;
  32. script.api.startTween = startTween;
  33. script.api.resetObject = resetObject;
  34. script.api.tween = null;
  35.  
  36. // Play it automatically if specified
  37. if( script.playAutomatically )
  38. {
  39.     // Start the tween
  40.     startTween();
  41. }
  42.  
  43. // Create the tween with passed in parameters
  44. function startTween()
  45. {
  46.     var startValue = {
  47.         "a": script.start
  48.     };
  49.  
  50.     var endValue = {
  51.         "a": script.end
  52.     };
  53.  
  54.     // Reset object to start
  55.     resetObject();
  56.  
  57.     // Create the tween
  58.     var tween = new TWEEN.Tween( startValue )
  59.         .to( endValue, script.time * 1000.0 )
  60.         .delay( script.delay * 1000.0 )
  61.         .easing( global.tweenManager.getTweenEasingType( script.easingFunction, script.easingType ) )
  62.         .onUpdate( updateValue );
  63.  
  64.     // Configure the type of looping based on the inputted parameters
  65.     global.tweenManager.setTweenLoopType( tween, script.loopType );
  66.  
  67.     // Save reference to tween
  68.     script.api.tween = tween;
  69.  
  70.     // Start the tween
  71.     script.api.tween.start();
  72. }
  73.  
  74. // Resets the object to its start
  75. function resetObject()
  76. {
  77.     var startValue = {
  78.         "a": script.start
  79.     };
  80.  
  81.     // Initialize transform to start value
  82.     updateValue( startValue );
  83. }
  84.  
  85. // Here's were the values returned by the tween are used
  86. // to drive the transform of the SceneObject
  87. function updateValue( value )
  88. {
  89.     updateComponentValue( script.sceneObject, "Component.FaceStretchVisual", value );
  90. }
  91.  
  92. function updateComponentValue( sceneObject, componentName, value )
  93. {
  94.     for( var i = 0; i < sceneObject.getComponentCount( componentName); i++ )
  95.     {
  96.         var visual = sceneObject.getComponentByIndex( componentName, i );
  97.         visual.setFeatureWeight( script.featureName, value.a );
  98.     }
  99.  
  100.     if( script.recursive )
  101.     {
  102.  
  103.         for( var i = 0; i < sceneObject.getChildrenCount(); i++ )
  104.         {
  105.             updateComponentValue( sceneObject.getChild(i), componentName, value.a );
  106.         }
  107.     }
  108. }
RAW Paste Data