surfaceMaterialFromJson function
- Map<
String, Object?> json, { - String? name,
- List<
String> ? warnings, - TextureBinding? baseColorTexture,
- TextureBinding? normalTexture,
- TextureBinding? metallicRoughnessTexture,
- TextureBinding? occlusionTexture,
- TextureBinding? emissiveTexture,
- MaterialExtensions? extensions,
The inverse of surfaceMaterialToJson: a SurfaceMaterial built from
json's own scalar and colour fields, with name as the fallback for a
document that names itself no other way and the five texture bindings
supplied by the caller — already resolved against whatever document
json came from, the same division surfaceMaterialToJson draws.
A field json does not carry reads as the same default
SurfaceMaterial's own constructor gives it; an alphaMode this build
has never heard of is reported through warnings and read as opaque,
the identical fallback readFmat has always given one.
Implementation
SurfaceMaterial surfaceMaterialFromJson(
Map<String, Object?> json, {
String? name,
List<String>? warnings,
TextureBinding? baseColorTexture,
TextureBinding? normalTexture,
TextureBinding? metallicRoughnessTexture,
TextureBinding? occlusionTexture,
TextureBinding? emissiveTexture,
MaterialExtensions? extensions,
}) => SurfaceMaterial(
name: json['name'] as String? ?? name,
baseColor: _vec4(json['baseColor']) ?? Vector4(1.0, 1.0, 1.0, 1.0),
metallic: _number(json['metallic'], 0.0),
roughness: _number(json['roughness'], 0.5),
baseColorTexture: baseColorTexture,
metallicRoughnessTexture: metallicRoughnessTexture,
normalTexture: normalTexture,
normalScale: _number(json['normalScale'], 1.0),
occlusionTexture: occlusionTexture,
occlusionStrength: _number(json['occlusionStrength'], 1.0),
emissiveTexture: emissiveTexture,
emissive: _vec3(json['emissive']) ?? Vector3.zero(),
emissiveStrength: _number(json['emissiveStrength'], 1.0),
alphaMode: _alphaMode(json['alphaMode'], warnings ?? <String>[]),
alphaCutoff: _number(json['alphaCutoff'], 0.5),
doubleSided: json['doubleSided'] as bool? ?? false,
unlit: json['unlit'] as bool? ?? false,
lightingModel: _readLighting(
json['lightingModel'],
warnings ?? <String>[],
key: 'lightingModel',
),
extensions: extensions,
);