AnimationLoader.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { AnimationClip } from '../animation/AnimationClip.js';
  2. import { FileLoader } from './FileLoader.js';
  3. import { Loader } from './Loader.js';
  4. /**
  5. * @author bhouston / http://clara.io/
  6. */
  7. function AnimationLoader( manager ) {
  8. Loader.call( this, manager );
  9. }
  10. AnimationLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  11. constructor: AnimationLoader,
  12. load: function ( url, onLoad, onProgress, onError ) {
  13. const scope = this;
  14. const loader = new FileLoader( scope.manager );
  15. loader.setPath( scope.path );
  16. loader.setRequestHeader( scope.requestHeader );
  17. loader.load( url, function ( text ) {
  18. try {
  19. onLoad( scope.parse( JSON.parse( text ) ) );
  20. } catch ( e ) {
  21. if ( onError ) {
  22. onError( e );
  23. } else {
  24. console.error( e );
  25. }
  26. scope.manager.itemError( url );
  27. }
  28. }, onProgress, onError );
  29. },
  30. parse: function ( json ) {
  31. const animations = [];
  32. for ( let i = 0; i < json.length; i ++ ) {
  33. const clip = AnimationClip.parse( json[ i ] );
  34. animations.push( clip );
  35. }
  36. return animations;
  37. }
  38. } );
  39. export { AnimationLoader };