std::vector<Joint *> SkeletonData::LoadSkeleton(std::string filePath) { //Not sure about this error catching setup std::vector<Joint*> joints; if( PathFileExistsA(filePath.c_str()) == TRUE) { try{ JsonTree doc = JsonTree(loadFile(filePath)); JsonTree jointsJson = doc.getChild( "joints" ); Joint * parent = nullptr; unsigned int i = 0; for( JsonTree::ConstIter joint = jointsJson.begin(); joint != jointsJson.end(); ++joint ) { // Apparently, getKey DOESN't return an index if there is no key? (Even though it says it will in the json.h header...) //JsonTree jJson = jointsJson.getChild(joint->getKey()); JsonTree jJson = jointsJson.getChild(i); Joint * j = readJoint(jJson); joints.push_back(j); i++; } }catch (std::exception ex) { //throw ex; throw std::exception("Invalid File Format. File may be out of date."); } }else{ throw std::exception("File does not exist!"); } return joints; }
Joint * SkeletonData::readJoint(JsonTree joint, Joint * parent) { Joint * j = new Joint(); if(parent != nullptr){ parent->addChild(j); } std::vector<NodeChild *> children; std::vector<Voxel *> voxels; j->id = joint.getChild( "id" ).getValue<int>(); app::console() << "id: " << j->id << std::endl; // Transform: Object JsonTree transform = joint.getChild("transform"); JsonTree pos = transform.getChild("pos"); app::console() << " jt_pos: x = " << pos.getChild("x").getValue<float>() << " y = " << pos.getChild("y").getValue<float>() << " pos: z = " << pos.getChild("z").getValue<float>() << std::endl; j->setPos(glm::vec3(pos.getChild("x").getValue<float>(), pos.getChild("y").getValue<float>(), pos.getChild("z").getValue<float>()), false); app::console() << " pos: x = " << j->getPos().x << " y = " << j->getPos().y << " pos: z = " << j->getPos().z << std::endl; JsonTree orientation = transform.getChild("orientation"); j->transform->orientation = glm::quat(orientation.getChild("w").getValue<float>(), orientation.getChild("x").getValue<float>(), orientation.getChild("y").getValue<float>(), orientation.getChild("z").getValue<float>()); app::console() << " orientation: x = " << j->transform->orientation.x << " y = " << j->transform->orientation.y << " z = " << j->transform->orientation.z << " w = " << j->transform->orientation.w << std::endl; JsonTree scale = transform.getChild("scaleVector"); j->transform->scaleVector = glm::vec3(scale.getChild("x").getValue<float>(), scale.getChild("y").getValue<float>(), scale.getChild("z").getValue<float>()); app::console() << " scale: x = " << j->transform->scaleVector.x << " y = " << j->transform->scaleVector.y << " z = " << j->transform->scaleVector.z << std::endl; // Voxels: Array JsonTree voxelsJson = joint.getChild("voxels"); unsigned int voxel_index = 0; for (JsonTree::ConstIter voxel = voxelsJson.begin(); voxel != voxelsJson.end(); ++voxel) { // Apparently, getKey DOESN't return an index if there is no key? //JsonTree cJson = childrenJson.getChild(child->getKey()); JsonTree vJson = voxelsJson.getChild(voxel_index); readVoxel(vJson, j); voxel_index++; } // Animations: Objects readAnimations(joint.getChild("animations"), j); // Children: Array JsonTree childrenJson = joint.getChild("children"); unsigned int children_index = 0; for( JsonTree::ConstIter child = childrenJson.begin(); child != childrenJson.end(); ++child ) { // Apparently, getKey DOESN't return an index if there is no key? //JsonTree cJson = childrenJson.getChild(child->getKey()); JsonTree cJson = childrenJson.getChild(children_index); Joint * c = readJoint(cJson, j); children.push_back(c); children_index++; } j->children = children; return j; }
void BVH::read(std::istream& in) { //int lineIndex = 0; std::string line; while( in && !in.eof() ) { //lineIndex++; std::getline(in,line); if ( in.bad() ){ std::cout << " Warning! Could not read file properly! BVH part: skeleton"<<std::endl; } trimString(line); if ( line.size() == 0 || line[0] == '#' || isspace(line[0]) || line.empty() ) { continue; } std::string keyWrd; std::stringstream stream(line); stream >> keyWrd; if(!stream.fail()) { if(keyWrd == "HIERARCHY") { //#if defined(_DEBUG) || defined(DEBUG) // std::cout<<"HIERARCHY " <<std::endl; //#endif } else if(keyWrd == "ROOT") { //#if defined(_DEBUG) || defined(DEBUG) // std::cout<<"Root " <<std::endl; //#endif stream >> keyWrd; readJoint(in, keyWrd); } else if(keyWrd == "MOTION") { //#if defined(_DEBUG) || defined(DEBUG) // std::cout<<"MOTION " <<std::endl; //#endif stream >> keyWrd; readFrames(in); }