materialFor method

GpuMaterial materialFor(
  1. Primitive3D shape, {
  2. Map<String, Object?> overrides = const {},
})

shape's material: its material file's once that is read (its own look meanwhile), with overrides (its entity's own values, MaterialOverrides3D) on top; else its own look, with its texture once that has loaded.

Implementation

GpuMaterial materialFor(
  Primitive3D shape, {
  Map<String, Object?> overrides = const {},
}) {
  final file = shape.material;
  if (file.isNotEmpty) {
    final shared = library?.gpuOf(file, overrides: overrides);
    if (shared != null) return shared;
  }
  final key = shape.materialKey;
  final known = _materials[key];
  if (known != null) {
    known.used = _frame;
    return known.value;
  }
  final path = shape.texture;
  final texture = path.isEmpty ? null : _texture(path);
  final material = uploader.material(
    materialDataOf(shape),
    baseColor: texture == null ? null : (texture, GpuSampler.linearRepeat),
  );
  _materials[key] = _Entry(material, _frame, texture: path);
  return material;
}