Beispiel #1
0
CINF::CINF(const Armature& armature, std::unordered_map<std::string, atInt32>& idMap) {
  idMap.reserve(armature.bones.size());
  bones.reserve(armature.bones.size());

  std::map<std::string, int> nameMap;

  const BlenderBone* bone = armature.getRoot();
  if (bone) {
    if (bone->children.size()) {
      int curId = 4;
      const BlenderBone* child;
      for (size_t i = 0; (child = armature.getChild(bone, i)); ++i)
        RecursiveAddArmatureBone(armature, child, 3, curId, idMap, nameMap);
    }

    bones.emplace_back();
    Bone& boneOut = bones.back();
    nameMap[bone->name] = 3;
    boneOut.id = 3;
    boneOut.parentId = 2;
    boneOut.origin = bone->origin;
    idMap.emplace(std::make_pair(bone->name, 3));

    if (bone->children.size()) {
      boneOut.linkedCount = 2;
      boneOut.linked = {2, 4};
    } else {
      boneOut.linkedCount = 1;
      boneOut.linked = {2};
    }
  }

  boneCount = bones.size();

  names.reserve(nameMap.size());
  nameCount = nameMap.size();
  for (const auto& name : nameMap) {
    names.emplace_back();
    Name& nameOut = names.back();
    nameOut.name = name.first;
    nameOut.boneId = name.second;
  }

  boneIdCount = boneCount;
  boneIds.reserve(boneIdCount);
  for (auto it = bones.crbegin(); it != bones.crend(); ++it)
    boneIds.push_back(it->id);
}