Esempio n. 1
0
void OgreXmlSerializer::ReadBoneHierarchy(Skeleton *skeleton)
{
    if (skeleton->bones.empty()) {
        throw DeadlyImportError("Cannot read <bonehierarchy> for a Skeleton without bones");
    }

    while(NextNode() == nnBoneParent)
    {
        const std::string name = ReadAttribute<std::string>("bone");
        const std::string parentName = ReadAttribute<std::string>("parent");

        Bone *bone = skeleton->BoneByName(name);
        Bone *parent = skeleton->BoneByName(parentName);

        if (bone && parent)
            parent->AddChild(bone);
        else
            throw DeadlyImportError("Failed to find bones for parenting: Child " + name + " for parent " + parentName);
    }

    // Calculate bone matrices for root bones. Recursively calculates their children.
    for (size_t i=0, len=skeleton->bones.size(); i<len; ++i)
    {
        Bone *bone = skeleton->bones[i];
        if (!bone->IsParented())
            bone->CalculateWorldMatrixAndDefaultPose(skeleton);
    }
}