complete method

Future<GpuMaterial> complete(
  1. MaterialFile file
)

file's material with every map read first — for a picture of it, not a scene drawn frame by frame. A variant's parents, its layers' files and the maps are read through read too (or taken from a preview). Throws what reading the file's maps or layers throws; a parent that cannot be read is skipped.

Implementation

Future<GpuMaterial> complete(MaterialFile file) async {
  Future<(GpuTexture, GpuSampler)?> map(
    String path, {
    required bool srgb,
  }) async {
    if (path.isEmpty) return null;
    final texture = await uploader.uploadImage(await read(path), srgb: srgb);
    return texture == null ? null : (texture, GpuSampler.linearRepeat);
  }

  final resolved = await _resolveNow(file);
  final layers = [
    for (final l in resolved.layers.take(MaterialFile.maxLayers))
      await _resolveNow(await _readNow(l)),
  ];
  final maps = resolved.kind == MaterialKind.layered
      ? [
          for (var i = 0; i < 4; i++)
            i < layers.length
                ? await map(layers[i].colorMap, srgb: true)
                : null,
        ]
      : [
          await map(resolved.colorMap, srgb: true),
          await map(resolved.metalRoughMap, srgb: false),
          await map(resolved.normalMap, srgb: false),
          await map(resolved.occlusionMap, srgb: false),
          await map(resolved.emissionMap, srgb: true),
        ];
  return uploader.material(dataOf(resolved, layers: layers), maps: maps);
}