buildSkeleton method

dynamic buildSkeleton(
  1. dynamic relationships,
  2. dynamic skeletons,
  3. dynamic id,
  4. dynamic name,
)

Implementation

buildSkeleton(relationships, skeletons, id, name) {
  var bone;

  relationships["parents"].forEach((parent) {
    for (var id in skeletons.keys) {
      var skeleton = skeletons[id];

      skeleton["rawBones"].asMap().forEach((i, rawBone) {
        if (rawBone["ID"] == parent["ID"]) {
          var subBone = bone;
          bone = Bone();

          bone.matrixWorld.copy(rawBone["transformLink"]);

          // set name and id here - otherwise in cases where "subBone" is created it will not have a name / id

          bone.name = name != null ? PropertyBinding.sanitizeNodeName(name) : '';
          bone.id = id;

          if (skeleton["bones"].length <= i) {
            final boneList = List<Bone>.filled((i + 1) - skeleton["bones"].length, Bone());

            skeleton["bones"].addAll(boneList);
          }

          skeleton["bones"][i] = bone;

          // In cases where a bone is shared between multiple meshes
          // duplicate the bone here and and it as a child of the first bone
          if (subBone != null) {
            bone.add(subBone);
          }
        }
      });
    }
  });

  return bone;
}