buildAnimationChannel method

Future<Map<String, dynamic>> buildAnimationChannel(
  1. Map<String, dynamic> channel,
  2. dynamic inputSource,
  3. dynamic outputSource
)

Implementation

Future<Map<String, dynamic>> buildAnimationChannel(Map<String,dynamic> channel, inputSource, outputSource ) async{
  final node = library['nodes']![ channel['id'] ];
  final object3D = await getNode( node['id'] );

  final transform = node['transforms'][ channel['sid'] ];
  final defaultMatrix = node['matrix'].clone().transpose();

  var time, stride;

  final Map data = {};

  // the collada spec allows the animation of data in various ways.
  // depending on the transform type (matrix, translate, rotate, scale), we execute different logic

  switch ( transform ) {
    case 'matrix':
      for (int i = 0, il = inputSource['array'].length; i < il; i ++ ) {
        time = inputSource['array'][ i ];
        stride = i * outputSource['stride'];

        if ( data[ time ] == null ) data[ time ] = {};

        if ( channel['arraySyntax'] == true ) {
          final value = outputSource['array'][ stride ];
          final index = channel['indices'][ 0 ] + 4 * channel['indices'][ 1 ];

          data[ time ][ index ] = value;
        } else {
          for ( int j = 0, jl = outputSource['stride']; j < jl; j ++ ) {
            data[ time ][ j ] = outputSource['array'][ stride + j ];
          }
        }
      }
      break;

    case 'translate':
      console.warning( 'ColladaLoader: Animation transform type "$transform" not yet implemented. ');
      break;
    case 'rotate':
      console.warning( 'ColladaLoader: Animation transform type "$transform" not yet implemented.' );
      break;
    case 'scale':
      console.warning( 'ColladaLoader: Animation transform type "$transform" not yet implemented.' );
      break;
  }

  final keyframes = prepareAnimationData( data, defaultMatrix );

  final animation = {
    'name': object3D.uuid,
    'keyframes': keyframes
  };

  return animation;
}