AnimationLoader.js 1.1 KB

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