MaterialOverride.fromJson constructor

MaterialOverride.fromJson(
  1. Map<String, dynamic> json
)

Reads one saved by toJson.

Implementation

factory MaterialOverride.fromJson(Map<String, dynamic> json) {
  List<double>? list(Object? v, int n) =>
      v is List && v.length == n && v.every((e) => e is num)
      ? [for (final e in v) (e as num).toDouble()]
      : null;
  final c = list(json['baseColor'], 4);
  final e = list(json['emissive'], 3);
  return MaterialOverride(
    baseColor: c == null ? null : (c[0], c[1], c[2], c[3]),
    metallic: (json['metallic'] as num?)?.toDouble(),
    roughness: (json['roughness'] as num?)?.toDouble(),
    emissive: e == null ? null : (e[0], e[1], e[2]),
    emissiveStrength: (json['emissiveStrength'] as num?)?.toDouble(),
    doubleSided: json['doubleSided'] as bool?,
    unlit: json['unlit'] as bool?,
  );
}