bool M3DLoader::LoadM3d(const std::string& filename, std::vector<Vertex::PosNormalTexTan>& vertices, std::vector<USHORT>& indices, std::vector<MeshGeometry::Subset>& subsets, std::vector<M3dMaterial>& mats) { std::ifstream fin(filename); UINT numMaterials = 0; UINT numVertices = 0; UINT numTriangles = 0; UINT numBones = 0; UINT numAnimationClips = 0; std::string ignore; if( fin ) { fin >> ignore; // file header text fin >> ignore >> numMaterials; fin >> ignore >> numVertices; fin >> ignore >> numTriangles; fin >> ignore >> numBones; fin >> ignore >> numAnimationClips; ReadMaterials(fin, numMaterials, mats); ReadSubsetTable(fin, numMaterials, subsets); ReadVertices(fin, numVertices, vertices); ReadTriangles(fin, numTriangles, indices); return true; } return false; }
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; }