parseAnimationCurves method

dynamic parseAnimationCurves(
  1. dynamic curveNodesMap
)

Implementation

parseAnimationCurves(curveNodesMap) {
  var rawCurves = fbxTree.objects["AnimationCurve"];

  // TODO: Many values are identical up to roundoff error, but won't be optimised
  // e.g. position times: [0, 0.4, 0. 8]
  // position values: [7.23538335023477e-7, 93.67518615722656, -0.9982695579528809, 7.23538335023477e-7, 93.67518615722656, -0.9982695579528809, 7.235384487103147e-7, 93.67520904541016, -0.9982695579528809]
  // clearly, this should be optimised to
  // times: [0], positions [7.23538335023477e-7, 93.67518615722656, -0.9982695579528809]
  // this shows up in nearly every FBX file, and generally time array is length > 100

  for (var nodeID in rawCurves.keys) {
    var animationCurve = {
      "id": rawCurves[nodeID]["id"],
      "times": rawCurves[nodeID]["KeyTime"]["a"].map(convertFBXTimeToSeconds).toList(),
      "values": rawCurves[nodeID]["KeyValueFloat"]["a"],
    };

    var relationships = connections[animationCurve["id"]];

    if (relationships != null) {
      var animationCurveID = relationships["parents"][0]["ID"];
      var animationCurveRelationship = relationships["parents"][0]["relationship"];

      if (RegExp(r'X').hasMatch(animationCurveRelationship)) {
        curveNodesMap[animationCurveID]["curves"]['x'] = animationCurve;
      } else if (RegExp(r'Y').hasMatch(animationCurveRelationship)) {
        curveNodesMap[animationCurveID]["curves"]['y'] = animationCurve;
      } else if (RegExp(r'Z').hasMatch(animationCurveRelationship)) {
        curveNodesMap[animationCurveID]["curves"]['z'] = animationCurve;
      } else if (RegExp(r'd|DeformPercent').hasMatch(animationCurveRelationship) &&
          curveNodesMap.has(animationCurveID)) {
        curveNodesMap[animationCurveID]["curves"]['morph'] = animationCurve;
      }
    }
  }
}