parseSubNode method

dynamic parseSubNode(
  1. dynamic name,
  2. Map<String, dynamic> node,
  3. Map<String, dynamic> subNode
)

Implementation

parseSubNode(name, Map<String, dynamic> node, Map<String, dynamic> subNode) {
  // special case: child node is single property
  if (subNode["singleProperty"] == true) {
    var value = subNode["propertyList"][0];

    if (value is List) {
      node[subNode["name"]] = subNode;

      subNode["a"] = value;
    } else {
      node[subNode["name"]] = value;
    }
  } else if (name == 'Connections' && subNode["name"] == 'C') {
    var array = [];

    subNode["propertyList"].asMap().forEach((i, property) {
      // first Connection is FBX type (OO, OP, etc.). We'll discard these
      if (i != 0) array.add(property);
    });

    if (node["connections"] == null) {
      node["connections"] = [];
    }

    node["connections"].add(array);
  } else if (subNode["name"] == 'Properties70') {
    var keys = subNode.keys;

    for (var key in keys) {
      node[key] = subNode[key];
    }
  } else if (name == 'Properties70' && subNode["name"] == 'P') {
    String innerPropName = subNode["propertyList"][0];
    var innerPropType1 = subNode["propertyList"][1];
    var innerPropType2 = subNode["propertyList"][2];
    var innerPropFlag = subNode["propertyList"][3];
    var innerPropValue;

    if (innerPropName.indexOf('Lcl ') == 0) innerPropName = innerPropName.replaceFirst('Lcl ', 'Lcl_');
    if (innerPropType1.indexOf('Lcl ') == 0) innerPropType1 = innerPropType1.replaceFirst('Lcl ', 'Lcl_');

    if (innerPropType1 == 'Color' ||
        innerPropType1 == 'ColorRGB' ||
        innerPropType1 == 'Vector' ||
        innerPropType1 == 'Vector3D' ||
        innerPropType1.indexOf('Lcl_') == 0) {
      innerPropValue = [subNode["propertyList"][4], subNode["propertyList"][5], subNode["propertyList"][6]];
    } else {
      if (subNode["propertyList"].length > 4) {
        innerPropValue = subNode["propertyList"][4];
      }
    }

    // this will be copied to parent, see above
    node[innerPropName] = {
      'type': innerPropType1,
      'type2': innerPropType2,
      'flag': innerPropFlag,
      'value': innerPropValue
    };
  } else if (node[subNode["name"]] == null) {
    if (subNode["id"] is num) {
      node[subNode["name"]] = {};
      node[subNode["name"]][subNode["id"]] = subNode;
    } else {
      node[subNode["name"]] = subNode;
    }
  } else {
    if (subNode["name"] == 'PoseNode') {
      if (node[subNode["name"]] is! List) {
        node[subNode["name"]] = [node[subNode["name"]]];
      }

      node[subNode["name"]].add(subNode);
    } else if (node[subNode["name"]][subNode["id"]] == null) {
      if (subNode["id"] != null) {
        node[subNode["name"]][subNode["id"]] = subNode;
      }
    }
  }
}