GLTFMaterialsSheenExtension constructor

GLTFMaterialsSheenExtension(
  1. dynamic parser
)

Implementation

GLTFMaterialsSheenExtension(parser) {
  this.parser = parser;
  this.name = EXTENSIONS["KHR_MATERIALS_SHEEN"]!;

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

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

    return MeshPhysicalMaterial;
  };

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

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

    List<Future> pending = [];

    materialParams.sheenColor = new Color(0, 0, 0);
    materialParams.sheenRoughness = 0;
    materialParams.sheen = 1;

    Map extension = materialDef["extensions"][this.name];

    if (extension["sheenColorFactor"] != null) {
      materialParams.sheenColor.fromArray(extension["sheenColorFactor"]);
    }

    if (extension["sheenRoughnessFactor"] != null) {
      materialParams.sheenRoughness = extension["sheenRoughnessFactor"];
    }

    if (extension["sheenColorTexture"] != null) {
      pending.add(parser.assignTexture(
          materialParams, 'sheenColorMap', extension["sheenColorTexture"], sRGBEncoding));
    }

    if (extension["sheenRoughnessTexture"] != null) {
      pending.add(parser.assignTexture(materialParams, 'sheenRoughnessMap',
          extension["sheenRoughnessTexture"]));
    }

    return Future.wait(pending);
  };
}