parseParameters method

dynamic parseParameters(
  1. Map materialNode,
  2. dynamic textureMap,
  3. dynamic id
)

Implementation

parseParameters(Map materialNode, textureMap, id) {
  Map<String, dynamic> parameters = {};

  if (materialNode["BumpFactor"] != null) {
    parameters["bumpScale"] = materialNode["BumpFactor"]["value"];
  }

  if (materialNode["Diffuse"] != null) {
    parameters["color"] = Color().fromArray(List<double>.from(materialNode["Diffuse"]["value"]));
  } else if (materialNode["DiffuseColor"] != null &&
      (materialNode["DiffuseColor"]["type"] == 'Color' || materialNode["DiffuseColor"]["type"] == 'ColorRGB')) {
    // The blender exporter exports diffuse here instead of in materialNode.Diffuse
    parameters["color"] = Color().fromArray(materialNode["DiffuseColor"]["value"]);
  }

  if (materialNode["DisplacementFactor"] != null) {
    parameters["displacementScale"] = materialNode["DisplacementFactor"]["value"];
  }

  if (materialNode["Emissive"] != null) {
    parameters["emissive"] = Color().fromArray(List<double>.from(materialNode["Emissive"]["value"]));
  } else if (materialNode["EmissiveColor"] != null &&
      (materialNode["EmissiveColor"]["type"] == 'Color' || materialNode["EmissiveColor"].type == 'ColorRGB')) {
    // The blender exporter exports emissive color here instead of in materialNode.Emissive
    parameters["emissive"] = Color().fromArray(List<double>.from(materialNode["EmissiveColor"]["value"]));
  }

  if (materialNode["EmissiveFactor"] != null) {
    parameters["emissiveIntensity"] = parseFloat(materialNode["EmissiveFactor"]["value"]);
  }

  if (materialNode["Opacity"] != null) {
    parameters["opacity"] = parseFloat(materialNode["Opacity"]["value"].toString());
  }

  if (parameters["opacity"] < 1.0) {
    parameters["transparent"] = true;
  }

  if (materialNode["ReflectionFactor"] != null) {
    parameters["reflectivity"] = materialNode["ReflectionFactor"]["value"];
  }

  if (materialNode["Shininess"] != null) {
    parameters["shininess"] = materialNode["Shininess"]["value"];
  }

  if (materialNode["Specular"] != null) {
    parameters["specular"] = Color().fromArray(List<double>.from(materialNode["Specular"]["value"]));
  } else if (materialNode["SpecularColor"] != null && materialNode["SpecularColor"]["type"] == 'Color') {
    // The blender exporter exports specular color here instead of in materialNode.Specular
    parameters["specular"] = Color().fromArray(materialNode["SpecularColor"]["value"]);
  }

  var scope = this;

  final connection = connections[id];

  if (connection["children"] != null) {
    connection["children"].forEach((child) {
      var type = child["relationship"];

      var childID = child["ID"];

      switch (type) {
        case 'Bump':
          parameters["bumpMap"] = scope.getTexture(textureMap, childID);
          break;

        case 'Maya|TEX_ao_map':
          parameters["aoMap"] = scope.getTexture(textureMap, childID);
          break;

        case 'DiffuseColor':
        case 'Maya|TEX_color_map':
          parameters["map"] = scope.getTexture(textureMap, childID);
          if (parameters["map"] != null) {
            parameters["map"].encoding = sRGBEncoding;
          }

          break;

        case 'DisplacementColor':
          parameters["displacementMap"] = scope.getTexture(textureMap, childID);
          break;

        case 'EmissiveColor':
          parameters["emissiveMap"] = scope.getTexture(textureMap, childID);
          if (parameters["emissiveMap"] != null) {
            parameters["emissiveMap"].encoding = sRGBEncoding;
          }

          break;

        case 'NormalMap':
        case 'Maya|TEX_normal_map':
          parameters["normalMap"] = scope.getTexture(textureMap, childID);
          break;

        case 'ReflectionColor':
          parameters["envMap"] = scope.getTexture(textureMap, childID);
          if (parameters["envMap"] != null) {
            parameters["envMap"].mapping = EquirectangularReflectionMapping;
            parameters["envMap"].encoding = sRGBEncoding;
          }

          break;

        case 'SpecularColor':
          parameters["specularMap"] = scope.getTexture(textureMap, childID);
          if (parameters["specularMap"] != null) {
            parameters["specularMap"].encoding = sRGBEncoding;
          }

          break;

        case 'TransparentColor':
        case 'TransparencyFactor':
          parameters["alphaMap"] = scope.getTexture(textureMap, childID);
          parameters["transparent"] = true;
          break;

        case 'AmbientColor':
        case 'ShininessExponent': // AKA glossiness map
        case 'SpecularFactor': // AKA specularLevel
        case 'VectorDisplacementColor': // NOTE: Seems to be a copy of DisplacementColor
        default:
          print('THREE.FBXLoader: %s map is not supported in three.js, skipping texture. $type');
          break;
      }
    });
  }

  return parameters;
}