LS.Animation.Track Class
Represents one track with data over time about one property Data could be stored in two forms, or an array containing arrays of [time,data] (unpacked data) or in a single typed array (packed data), depends on the attribute typed_mode
Constructor
LS.Animation.Track
()
Item Index
Methods
Properties
- data contains all the keyframes, could be an array or a typed array
- enabled if it must be applied
- interpolation type of interpolation LS.NONE, LS.LINEAR, LS.TRIGONOMETRIC, LS.BEZIER, LS.SPLICE
- looped if the last and the first keyframe should be connected
- name title to show in the editor
- property the locator to the property this track should modify ( "node/component_uid/property" )
- type if the data is number, vec2, color, etc
Methods
addKeyframe
-
time
-
value
-
skip_replace
Adds a new keyframe to this track
Parameters:
-
time
Numbertime stamp in seconds
-
value
anything you want to store
-
skip_replace
Booleanif you want to replace existing keyframes at same time stamp or add it next to that
Returns:
index of keyframe
convertToTrans10
()
If the track used matrices, it transform them to position,quaternion and scale (10 floats, also known as trans10) this makes working with animations faster
findTimeIndex
-
time
Returns nearest index of keyframe with time equal or less to specified time (Dichotimic search)
Parameters:
-
time
Number
Returns:
the nearest index (lower-bound)
getIDasName
-
use_basename
-
root
used to change every track so instead of using UIDs for properties it uses node names this is used when you want to apply the same animation to different nodes in the scene
Parameters:
-
use_basename
Booleanif you want to just use the node name, othewise it uses the fullname (name with path)
-
root
LS.SceneNode
Returns:
the result name
getKeyframe
-
index
returns a keyframe given an index
Parameters:
-
index
Number
Returns:
the keyframe in [time,data] format
getKeyframeByTime
-
time
returns the first keyframe that matches this time
Parameters:
-
time
Number
Returns:
keyframe in [time,value]
getNumberOfKeyframes
()
returns the number of keyframes
getPropertyInfo
-
scene
returns information about the object being affected by this track based on its locator the object contains a reference to the object, the property name, the type of the data
Parameters:
-
scene
LS.Scene[optional]
Returns:
an object with the info { target, name, type, value }
getSample
-
time
-
interpolation
-
result
Samples the data in one time, taking into account interpolation. Warning: if no result container is provided the same container is reused between samples to avoid garbage, be careful.
Parameters:
-
time
Number -
interpolation
Number[optional] the interpolation method could be LS.NONE, LS.LINEAR, LS.BEZIER
-
result
[optional] the container where to store the data (in case is an array). IF NOT CONTAINER IS PROVIDED THE SAME ONE IS RETURNED EVERY TIME!
Returns:
data
getSampledData
-
start_time
-
end_time
-
num_samples
returns an array containing N samples for this property over time using the interpolation of the track
Parameters:
-
start_time
Numberwhen to start sampling
-
end_time
Numberwhen to finish sampling
-
num_samples
Numberthe number of samples
Returns:
an array containing all the samples
moveKeyframe
-
index
-
new_time
changes a keyframe time and rearranges it
Parameters:
-
index
Number -
new_time
Number
Returns:
new index
packData
()
takes all the keyframes and stores them inside a typed-array so they are faster to store in server or work with
removeKeyframe
-
index
removes one keyframe
Parameters:
-
index
Number
removeScaling
()
If this track changes the scale, it forces it to be 1,1,1
sortKeyframes
()
Sometimes when moving keyframes they could end up not sorted by timestamp, which will cause problems when sampling, to avoid it, we can force to sort all keyframes
stretch
-
scale
Scales the time in every keyframe
Parameters:
-
scale
Numberthe sacle to apply to all times
trim
-
start
-
end
removes keyframes that are before or after the time range
Parameters:
-
start
Numbertime
-
end
Numbertime
unpackData
()
takes all the keyframes and unpacks them so they are in a simple array, easier to work with