load method

dynamic load(
  1. dynamic url,
  2. Function onLoad, [
  3. Function? onProgress,
  4. Function? onError,
])
override

Implementation

load(url, Function onLoad, [Function? onProgress, Function? onError]) {
  var scope = this;

  var resourcePath;

  if (this.resourcePath != '') {
    resourcePath = this.resourcePath;
  } else if (this.path != '') {
    resourcePath = this.path;
  } else {
    resourcePath = LoaderUtils.extractUrlBase(url);
  }

  // Tells the LoadingManager to track an extra item, which resolves after
  // the model is fully loaded. This means the count of items loaded will
  // be incorrect, but ensures manager.onLoad() does not fire early.
  this.manager.itemStart(url);

  Function _onError = (e) {
    if (onError != null) {
      onError(e);
    } else {
      print(e);
    }

    scope.manager.itemError(url);
    scope.manager.itemEnd(url);
  };

  var loader = new FileLoader(this.manager);

  loader.setPath(this.path);
  loader.setResponseType('arraybuffer');
  loader.setRequestHeader(this.requestHeader);
  loader.setWithCredentials(this.withCredentials);

  loader.load(url, (data) {
    // try {

    scope.parse(data, resourcePath, (gltf) {
      onLoad(gltf);

      scope.manager.itemEnd(url);
    }, _onError);

    // } catch ( e ) {

    //   _onError( e );

    // }
  }, onProgress, _onError);
}