GLTFMaterialsVolumeExtension constructor

GLTFMaterialsVolumeExtension(
  1. dynamic parser
)

Implementation

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

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

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

    return MeshPhysicalMaterial;
  };

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

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

    List<Future> pending = [];

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

    materialParams.thickness = 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 = Color(colorArray[0], colorArray[1], colorArray[2]);

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