convert method

dynamic convert(
  1. dynamic materialsInfo
)

Implementation

convert(materialsInfo) {
  // TODO options can be null? or have default value
  if (this.options == null) return materialsInfo;

  Map<String, dynamic> converted = {};

  for (var mn in materialsInfo.keys) {
    // Convert materials info into normalized form based on options

    var mat = materialsInfo[mn];

    Map<String, dynamic> covmat = {};

    converted[mn] = covmat;

    for (var prop in mat.keys) {
      var save = true;
      var value = mat[prop];
      var lprop = prop.toLowerCase();

      switch (lprop) {
        case 'kd':
        case 'ka':
        case 'ks':

          // Diffuse color (color under white light) using RGB values

          if (this.options != null && this.options["normalizeRGB"] != null) {
            value = [value[0] / 255, value[1] / 255, value[2] / 255];
          }

          if (this.options != null &&
              this.options["ignoreZeroRGBs"] != null) {
            if (value[0] == 0 && value[1] == 0 && value[2] == 0) {
              // ignore

              save = false;
            }
          }

          break;

        default:
          break;
      }

      if (save) {
        covmat[lprop] = value;
      }
    }
  }

  return converted;
}