ImportAnimationFromThreeJsJson function

SkeletalAnimation ImportAnimationFromThreeJsJson(
  1. Map json,
  2. List<Bone> skeleton
)

Implementation

SkeletalAnimation ImportAnimationFromThreeJsJson(
    Map json, List<Bone> skeleton) {
  final Map animation = json["animation"];
  final List hierarchy = animation["hierarchy"];
  SkeletalAnimation s = SkeletalAnimation(
      animation["name"], animation["length"], hierarchy.length);
  assert(hierarchy.length == json["bones"].length);
  for (int i = 0; i < hierarchy.length; ++i) {
    List<double> pTimes = [];
    List<VM.Vector3> pValues = [];
    List<double> rTimes = [];
    List<VM.Quaternion> rValues = [];
    List<double> sTimes = [];
    List<VM.Vector3> sValues = [];
    for (Map m in hierarchy[i]["keys"]) {
      double t = m["time"].toDouble();

      if (m.containsKey("pos")) {
        pTimes.add(t);
        pValues.add(MakeTransVector3(m["pos"]));
      }

      if (m.containsKey("scale")) {
        sTimes.add(t);
        sValues.add(MakeScaleVector3(m["scl"]));
      }

      if (m.containsKey("rot")) {
        rTimes.add(t);
        rValues.add(MakeQuaternion(m["rot"]));
      }
    }
    BoneAnimation ba = BoneAnimation(
        skeleton[i], pTimes, pValues, rTimes, rValues, sTimes, sValues);
    s.InsertBone(ba);
  }
  print("anim-bones: ${s.animList.length}");
  return s;
}