GLTFMaterialsClearcoatExtension constructor

GLTFMaterialsClearcoatExtension(
  1. dynamic parser
)

Implementation

GLTFMaterialsClearcoatExtension(parser) {
  this.parser = parser;

  this.getMaterialType = (materialIndex) {
    var parser = this.parser;
    var materialDef = parser.json["materials"][materialIndex];

    if (materialDef["extensions"] == null ||
        materialDef["extensions"][this.name]) return null;

    return MeshPhysicalMaterial;
  };

  this.extendMaterialParams = (materialIndex, materialParams) async {
    var parser = this.parser;
    Map<String, dynamic> materialDef =
        parser.json["materials"][materialIndex];

    if (materialDef["extensions"] == null ||
        materialDef["extensions"][this.name] == null) {
      return null;
    }

    List<Future> pending = [];

    Map<String, dynamic> exten = materialDef["extensions"][this.name];

    if (exten["clearcoatFactor"] != null) {
      materialParams.clearcoat = exten["clearcoatFactor"];
    }

    if (exten["clearcoatTexture"] != null) {
      pending.add(parser.assignTexture(
          materialParams, 'clearcoatMap', exten["clearcoatTexture"]));
    }

    if (exten["clearcoatRoughnessFactor"] != null) {
      materialParams.clearcoatRoughness = exten["clearcoatRoughnessFactor"];
    }

    if (exten["clearcoatRoughnessTexture"] != null) {
      pending.add(parser.assignTexture(materialParams,
          'clearcoatRoughnessMap', exten["clearcoatRoughnessTexture"]));
    }

    if (exten["clearcoatNormalTexture"] != null) {
      pending.add(parser.assignTexture(materialParams, 'clearcoatNormalMap',
          exten["clearcoatNormalTexture"]));

      if (exten["clearcoatNormalTexture"]["scale"] != null) {
        var scale = exten["clearcoatNormalTexture"]["scale"];

        materialParams.clearcoatNormalScale = new Vector2(scale, scale);
      }
    }

    return await Future.wait(pending);
  };
}