LoadingManager.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. function LoadingManager( onLoad, onProgress, onError ) {
  5. var scope = this;
  6. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  7. this.onStart = undefined;
  8. this.onLoad = onLoad;
  9. this.onProgress = onProgress;
  10. this.onError = onError;
  11. this.itemStart = function ( url ) {
  12. itemsTotal ++;
  13. if ( isLoading === false ) {
  14. if ( scope.onStart !== undefined ) {
  15. scope.onStart( url, itemsLoaded, itemsTotal );
  16. }
  17. }
  18. isLoading = true;
  19. };
  20. this.itemEnd = function ( url ) {
  21. itemsLoaded ++;
  22. if ( scope.onProgress !== undefined ) {
  23. scope.onProgress( url, itemsLoaded, itemsTotal );
  24. }
  25. if ( itemsLoaded === itemsTotal ) {
  26. isLoading = false;
  27. if ( scope.onLoad !== undefined ) {
  28. scope.onLoad();
  29. }
  30. }
  31. };
  32. this.itemError = function ( url ) {
  33. if ( scope.onError !== undefined ) {
  34. scope.onError( url );
  35. }
  36. };
  37. }
  38. var DefaultLoadingManager = new LoadingManager();
  39. export { DefaultLoadingManager, LoadingManager };