GLTFMaterialsClearcoatExtension constructor

GLTFMaterialsClearcoatExtension(
  1. dynamic parser
)

Implementation

GLTFMaterialsClearcoatExtension(this.parser) {
  name = gltfExtensions["KHR_MATERIALS_CLEARCOAT"]!;

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

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

    return MeshPhysicalMaterial;
  };

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

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

    List<Future> pending = [];

    Map<String, dynamic> exten = materialDef["extensions"][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 = Vector2(scale, scale);
      }
    }

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