error_e readBoneList(const char *pchFile, std::vector<CBone> &boneList) { const char *nodeStr = strstr(pchFile, "\nnodes\n"); if(!nodeStr) return ERR_CORRUPT_FILE; const char *boneLine = nodeStr + strlen("\nnodes\n"); while(strncmp(boneLine, "end\n", 4) != NULL) { char chId[32] = {0}; int id = -1; int parentId = -1; char boneName[256] = {0}; int readCount = 0; int ret = sscanf(boneLine, "%s %s %i%n", chId, boneName, &parentId, &readCount); if(readCount > 0) { id = atoi(chId); string strBoneName(boneName); strBoneName.erase(strBoneName.begin()+strBoneName.size()-1); strBoneName.erase(strBoneName.begin()); boneList.push_back(CBone(strBoneName, id, parentId)); const char *boneLineEnd = strchr(boneLine + readCount, '\n'); if(!boneLineEnd) return ERR_CORRUPT_FILE; boneLine = boneLineEnd + 1; } else return ERR_CORRUPT_FILE; } return ERR_NONE; }
// *************************************************************************** CTransformShape *CSkeletonShape::createInstance(CScene &scene) { // Create a CSkeletonModel, an instance of a mesh. //=============================================== CSkeletonModel *sm= (CSkeletonModel*)scene.createModel(NL3D::SkeletonModelId); sm->Shape= this; // setup bones. //================= sm->Bones.reserve(_Bones.size()); for(sint i=0;i<(sint)_Bones.size();i++) { // Append a new bone. sm->Bones.push_back( CBone(&_Bones[i]) ); // Must set the Animatable father of the bone (the skeleton model!). sm->Bones[i].setFather(sm, CSkeletonModel::OwnerBit); } // Must create and init skeleton bone usage to 0. sm->initBoneUsages(); // For skinning: setup skeleton in Skin LoadBalancing group sm->setLoadBalancingGroup("Skin"); return sm; }