| 63 | namespace Assimp { |
| 64 | |
| 65 | static const aiNode *findSkeletonRootNode(const aiScene *scene, const aiMesh *mesh) { |
| 66 | std::set<const aiNode *> topParentBoneNodes; |
| 67 | if (mesh && mesh->mNumBones > 0) { |
| 68 | for (unsigned int i = 0; i < mesh->mNumBones; ++i) { |
| 69 | aiBone *bone = mesh->mBones[i]; |
| 70 | |
| 71 | const aiNode *node = scene->mRootNode->findBoneNode(bone); |
| 72 | if (node) { |
| 73 | while (node->mParent && scene->findBone(node->mParent->mName) != nullptr) { |
| 74 | node = node->mParent; |
| 75 | } |
| 76 | topParentBoneNodes.insert(node); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | if (!topParentBoneNodes.empty()) { |
| 82 | const aiNode *parentBoneNode = *topParentBoneNodes.begin(); |
| 83 | if (topParentBoneNodes.size() == 1) { |
| 84 | return parentBoneNode; |
| 85 | } else { |
| 86 | for (auto it : topParentBoneNodes) { |
| 87 | if (it->mParent) return it->mParent; |
| 88 | } |
| 89 | return parentBoneNode; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return nullptr; |
| 94 | } |
| 95 | |
| 96 | // ------------------------------------------------------------------------------------------------ |
| 97 | // Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp |