getKeyframeTrackValues method

dynamic getKeyframeTrackValues(
  1. dynamic times,
  2. Map curves,
  3. dynamic initialValue
)

Implementation

getKeyframeTrackValues( times, Map curves, initialValue ) {

	var prevValue = initialValue;

	var values = [];

	var xIndex = - 1;
	var yIndex = - 1;
	var zIndex = - 1;


	times.forEach( ( time ) {
		if ( curves["x"] != null ) xIndex = curves["x"]["times"].toList().indexOf( time );
		if ( curves["y"] != null ) yIndex = curves["y"]["times"].toList().indexOf( time );
		if ( curves["z"] != null ) zIndex = curves["z"]["times"].toList().indexOf( time );

		// if there is an x value defined for this frame, use that
		if ( xIndex != - 1 ) {

			var xValue = curves["x"]["values"][ xIndex ];
			values.add( xValue );
			prevValue[ 0 ] = xValue;

		} else {

			// otherwise use the x value from the previous frame
			values.add( prevValue[ 0 ] );

		}

		if ( yIndex != - 1 ) {

			var yValue = curves["y"]["values"][ yIndex ];
			values.add( yValue );
			prevValue[ 1 ] = yValue;

		} else {

			values.add( prevValue[ 1 ] );

		}

		if ( zIndex != - 1 ) {

			var zValue = curves["z"]["values"][ zIndex ];
			values.add( zValue );
			prevValue[ 2 ] = zValue;

		} else {

			values.add( prevValue[ 2 ] );

		}

	} );

	return values;

}