AnimationLoader.js 1.1 KB

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