extendParams method

dynamic extendParams(
  1. dynamic materialParams,
  2. dynamic materialDef,
  3. dynamic parser
)

Implementation

extendParams(materialParams, materialDef, parser) async {
  var pbrSpecularGlossiness = materialDef.extensions[name];

  materialParams.color = Color(1.0, 1.0, 1.0);
  materialParams.opacity = 1.0;

  List<Future> pending = [];

  if (pbrSpecularGlossiness.diffuseFactor is List) {
    var array = pbrSpecularGlossiness.diffuseFactor;

    materialParams.color.fromArray(array);
    materialParams.opacity = array[3];
  }

  if (pbrSpecularGlossiness.diffuseTexture != null) {
    pending.add(parser.assignTexture(materialParams, 'map', pbrSpecularGlossiness.diffuseTexture, sRGBEncoding));
  }

  materialParams.emissive = Color(0.0, 0.0, 0.0);
  materialParams.glossiness = pbrSpecularGlossiness.glossinessFactor ?? 1.0;
  materialParams.specular = Color(1.0, 1.0, 1.0);

  if (pbrSpecularGlossiness.specularFactor is List) {
    materialParams.specular.fromArray(pbrSpecularGlossiness.specularFactor);
  }

  if (pbrSpecularGlossiness.specularGlossinessTexture != null) {
    var specGlossMapDef = pbrSpecularGlossiness.specularGlossinessTexture;
    pending.add(parser.assignTexture(materialParams, 'glossinessMap', specGlossMapDef));
    pending.add(parser.assignTexture(materialParams, 'specularMap', specGlossMapDef, sRGBEncoding));
  }

  return Future.wait(pending);
}