ImportSkeletonFromAssimp2Json function

List<Bone> ImportSkeletonFromAssimp2Json(
  1. Map<String, dynamic> json
)

Implementation

List<Bone> ImportSkeletonFromAssimp2Json(Map<String, dynamic> json) {
  List<Bone> out = <Bone>[];
  int count = 0;

  void dfs(Map<String, dynamic> node, int parent) {
    final String name = node["name"];

    final VM.Matrix4 transform =
        VM.Matrix4.fromList(_Floatify(node["transformation"]));
    transform.transpose();

    final VM.Matrix4 offset = VM.Matrix4.identity();
    Bone bone = Bone(name, count, parent, transform, offset);
    count++;
    out.add(bone);
    if (node.containsKey("children")) {
      for (Map<String, dynamic> child in node["children"]) {
        dfs(child, bone.boneIndex);
      }
    }
  }

  // We do not represent the root node as a node as it seems to have
  // a bad transform matrix
  // dfs(json["rootnode"], -1);
  Map<String, dynamic> root = json["rootnode"];
  for (Map<String, dynamic> child in root["children"]) {
    dfs(child, -1);
  }

  return out;
}