void OgreXmlSerializer::ReadSkeleton(Skeleton *skeleton) { if (NextNode() != nnSkeleton) { throw DeadlyImportError("Root node is <" + m_currentNodeName + "> expecting <skeleton>"); } DefaultLogger::get()->debug("Reading Skeleton"); // Optional blend mode from root node if (HasAttribute("blendmode")) { skeleton->blendMode = (ToLower(ReadAttribute<std::string>("blendmode")) == "cumulative" ? Skeleton::ANIMBLEND_CUMULATIVE : Skeleton::ANIMBLEND_AVERAGE); } NextNode(); // Root level nodes while(m_currentNodeName == nnBones || m_currentNodeName == nnBoneHierarchy || m_currentNodeName == nnAnimations || m_currentNodeName == nnAnimationLinks) { if (m_currentNodeName == nnBones) ReadBones(skeleton); else if (m_currentNodeName == nnBoneHierarchy) ReadBoneHierarchy(skeleton); else if (m_currentNodeName == nnAnimations) ReadAnimations(skeleton); else SkipCurrentNode(); } }
bool SkeletalModelLoader::LoadM3d(const std::string& filename, std::vector<SimpleVertex>& vertices, std::vector<unsigned int>& indices, std::vector<SkeletalModelSubSet>& subsets, std::vector<SkeletalModelMaterial>& mats, SkinnedMeshSkeleton & skinInfo) { std::ifstream md3File(filename); unsigned int nMaterials = 0, nVertices = 0, nTriangles = 0, nBones = 0, nAnimationClips = 0; std::string ignorStr = ""; if (md3File.good()) { // call the bellow loading functions md3File >> ignorStr; // ***************m3d-File-Header*************** md3File >> ignorStr >> nMaterials; md3File >> ignorStr >> nVertices; md3File >> ignorStr >> nTriangles; md3File >> ignorStr >> nBones; md3File >> ignorStr >> nAnimationClips; std::vector<DirectX::XMFLOAT4X4> boneOffsets; std::vector<int> boneIndexToParentIndex; std::map<std::string, AnimationClip> animationClips; ReadMaterials(md3File, nMaterials, mats); ReadSubsetTable(md3File, nMaterials, subsets); ReadSkinnedVertices(md3File, nVertices, vertices); // now check to see if the bones on each vertex are in an ok range std::vector<unsigned int> badVertexIndercies; std::vector<BYTE> badWeightIndexValueForVert; for (unsigned int i = 0; i < vertices.size(); i++) { for (unsigned int j = 0; j < 4; j++) { if (vertices[i].BoneIndices[j] >= nBones) { BYTE theValue = vertices[i].BoneIndices[j]; int badVertexIndex = i; badVertexIndercies.push_back(badVertexIndex); badWeightIndexValueForVert.push_back(theValue); } } } ReadTriangles(md3File, nTriangles, indices); ReadBoneOffsets(md3File, nBones, boneOffsets); ReadBoneHierarchy(md3File, nBones, boneIndexToParentIndex); ReadAnimationClips(md3File, nBones, nAnimationClips, animationClips); skinInfo.set(boneIndexToParentIndex, boneOffsets, animationClips); return true; }