GLTFMaterialsVolumeExtension constructor

GLTFMaterialsVolumeExtension(
  1. dynamic parser
)

Implementation

GLTFMaterialsVolumeExtension(parser) {
  this.parser = parser;
  this.name = EXTENSIONS["KHR_MATERIALS_VOLUME"]!;

  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) async {
    var parser = this.parser;
    var materialDef = parser.json["materials"][materialIndex];

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

    List<Future> pending = [];

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

    materialParams.thickness =
        extension.thicknessFactor != null ? extension.thicknessFactor : 0;

    if (extension.thicknessTexture != null) {
      pending.add(parser.assignTexture(
          materialParams, 'thicknessMap', extension.thicknessTexture));
    }

    materialParams.attenuationDistance = extension.attenuationDistance ?? 0;

    var colorArray = extension.attenuationColor ?? [1, 1, 1];
    materialParams.attenuationColor =
        new Color(colorArray[0], colorArray[1], colorArray[2]);

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