complete method

Future<GpuMaterial> complete(
  1. Material3DFile 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(Material3DFile 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 = <Material3DFile?>[
    for (final l in resolved.layers.take(Material3DFile.maxLayers))
      // An empty slot is no layer, not a file to read.
      l.isEmpty ? null : await _resolveNow(await _readNow(l)),
  ];
  final maps = resolved.kind == Material3DKind.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);
}