AnimationLoader.js 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { AnimationClip } from '../animation/AnimationClip.js';
  2. import { FileLoader } from './FileLoader.js';
  3. import { Loader } from './Loader.js';
  4. class AnimationLoader extends Loader {
  5. constructor( manager ) {
  6. super( manager );
  7. }
  8. load( url, onLoad, onProgress, onError ) {
  9. const scope = this;
  10. const loader = new FileLoader( this.manager );
  11. loader.setPath( this.path );
  12. loader.setRequestHeader( this.requestHeader );
  13. loader.setWithCredentials( this.withCredentials );
  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( 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号