AnimationLoader.js 982 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { AnimationClip } from '../animation/AnimationClip.js';
  2. import { FileLoader } from './FileLoader.js';
  3. import { DefaultLoadingManager } from './LoadingManager.js';
  4. /**
  5. * @author bhouston / http://clara.io/
  6. */
  7. function AnimationLoader( manager ) {
  8. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  9. }
  10. Object.assign( AnimationLoader.prototype, {
  11. load: function ( url, onLoad, onProgress, onError ) {
  12. var scope = this;
  13. var loader = new FileLoader( scope.manager );
  14. loader.setPath( scope.path );
  15. loader.load( url, function ( text ) {
  16. onLoad( scope.parse( JSON.parse( text ) ) );
  17. }, onProgress, onError );
  18. },
  19. parse: function ( json ) {
  20. var animations = [];
  21. for ( var i = 0; i < json.length; i ++ ) {
  22. var clip = AnimationClip.parse( json[ i ] );
  23. animations.push( clip );
  24. }
  25. return animations;
  26. },
  27. setPath: function ( value ) {
  28. this.path = value;
  29. return this;
  30. }
  31. } );
  32. export { AnimationLoader };