void Loader::loadBoneList(const aiMesh *pMesh, CMC_MeshData *mesh) { m_model->m_hasAnimation = m_pScene->HasAnimations(); if(!m_model->m_hasAnimation) { m_model->setRootBone (nullptr); return; } for (uint i = 0 ; i < pMesh->mNumBones ; i++) { uint BoneIndex = 0; std::string BoneName(pMesh->mBones[i]->mName.data); if (m_model->m_BoneMetaInfoMapping.find(BoneName) == m_model->m_BoneMetaInfoMapping.end()) { // Allocate an index for a new bone BoneIndex = m_model->m_numBones; m_model->m_numBones++; CMC_NodeMetaInfo * metaInfo = new CMC_NodeMetaInfo(); metaInfo->setName (BoneName); auto matrix_assimp = pMesh->mBones[i]->mOffsetMatrix; auto matrix_qt = toQMatrix(matrix_assimp); metaInfo->setDefaultBoneOffset (matrix_qt); m_model->m_boneMetaInfoList.push_back (metaInfo); m_model->m_BoneMetaInfoMapping[BoneName] = BoneIndex; } else { BoneIndex = m_model->m_BoneMetaInfoMapping[BoneName]; } for (uint j = 0 ; j < pMesh->mBones[i]->mNumWeights ; j++) {//load bones weight and index to mesh's vertices.. uint VertexID = pMesh->mBones[i]->mWeights[j].mVertexId; float Weight = pMesh->mBones[i]->mWeights[j].mWeight; mesh->getVertex (VertexID)->addBoneData (BoneIndex,Weight); } } }
void Mesh::LoadBones(uint MeshIndex, const aiMesh* pMesh, vector<VertexBoneData>& Bones) { for (uint i = 0 ; i < pMesh->mNumBones ; i++) { uint BoneIndex = 0; string BoneName(pMesh->mBones[i]->mName.data); if (m_BoneMapping.find(BoneName) == m_BoneMapping.end()) { // Allocate an index for a new bone BoneIndex = m_NumBones; m_NumBones++; BoneInfo bi; m_BoneInfo.push_back(bi); m_BoneInfo[BoneIndex].BoneOffset = pMesh->mBones[i]->mOffsetMatrix; m_BoneMapping[BoneName] = BoneIndex; } else { BoneIndex = m_BoneMapping[BoneName]; } for (uint j = 0 ; j < pMesh->mBones[i]->mNumWeights ; j++) { uint VertexID = m_Entries[MeshIndex].BaseVertex + pMesh->mBones[i]->mWeights[j].mVertexId; float Weight = pMesh->mBones[i]->mWeights[j].mWeight; Bones[VertexID].AddBoneData(BoneIndex, Weight); } } }
void Mesh::LoadBones(unsigned int Index, const aiMesh* pMesh, std::vector<VtxBoneInfo>& bones) { printf("Mesh %d contains %d bones\n", Index, pMesh->mNumBones); for (unsigned int i=0; i < pMesh->mNumBones; i++) { unsigned int BoneIndex =0; std::string BoneName(pMesh->mBones[i]->mName.data); if(_b2i_map.find(BoneName)== _b2i_map.end()) { // Allocate an index for a new bone BoneIndex = _numBone; _numBone++; BoneTf bt; _boneTfs.push_back(bt); CopyaiMat(pMesh->mBones[i]->mOffsetMatrix, _boneTfs[BoneIndex].Offset); _b2i_map[BoneName] = BoneIndex; } else BoneIndex = _b2i_map[BoneName]; printf("%-2d BoneName: %15s, nweights=%d\n", i+1, BoneName.c_str(), pMesh->mBones[i]->mNumWeights); for (unsigned int j=0; j< pMesh->mBones[i]->mNumWeights; j++) { unsigned int Vid = _entries[Index].baseVtx + pMesh->mBones[i]->mWeights[j].mVertexId; float weight = pMesh->mBones[i]->mWeights[j].mWeight; // printf("vid = %u, weight = %f\n", Vid, weight); bones[Vid].AddBoneData(BoneIndex, weight); } } printf("_numBone = %d\n", _numBone); if(_b2i_map.find(std::string("Hips"))==_b2i_map.end()) { BoneTf bt; _boneTfs.push_back(bt); _b2i_map["Hips"] = _numBone++; printf("%-2d BoneName: Hips, nweights=0\n", _numBone); } }
Bone::Bone(aiScene const& scene) { //construct hierarchy *this = Bone { *(scene.mRootNode) }; std::map<std::string, std::pair<unsigned int, scm::math::mat4f> > bone_info {}; unsigned num_bones = 0; for (unsigned int i = 0; i < scene.mNumMeshes; i++) { for (unsigned int b = 0; b < scene.mMeshes[i]->mNumBones; ++b) { std::string BoneName(scene.mMeshes[i]->mBones[b]->mName.data); if (bone_info.find(BoneName) == bone_info.end()) { bone_info[BoneName] = std::make_pair( num_bones, to_gua::mat4f(scene.mMeshes[i]->mBones[b]->mOffsetMatrix)); ++num_bones; } } } this->set_properties(bone_info); }
std::string RigAnim::CsvHeaderForDebugging(int line) const { std::ostringstream oss; // Output the bone names, and gaps for where that bone's ops will go. for (BoneIndex i = 0; i < NumBones(); ++i) { const std::vector<MatrixOperationInit>& ops = anims_[i].ops(); if (ops.size() == 0) continue; if (line == 0) { oss << BoneName(i); } for (size_t j = 0; j < ops.size(); ++j) { if (line == 0) { oss << ','; } else { oss << MatrixOpName(ops[j].type) << ","; } } } return oss.str(); }