loadImageSource method

Future<Texture?> loadImageSource(
  1. dynamic sourceIndex,
  2. TextureLoader loader
)

Implementation

Future<Texture?> loadImageSource(sourceIndex, TextureLoader loader) async {
  final parser = this;
  final json = this.json;
  final options = this.options;
  Texture? texture;

  if (sourceCache[sourceIndex] != null) {
    texture = sourceCache[sourceIndex];
    return texture!.clone();
  }

  Map sourceDef = json["images"][sourceIndex];
  String? sourceURI = sourceDef["uri"];

  if (sourceDef["bufferView"] != null) {
    final bufferView = await parser.getDependency('bufferView', sourceDef["bufferView"]);
    final blob = Blob(bufferView.asUint8List(), {"type": sourceDef["mimeType"]});
    texture = await loader.fromBlob(blob);
  }
  else if (sourceURI != null) {
    final String resolve = LoaderUtils.resolveURL(sourceURI, options["path"]);
    texture = await loader.unknown(resolve);
  }
  else if (sourceURI == null) {
    throw ('GLTFLoader: Image $sourceIndex is missing URI and bufferView');
  }

  sourceCache[sourceIndex] = texture;
  return texture;
}