#include #include #include "Skeleton.h" #include "BinaryStream.h" //====================================================================================================================== // load = //====================================================================================================================== void Skeleton::load(const char* filename) { std::ifstream fs; fs.open(filename); if(!fs.is_open()) { throw EXCEPTION("Cannot open \"" + filename + "\""); } try { BinaryStream bs(fs.rdbuf()); // Magic word char magic[8]; bs.read(magic, 8); if(bs.fail() || memcmp(magic, "ANKISKEL", 8)) { throw EXCEPTION("Incorrect magic word"); } // Bones num uint bonesNum = bs.readUint(); bones.resize(bonesNum); // For all bones for(uint i=0; i= bonesNum) { throw EXCEPTION("Incorrect parent id"); } else { bone.parent = &bones[parentId]; } // Children uint childsNum = bs.readUint(); if(childsNum > Bone::MAX_CHILDS_PER_BONE) { throw EXCEPTION("Children for bone \"" + bone.getName() + "\" exceed the max"); } bone.childsNum = childsNum; for(uint j=0; j= bonesNum) { throw EXCEPTION("Incorrect child id"); } bone.childs[j] = &bones[id]; } } } catch(std::exception& e) { throw EXCEPTION("Skeleton \"" + filename + "\": " + e.what()); } }