FCurveKey.LeftTanX

Description

Sets or returns the left tangent X (in frames) of the fcurve key relative to the FCurveKey.Time value as a Double.

The left tan x value may be a negative value between a distance which is one third the distance between 2 consecutive key and 0; this guarantees that the curve is valid.

The left tangent of the first key and the right tangent of the last key cannot be changed. If you try to set the tangent for one of these the property does nothing and returns S_FALSE in C++.

Tangent values only apply to standard function curves (where FCurve.Type = siStandardFCurve), the tangent value 0 is returned for all other function curve types defined by siFCurveType.

Examples

1. JScript Example

/*
        This example illustrates how to create an fcurve and set the tangents on a specific key
*/
// Create new scene
NewScene( "", false );
// Create a null
var nullobj = Application.ActiveSceneRoot.AddNull();
// Get the posx parameter from the null
var posx = nullobj.posx;
// Create an fcurve on posx
var fc = posx.AddFCurve2();
// Define some keys (3 key-value pairs)
var keyvalues = new Array( 0,0, 50,25, 100,50 );
fc.SetKeys( keyvalues );
// Get the 1st, 2nd & 3rd FCurveKey objects
var key0 = fc.Keys(0);
var key1 = fc.Keys(1);
var key2 = fc.Keys(2);
// Make the key non-G1 continuous so it can have different left and right values
key1.Constraint( siG1ContinuousConstraint ) = false;
key1.LeftTanX = 0;
key1.LeftTanY = Math.abs( key1.Value - key0.Value );
key1.RightTanX = key2.Time - key1.Time;
key1.RightTanY = 0;
PrintKeys( fc );
// Convenience function to print the FCurveKeys
function PrintKeys( in_fcrv )
{
        for ( var i=0; i<in_fcrv.Keys.Count; i++ ) {
                var fckey = in_fcrv.Keys(i);
                var str = "key : " + fckey.Index;
                str += "\n\ttime : " + fckey.Time;
                str += "\n\tvalue : " + fckey.Value;
                str += "\n\ttangents : " + fckey.LeftTanX + "," + fckey.LeftTanY + "," + fckey.RightTanX + "," + fckey.RightTanY;
                str += "\n\tconstraints : " + GetConstraintType( fckey );
                Application.LogMessage( str );
        }
}
// Convenience function to get the user-friendly string describing the contraint type
function GetConstraintType( in_fcrvkey )
{
        var ConstraintTypes = new Array (
                new Array (siParameterConstraint,                       "LockParameter"),
                new Array (siLeftRightValuesConstraint,                 "LeftRightParameter"),
                new Array (siG1ContinuousConstraint,                    "G1Continuous"),
                new Array (siLeftRightTangentDirectionConstraint,       "LeftRightTangentDirection"),
                new Array (siLeftRightTangentLengthConstraint,          "LeftRightTangentLength"),
                new Array (siLockConstraint,                            "LockAll"),
                new Array (siHorizontalTangentConstraint,               "HorizontalTangent"),
                new Array (siExtremumHorizontalTangentConstraint,       "ExtremumHorizontalTangent"),
                new Array (siAdjustedTangentConstraint,                 "AdjustedTangent"),
                new Array (siZeroLengthTangentConstraint,               "ZeroLengthTangent"),
                new Array (siSameLengthTangentConstraint,               "SameLengthTangent"), 
                new Array (siNeighborTangentConstraint,                 "NeighborTangent"),
                new Array (siMirrorTangentConstraint,                   "MirrorTangent"),
                new Array (siAutoPlateauTangentConstraint,              "AutoPlateauTangent") 
        )
        var str = "";
        for ( var i=0; i<ConstraintTypes.length; i++ ) {
                if ( in_fcrvkey.Constraint( ConstraintTypes[i][0] ) ) {
                        str += ConstraintTypes[i][1] + " ";
                }                
        }
        return str;
}
// Expected results:
//INFO : key : 0
//      time : 0
//      value : 0
//      tangents : -16.666666666666668,0,16.666666666666668,0
//      constraints : G1Continuous  
//INFO : key : 1
//      time : 50
//      value : 25
//      tangents : 0,25,50,0
//      constraints : 
//INFO : key : 2
//      time : 100
//      value : 50
//      tangents : -16.666666666666664,0,16.666666666666664,0
//      constraints : G1Continuous

2. VBScript Example

'
' This example illustrates how to create an fcurve and set the tangents on a specific key
' 
' Create new scene
NewScene , false 
' Create a null
set nullobj = Application.ActiveSceneRoot.AddNull()
' Get the posx parameter from the null
set posx = nullobj.posx
' Create an fcurve on posx
set fc = posx.AddFCurve2()
' Define some keys (3 key-value pairs)
keyvalues = array( 0,0, 50,25, 100,50 )
fc.SetKeys keyvalues 
' Get the 1st, 2nd & 3rd FCurveKey objects
set key0 = fc.Keys(0)
set key1 = fc.Keys(1)
set key2 = fc.Keys(2)
' Make the key non-G1 continuous so it can have different left and right values
key1.Constraint( siG1ContinuousConstraint ) = false
key1.LeftTanX = 0
key1.LeftTanY = Abs( key1.Value - key0.Value )
key1.RightTanX = key2.Time - key1.Time
key1.RightTanY = 0
PrintKeys fc 
' Convenience routine to print the FCurveKeys
sub PrintKeys( in_fcrv )
        for each fckey in in_fcrv.Keys
                str = "key : " & fckey.Index
                str = str & vbCrLf & vbTab & "time : " & fckey.Time
                str = str & vbCrLf & vbTab & "value : " & fckey.Value
                str = str & vbCrLf & vbTab & "tangents : " & fckey.LeftTanX & "," & fckey.LeftTanY & "," & fckey.RightTanX & "," & fckey.RightTanY
                str = str & vbCrLf & vbTab & "constraints : " & GetConstraintType( fckey )
                Application.LogMessage str 
        next
end sub
' Convenience function to get the user-friendly string describing the contraint type
function GetConstraintType( in_fcrvkey )
        set ConstraintTypes = CreateObject( "Scripting.Dictionary" )
        ConstraintTypes.Add siParameterConstraint,                      "LockParameter"
        ConstraintTypes.Add siLeftRightValuesConstraint,                "LeftRightParameter"
        ConstraintTypes.Add siG1ContinuousConstraint,                   "G1Continuous"
        ConstraintTypes.Add siLeftRightTangentDirectionConstraint,      "LeftRightTangentDirection"
        ConstraintTypes.Add siLeftRightTangentLengthConstraint,         "LeftRightTangentLength"
        ConstraintTypes.Add siLockConstraint,                           "LockAll"
        ConstraintTypes.Add siHorizontalTangentConstraint,              "HorizontalTangent"
        ConstraintTypes.Add siExtremumHorizontalTangentConstraint,      "ExtremumHorizontalTangent"
        ConstraintTypes.Add siAdjustedTangentConstraint,                "AdjustedTangent"
        ConstraintTypes.Add siZeroLengthTangentConstraint,              "ZeroLengthTangent"
        ConstraintTypes.Add siSameLengthTangentConstraint,              "SameLengthTangent"
        ConstraintTypes.Add siNeighborTangentConstraint,                "NeighborTangent"
        ConstraintTypes.Add siMirrorTangentConstraint,                  "MirrorTangent"
        ConstraintTypes.Add siAutoPlateauTangentConstraint,             "AutoPlateauTangent"
        str = ""
        for each k in ConstraintTypes.Keys
                if in_fcrvkey.Constraint( k ) then
                        str = str & ConstraintTypes(k) & " "
                end if
        next
        GetConstraintType = str
end function
' Expected results:
'INFO : key : 0
'       time : 0
'       value : 0
'       tangents : -16.6666666666667,0,16.6666666666667,0
'       constraints : G1Continuous  
'INFO : key : 1
'       time : 50
'       value : 25
'       tangents : 0,25,50,0
'       constraints : 
'INFO : key : 2
'       time : 100
'       value : 50
'       tangents : -16.6666666666667,0,16.6666666666667,0
'       constraints : G1Continuous

3. Python Example

#
# This example illustrates how to create an fcurve and set the tangents on a specific key
# 
from win32com.client import constants as c
# Convenience function to get the user-friendly string describing the contraint type
def GetConstraintType( in_fcrvkey ) :
        ConstraintTypes = {
                c.siParameterConstraint:"LockParameter", 
                c.siLeftRightValuesConstraint:"LeftRightParameter", 
                c.siG1ContinuousConstraint:"G1Continuous", 
                c.siLeftRightTangentDirectionConstraint:"LeftRightTangentDirection", 
                c.siLeftRightTangentLengthConstraint:"LeftRightTangentLength", 
                c.siLockConstraint:"LockAll", 
                c.siHorizontalTangentConstraint:"HorizontalTangent", 
                c.siExtremumHorizontalTangentConstraint:"ExtremumHorizontalTangent", 
                c.siAdjustedTangentConstraint:"AdjustedTangent", 
                c.siZeroLengthTangentConstraint:"ZeroLengthTangent", 
                c.siSameLengthTangentConstraint:"SameLengthTangent",
                c.siNeighborTangentConstraint:"NeighborTangent",
                c.siMirrorTangentConstraint:"MirrorTangent",
                c.siAutoPlateauTangentConstraint:"AutoPlateauTangent"
        }
        str = ""
        for k in ConstraintTypes.keys() :
                if ( in_fcrvkey.Constraint(k) ) :
                        str += ConstraintTypes[k] + " "
        return str
# Convenience function to print the FCurveKeys
def PrintKeys( in_fcrv ) :
        for fckey in in_fcrv.Keys :
                str = "key : %d" % (fckey.Index)
                str = str + "\n\ttime : %d" % (fckey.Time)
                str = str + "\n\tvalue : %d" % (fckey.Value)
                str = str + "\n\ttangents : %d,%d,%d,%d" % (fckey.LeftTanX,fckey.LeftTanY,fckey.RightTanX,fckey.RightTanY)
                str = str + "\n\tconstraints : " + GetConstraintType( fckey )
                Application.LogMessage( str )
        return None
# Create new scene
Application.NewScene( "", 0 )
# Create a null
nullobj = Application.ActiveSceneRoot.AddNull()
# Get the posx parameter from the null
posx = nullobj.posx
# Create an fcurve on posx
fc = posx.AddFCurve2()
# Define some keys (3 key-value pairs)
keyvalues = [ 0,0, 50,25, 100,50 ]
fc.SetKeys( keyvalues )
# Get the 1st, 2nd & 3rd FCurveKey objects
key0 = fc.Keys(0)
key1 = fc.Keys(1)
key2 = fc.Keys(2)
# Make the key non-G1 continuous so it can have different left and right values
# (Python can't use the Constraint property as-is, so use SetConstraint as an alias)
key1.SetConstraint( c.siG1ContinuousConstraint, 0 )
key1.LeftTanX = 0
key1.LeftTanY = abs( key1.Value - key0.Value )
key1.RightTanX = key2.Time - key1.Time
key1.RightTanY = 0
PrintKeys( fc )
# Expected results:
# INFO : key : 0
#       time : 0
#       value : 0
#       tangents : -16,0,16,0
#       constraints : G1Continuous 
# INFO : key : 1
#       time : 50
#       value : 25
#       tangents : 0,25,50,0
#       constraints : 
# INFO : key : 2
#       time : 100
#       value : 50
#       tangents : -16,0,16,0
#       constraints : G1Continuous

See Also

FCurve.SetKeyTangents FCurveKey.LeftTanY FCurveKey.RightTanY FCurveKey.RightTanX