AnimationLoader.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.load( url, function ( text ) {
  15. try {
  16. onLoad( scope.parse( JSON.parse( text ) ) );
  17. } catch ( e ) {
  18. if ( onError ) {
  19. onError( e );
  20. } else {
  21. console.error( e );
  22. }
  23. scope.manager.itemError( url );
  24. }
  25. }, onProgress, onError );
  26. },
  27. parse: function ( json ) {
  28. const animations = [];
  29. for ( let i = 0; i < json.length; i ++ ) {
  30. const clip = AnimationClip.parse( json[ i ] );
  31. animations.push( clip );
  32. }
  33. return animations;
  34. }
  35. } );
  36. export { AnimationLoader };
粤ICP备19079148号