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; }
void SkeletonData::readAnimations(JsonTree animations, Joint * j){ readAnimation(animations.getChild("translateX"), j->translateX); readAnimation(animations.getChild("translateY"), j->translateY); readAnimation(animations.getChild("translateZ"), j->translateZ); readAnimation(animations.getChild("rotate"), j->rotate); readAnimation(animations.getChild("scaleX"), j->scaleX); readAnimation(animations.getChild("scaleY"), j->scaleY); readAnimation(animations.getChild("scaleZ"), j->scaleX); }
std::string Server::sendVkSharePlus() { if (!RELEASE_VER) return SERVER_OK; std::map<string,string> strings; strings.insert(pair<string, string>( "action" , "cnt")); strings.insert(pair<string, string>( "cnt" , "1")); strings.insert(pair<string, string>( "type" , "vk")); string request = Curl::post( SERVER"/save.php", strings); JsonTree jTree; try { jTree = JsonTree(request); console()<<"VKONTAKTE PLUS "<< jTree.getChild("cnt").getValue()<<std::endl; return SERVER_OK; } catch(...) { } return SERVER_ERROR; }
void PretzelGlobal::loadSettings(fs::path settingsPath){ fs::path loadPath = settingsPath; if (loadPath.string() == ""){ loadPath = getAppPath() / "guiSettings" / "settings.json"; } if (!fs::exists(loadPath)){ console() << loadPath << " does not exist" << endl; } else{ JsonTree loadTree(loadFile(loadPath)); JsonTree appSettings = loadTree.getChild(0); for (int i = 0; i < mParamList.size(); i++){ string pName = mParamList[i].name; switch (mParamList[i].type){ case _FLOAT: if (appSettings.hasChild(pName)){ float fVal = appSettings.getChild(pName).getValue<float>(); *((float*)mParamList[i].value) = fVal; } break; case _INT: if (appSettings.hasChild(pName)){ int fVal = appSettings.getChild(pName).getValue<int>(); *((int*)mParamList[i].value) = fVal; } break; case _BOOL: if (appSettings.hasChild(pName)){ bool bVal = appSettings.getChild(pName).getValue<float>(); *((bool*)mParamList[i].value) = bVal; } break; default: console() << "Pretzel :: Can't load settings type " << endl; break; } } } }
void EmailForm::sendToServerThread() { ci::ThreadSetup threadSetup; // instantiate this if you're talking to Cinder from a secondary thread isSendingToServer = true; string allEmails = ""; for (size_t i = 0; i < emailVector.size(); i++) { if ( i != emailVector.size()-1) { allEmails +=emailVector[i] +","; } else allEmails +=emailVector[i]; } console()<<"SEND TO EMAILS:: "<<allEmails<<std::endl; std::map<string,string> strings; strings.insert(pair<string, string>( "action" , "mail")); strings.insert(pair<string, string>( "id" , Params::sessionId)); strings.insert(pair<string, string>( "email" , allEmails)); string request = Curl::post( SERVER"/save.php", strings); JsonTree jTree; console()<<"SERVER ANSWER TO SEND MAILS "<<request<<std::endl; try { jTree = JsonTree(request); string success = jTree.getChild("success").getValue(); if (success == "1") { SERVER_STATUS = "OK"; } else { SERVER_STATUS = "ERROR"; touchKeyBoard.removeHandlers(); } } catch (... ) { SERVER_STATUS = "ERROR"; touchKeyBoard.removeHandlers(); } isSendingToServer = false; serverThread->detach(); }
void ColorCubePoints::fromJson(const JsonTree &tree) { clear(); mOrigin = tree.getValueForKey<float>("origin"); const JsonTree& points = tree.getChild("points"); for (unsigned i = 0; i < points.getNumChildren(); i++) { const JsonTree& point = points.getChild(i); push(point.getValueAtIndex<float>(0), point.getValueAtIndex<float>(1), point.getValueAtIndex<float>(2)); } }
//! from json void WarpPerspectiveBilinear::fromJson(const JsonTree &json) { Warp::fromJson(json); if (json.hasChild("warp")) { JsonTree warp(json.getChild("warp")); // get corners JsonTree corners(warp.getChild("corners")); for (size_t i = 0; i < corners.getNumChildren(); i++) { JsonTree child = corners.getChild(i); float x = (child.hasChild("x")) ? child.getValueForKey<float>("x") : 0.0f; float y = (child.hasChild("y")) ? child.getValueForKey<float>("y") : 0.0f; mWarp->setControlPoint(i, vec2(x, y)); CI_LOG_V("corner:" + toString(x) + " " + toString(y)); } } }
void View::load( const JsonTree &data ) { if( data.hasChild( "SUBVIEWS" ) && mLoadSubViews ) { JsonTree tree = data.getChild( "SUBVIEWS" ); int numSubViews = tree.getNumChildren(); for(int i = 0; i < numSubViews; i++) { JsonTree sub = tree[i]; ViewRef subview = getSubView( sub.getValueForKey( "NAME" ) ); if( subview ) { subview->load( sub ); } } } }
// Function the background thread lives in void TweetStream::serviceTweets() { ThreadSetup threadSetup; std::string nextQueryString = "?q=" + Url::encode( mSearchPhrase ); JsonTree searchResults; JsonTree::ConstIter resultIt = searchResults.end(); // This function loops until the app quits. Each iteration a pulls out the next result from the Twitter API query. // When it reaches the last result of the current query it issues a new one, based on the "refresh_url" property // of the current query. // The loop doesn't spin (max out the processor) because ConcurrentCircularBuffer.pushFront() non-busy-waits for a new // slot in the circular buffer to become available. while( ! mCanceled ) { if( resultIt == searchResults.end() ) { // are we at the end of the results of this JSON query? // issue a new query try { JsonTree queryResult = queryTwitter( nextQueryString ); // the next query will be the "refresh_url" of this one. nextQueryString = queryResult["refresh_url"].getValue(); searchResults = queryResult.getChild( "results" ); resultIt = searchResults.begin(); } catch( ci::Exception &exc ) { // our API query failed: put up a "tweet" with our error CI_LOG_W( "exception caught parsing query: " << exc.what() ); mBuffer.pushFront( Tweet( "Twitter API query failed", "sadness", SurfaceRef() ) ); ci::sleep( 2000 ); // try again in 2 seconds } } if( resultIt != searchResults.end() ) { try { // get the URL and load the image for this profile Url profileImgUrl = (*resultIt)["profile_image_url"].getValue<Url>(); SurfaceRef userIcon = Surface::create( loadImage( loadUrl( profileImgUrl ) ) ); // pull out the text of the tweet and replace any XML-style escapes string text = replaceEscapes( (*resultIt)["text"].getValue() ); string userName = (*resultIt)["from_user"].getValue(); mBuffer.pushFront( Tweet( text, userName, userIcon ) ); } catch( ci::Exception &exc ) { CI_LOG_W( "exception caught parsing search results: " << exc.what() ); } ++resultIt; } } }
bool Twitter::postPhotoTweet(string status, vector<string> filesPath) { if (!isAuthFlowComplete) return false; int max_media_per_upload; std::string replyMsg = ""; if( twitterObj.getTwitterConfiguration()) { twitterObj.getLastWebResponse( replyMsg ); try { JsonTree jTree = JsonTree(replyMsg); max_media_per_upload = atoi(jTree.getChild("max_media_per_upload").getValue().c_str()); } catch(...){}; } else { twitterObj.getLastCurlError( replyMsg ); console()<<"twitterClient:: twitCurl::statusUpdate error: "<< replyMsg.c_str()<<std::endl; return false; } vector<string> filelinks; for (int i = 0; i < max_media_per_upload; i++) { console()<<"path :: "<<filesPath[i]<<std::endl; filelinks.push_back(filesPath[i]); } if( twitterObj.uploadPictureFromFile(filelinks, Utils::cp1251_to_utf8(status.c_str()) )) { twitterObj.getLastWebResponse( replyMsg ); console()<<"twitterClient:: twitCurl:: statusUpdate web response: "<< replyMsg.c_str()<<std::endl; return true; } else { twitterObj.getLastCurlError( replyMsg ); console()<<"twitterClient:: twitCurl:: statusUpdate error: "<< replyMsg.c_str()<<std::endl; return false; } }
//! to json JsonTree WarpPerspectiveBilinear::toJson() const { JsonTree json = WarpBilinear::toJson(); if (json.hasChild("warp")) { JsonTree warp(json.getChild("warp")); // set corners JsonTree corners = JsonTree::makeArray("corners"); for (unsigned i = 0; i < 4; ++i) { vec2 corner = mWarp->getControlPoint(i); JsonTree cr; cr.addChild(ci::JsonTree("corner", i)); cr.addChild(ci::JsonTree("x", corner.x)); cr.addChild(ci::JsonTree("y", corner.y)); corners.pushBack(cr); } warp.pushBack(corners); json.pushBack(warp); } return json; }
std::string Server::sendToServerPrintInfo() { if (!RELEASE_VER) return SERVER_OK; std::map<string,string> strings; strings.insert(pair<string, string>( "action" , "print_count")); strings.insert(pair<string, string>( "cnt" , "1")); string request = Curl::post( SERVER"/save.php", strings); JsonTree jTree; try { jTree = JsonTree(request); console()<<"PHOTO NUMS "<< jTree.getChild("cnt").getValue()<<std::endl; return SERVER_OK; } catch(...) { } return SERVER_ERROR; }
void FaceController::loadFaces() { /* JsonTree faces( doc.getChild( "faces" ) ); facesStoreVector.clear(); for( JsonTree::ConstIter face = faces.begin(); face != faces.end(); ++face ) { FaceObject newFace; vector<Vec2f> points; string name = face->getChild( "texname" ).getValue<string>(); gl::Texture tex; try{ tex = loadImage(getAppPath() /FACE_STORAGE_FOLDER/name); } catch(...) { continue; } JsonTree datas =JsonTree( face->getChild( "data" )); for( JsonTree::ConstIter data = datas.begin(); data != datas.end(); ++data ) { float x = data->getChild( "x" ).getValue<float>(); float y = data->getChild( "y" ).getValue<float>(); points.push_back(Vec2f(x,y)); } newFace.setPoints(points); newFace.setTexName(name); newFace.setTexture(tex); facesStoreVector.push_back(newFace); } */ facesStoreVector.clear(); string path = getAppPath().string() + JSON_STORAGE_FOLDER; fs::path p(path); for (fs::directory_iterator it(p); it != fs::directory_iterator(); ++it) { if (fs::is_regular_file(*it)) { JsonTree doc; try{ doc = JsonTree(loadFile(getAppPath() / JSON_STORAGE_FOLDER / it->path().filename().string())); } catch(...) { return; } JsonTree faces( doc.getChild( "faces" ) ); for( JsonTree::ConstIter face = faces.begin(); face != faces.end(); ++face ) { FaceObject newFace; vector<Vec2f> points; string name = face->getChild( "texname" ).getValue<string>(); gl::Texture tex; try{ tex = loadImage(getAppPath() /FACE_STORAGE_FOLDER/name); } catch(...) { continue; } JsonTree datas =JsonTree( face->getChild( "data" )); for( JsonTree::ConstIter data = datas.begin(); data != datas.end(); ++data ) { float x = data->getChild( "x" ).getValue<float>(); float y = data->getChild( "y" ).getValue<float>(); points.push_back(Vec2f(x,y)); } newFace.setPoints(points); newFace.setTexName(name); newFace.setTexture(tex); facesStoreVector.push_back(newFace); } } } }
ChattyPostDataRef getChattyPostDataRefFromJSONPost(const JsonTree& post) { ChattyPostDataRef post_data_ref = ChattyPostData::create(); post_data_ref->m_id = fromString<uint32_t>(post["id"].getValue()); post_data_ref->m_thread_id = fromString<uint32_t>(post["threadId"].getValue()); post_data_ref->m_parent_id = fromString<uint32_t>(post["parentId"].getValue()); post_data_ref->m_author = post["author"].getValue(); post_data_ref->m_body = post["body"].getValue(); replaceEncodingsInString(post_data_ref->m_body); std::string strvalue = post["category"].getValue(); if(strvalue.length() > 0) { if(strvalue == "ontopic") post_data_ref->m_category = category_type::NORMAL; else if(strvalue == "nws") post_data_ref->m_category = category_type::NWS; else if(strvalue == "stupid") post_data_ref->m_category = category_type::STUPID; else if(strvalue == "political") post_data_ref->m_category = category_type::POLITICAL; else if(strvalue == "tangent") post_data_ref->m_category = category_type::OFFTOPIC; else if(strvalue == "informative") post_data_ref->m_category = category_type::INFORMATIVE; else if(strvalue == "nuked") post_data_ref->m_category = category_type::NUKED; } strvalue = post["date"].getValue(); if(strvalue.length() > 0) { std::tm post_time; memset(&post_time, 0, sizeof(std::tm)); #if defined(CINDER_MSW) sscanf_s(strvalue.c_str(), "%d-%d-%dT%d:%d", &post_time.tm_year, &post_time.tm_mon, &post_time.tm_mday, &post_time.tm_hour, &post_time.tm_min); #else sscanf(strvalue.c_str(), "%d-%d-%dT%d:%d", &post_time.tm_year, &post_time.tm_mon, &post_time.tm_mday, &post_time.tm_hour, &post_time.tm_min); #endif post_time.tm_year -= 1900; post_time.tm_mon -= 1; #if defined(CINDER_MSW) post_data_ref->m_date_time = _mkgmtime(&post_time); #else post_data_ref->m_date_time = timegm(&post_time); // and I have no idea if this is right #endif // if mac doesn't have _mkgmtime, need to find a way to convert UTC to local //post_data_ref->m_date_time = std::mktime(&post_time); } if(post.hasChild("lols")) { const JsonTree& lols = post.getChild("lols"); for(size_t lol_i = 0; lol_i < lols.getNumChildren(); lol_i++) { const JsonTree& lol = lols.getChild(lol_i); strvalue = lol["tag"].getValue(); if(strvalue.length() > 0) { lol_type which_lol = LOL; if(strvalue == "lol") which_lol = lol_type::LOL; else if(strvalue == "inf") which_lol = lol_type::INF; else if(strvalue == "unf") which_lol = lol_type::UNF; else if(strvalue == "tag") which_lol = lol_type::TAG; else if(strvalue == "wtf") which_lol = lol_type::WTF; else if(strvalue == "ugh") which_lol = lol_type::UGH; post_data_ref->m_lol_count[which_lol] = fromString<unsigned int>(lol["count"].getValue()); } } } return post_data_ref; }
void TreeHeartbeat::getNewEvents() { try { JsonTree queryResult = queryWinChattyv2Server("waitForEvent?lastEventId=" + toString(m_last_event_id)); if(queryResult.hasChild("lastEventId")) { std::string strvalue = queryResult["lastEventId"].getValue(); if(strvalue.length() > 0) { m_last_event_id = fromString<uint32_t>(strvalue); } if(queryResult.hasChild("events")) { AppMessageRef worldTreeEventMessage = AppMessage::create(AppMessage::message_type::WORLDTREE_EVENT); const JsonTree& events = queryResult.getChild("events"); for(size_t event_i = 0; event_i < events.getNumChildren(); event_i++) { const JsonTree& this_event = events.getChild(event_i); const JsonTree& event_data = this_event.getChild("eventData"); strvalue = this_event["eventType"].getValue(); if(strvalue == "newPost") { const JsonTree& post = event_data.getChild("post"); worldTreeEventMessage->AsWorldTreeEvent()->m_new_posts_list.push_front(getChattyPostDataRefFromJSONPost(post)); } else if(strvalue == "categoryChange") { } else if(strvalue == "serverMessage") { } else if(strvalue == "lolCountsUpdate") { } } sortChattyPostDataList(worldTreeEventMessage->AsWorldTreeEvent()->m_new_posts_list); if(!m_canceled) { ((LampApp*)app::App::get())->postMessage(worldTreeEventMessage); } } } else { ci::sleep(2000.0f); } } catch(ci::Exception& exc) { CI_LOG_E("Error calling WCv2 method waitForEvent: " << exc.what()); ci::sleep(2000.0f); } }
void TreeHeartbeat::getWorldTree() { getLastEventId(); try { JsonTree queryResult = queryWinChattyv2Server("getChatty"); if(queryResult.hasChild("threads")) { AppMessageRef worldTreeBuiltMessage = AppMessage::create(AppMessage::message_type::WORLDTREE_BUILT); const JsonTree& threads = queryResult.getChild("threads"); for(size_t thread_i = 0; thread_i < threads.getNumChildren(); thread_i++) { std::list<ChattyPostDataRef> list_of_posts_in_thread; const JsonTree& this_thread = threads.getChild(thread_i); if(this_thread.hasChild("posts")) { const JsonTree& posts = this_thread.getChild("posts"); for(size_t post_i = 0; post_i < posts.getNumChildren(); post_i++) { const JsonTree& post = posts.getChild(post_i); list_of_posts_in_thread.push_back(getChattyPostDataRefFromJSONPost(post)); } } // sort list into tree chatty_post_id thread_id = fromString<uint32_t>(this_thread["threadId"].getValue()); ChattyPostDataRef thread_tree; for(std::list<ChattyPostDataRef>::iterator it = list_of_posts_in_thread.begin(); it != list_of_posts_in_thread.end(); it++) { if((*it)->m_id == thread_id) { thread_tree = *it; list_of_posts_in_thread.erase(it); break; } } if(thread_tree) { thread_tree->adoptChildren(list_of_posts_in_thread); CI_ASSERT(list_of_posts_in_thread.size() == 0); } thread_tree->markAsRead(false); // add tree to list of thread trees worldTreeBuiltMessage->AsWorldTreeBuilt()->m_thread_tree_list.push_back(thread_tree); } if(!m_canceled) { ((LampApp*)app::App::get())->postMessage(worldTreeBuiltMessage); } } } catch(ci::Exception& exc) { CI_LOG_E("Error calling WCv2 method getChatty: " << exc.what()); m_last_event_id = 0; } }
// Function the background thread lives in void InstagramStream::serviceGrams(string url) { ThreadSetup threadSetup; std::string nextQueryString = url; JsonTree searchResults; JsonTree::ConstIter resultIt = searchResults.end(); // This function loops until the app quits. Each iteration a pulls out the next result from the Twitter API query. // When it reaches the last result of the current query it issues a new one, based on the "refresh_url" property // of the current query. // The loop doesn't spin (max out the processor) because ConcurrentCircularBuffer.pushFront() non-busy-waits for a new // slot in the circular buffer to become available. JsonTree queryResult; while( ! mCanceled ) { if( resultIt == searchResults.end() ) { // are we at the end of the results of this JSON query? // issue a new query try { queryResult = queryInstagram( nextQueryString ); // the next query will be the "refresh_url" of this one. try { nextQueryString = queryResult["pagination"].getChild("next_url").getValue(); } catch(...) { } searchResults = queryResult.getChild("data"); resultIt = searchResults.begin(); mIsConnected = true; } catch( ... ) { console() << "something broke" << endl; console() << queryResult << endl; console() << nextQueryString << endl; // check if it's a 420 error if(queryResult.getChild("meta").getChild("code").getValue() == "420"){ console() << "420 error" << endl; mIsConnected = false; } ci::sleep( 1000 ); // try again in 1 second } } if( resultIt != searchResults.end() ) { try { string userName = (*resultIt)["user"]["username"].getValue(); // get the URL and load this instagram image string imageUrl = (*resultIt)["images"]["standard_resolution"]["url"].getValue(); Surface image( loadImage( loadUrl( imageUrl ) ) ); // string imageUrl = "http://distilleryimage5.s3.amazonaws.com/1dd174cca14611e1af7612313813f8e8_7.jpg"; // Test image mBuffer.pushFront( Instagram( userName, imageUrl, image ) ); } catch( ... ) { // just ignore any errors console() << "ERRORS FOUND" << endl; } ++resultIt; } } }
void SkeletonData::readVoxel(JsonTree voxel, Joint * parent){ // create voxel, added to parent in constructor Voxel * v = new Voxel(Vec3d(voxel.getChild("x").getValue<float>(), voxel.getChild("y").getValue<float>(), voxel.getChild("z").getValue<float>()), parent, false); parent->addChild(v); }
using namespace ci; using namespace ci::app; using namespace std; TEST_CASE("Json", "[noisy]") { SECTION("Basic JSON Parsing") { console() << "jsoncpp version: " << JSONCPP_VERSION_STRING << endl; JsonTree value( "key", "value" ); console() << value << endl; JsonTree doc( loadFile( "data/library.json" ) ); JsonTree musicLibrary( doc.getChild( "library" ) ); JsonTree owner = doc.getChild( "library.owner" ); for( JsonTree::ConstIter item = owner.begin(); item != owner.end(); ++item ) { console() << "Node: " << item->getKey() << " Value: " << item->getValue<string>() << endl; } JsonTree tracks = doc.getChild( "library.albums[0].tracks" ); for( JsonTree::ConstIter track = tracks.begin(); track != tracks.end(); ++track ) { console() << track->getChild( "id" ).getValue<int>() << endl; } for( JsonTree::ConstIter trackIt = tracks.begin(); trackIt != tracks.end(); ++trackIt ) { JsonTree track = * trackIt; console() << track["id"].getValue<int>() << endl; }
void ReymentaServerApp::fileDrop(FileDropEvent event) { int index; string ext = ""; // use the last of the dropped files const fs::path &mPath = event.getFile(event.getNumFiles() - 1); string mFile = mPath.string(); int dotIndex = mFile.find_last_of("."); int slashIndex = mFile.find_last_of("\\"); if (dotIndex != std::string::npos && dotIndex > slashIndex) ext = mFile.substr(mFile.find_last_of(".") + 1); index = (int)(event.getX() / (margin + mParameterBag->mPreviewFboWidth + inBetween));// +1; //mBatchass->log(mFile + " dropped, currentSelectedIndex:" + toString(mParameterBag->currentSelectedIndex) + " x: " + toString(event.getX()) + " PreviewFboWidth: " + toString(mParameterBag->mPreviewFboWidth)); if (ext == "wav" || ext == "mp3") { //mAudio->loadWaveFile(mFile); } else if (ext == "png" || ext == "jpg") { if (index < 1) index = 1; if (index > 3) index = 3; //mTextures->loadImageFile(mParameterBag->currentSelectedIndex, mFile); mBatchass->getTexturesRef()->loadImageFile(index, mFile); } else if (ext == "glsl") { if (index < 4) index = 4; int rtn = mBatchass->getShadersRef()->loadPixelFragmentShaderAtIndex(mFile, index); if (rtn > -1 && rtn < mBatchass->getShadersRef()->getCount()) { mParameterBag->controlValues[22] = 1.0f; // TODO send content via websockets /*fs::path fr = mFile; string name = "unknown"; if (mFile.find_last_of("\\") != std::string::npos) name = mFile.substr(mFile.find_last_of("\\") + 1); if (fs::exists(fr)) { std::string fs = loadString(loadFile(mFile)); if (mParameterBag->mOSCEnabled) mOSC->sendOSCStringMessage("/fs", 0, fs, name); }*/ // save thumb //timeline().apply(&mTimer, 1.0f, 1.0f).finishFn([&]{ saveThumb(); }); } } else if (ext == "mov" || ext == "mp4") { /* if (index < 1) index = 1; if (index > 3) index = 3; mBatchass->getTexturesRef()->loadMovieFile(index, mFile);*/ } else if (ext == "fs") { //mShaders->incrementPreviewIndex(); mBatchass->getShadersRef()->loadFragmentShader(mPath); } else if (ext == "xml") { mBatchass->getWarpsRef()->loadWarps(mFile); } else if (ext == "patchjson") { // try loading patch try { JsonTree patchjson; try { patchjson = JsonTree(loadFile(mFile)); mParameterBag->mCurrentFilePath = mFile; } catch (cinder::JsonTree::Exception exception) { CI_LOG_V("patchjsonparser exception " + mFile + ": " + exception.what()); } //Assets int i = 1; // 0 is audio JsonTree jsons = patchjson.getChild("assets"); for (JsonTree::ConstIter jsonElement = jsons.begin(); jsonElement != jsons.end(); ++jsonElement) { string jsonFileName = jsonElement->getChild("filename").getValue<string>(); int channel = jsonElement->getChild("channel").getValue<int>(); if (channel < mBatchass->getTexturesRef()->getTextureCount()) { CI_LOG_V("asset filename: " + jsonFileName); mBatchass->getTexturesRef()->setTexture(channel, jsonFileName); } i++; } } catch (...) { CI_LOG_V("patchjson parsing error: " + mFile); } } else if (ext == "txt") { // try loading shader parts if (mBatchass->getShadersRef()->loadTextFile(mFile)) { } } else if (ext == "") { // try loading image sequence from dir if (index < 1) index = 1; if (index > 3) index = 3; mBatchass->getTexturesRef()->createFromDir(mFile + "/", index); // or create thumbs from shaders mBatchass->getShadersRef()->createThumbsFromDir(mFile + "/"); } }
void PretzelGlobal::loadSettings(fs::path settingsPath){ fs::path loadPath = settingsPath; if (loadPath.string() == ""){ loadPath = getAppPath() / "guiSettings" / "settings.json"; } if (!fs::exists(loadPath)){ CI_LOG_W("Pretzel :: Can't load ") << loadPath << " Path does not exist."; } else{ JsonTree loadTree(loadFile(loadPath)); JsonTree appSettings = loadTree.getChild(0); for (int i = 0; i < mParamList.size(); i++){ string pName = mParamList[i].name; switch (mParamList[i].type){ case _FLOAT: if (appSettings.hasChild(pName)){ float fVal = appSettings.getChild(pName).getValue<float>(); *((float*)mParamList[i].value) = fVal; } break; case _INT: if (appSettings.hasChild(pName)){ int fVal = appSettings.getChild(pName).getValue<int>(); *((int*)mParamList[i].value) = fVal; } break; case _BOOL: if (appSettings.hasChild(pName)){ bool bVal = appSettings.getChild(pName).getValue<float>(); *((bool*)mParamList[i].value) = bVal; } break; case _STRING: if (appSettings.hasChild(pName)){ std::string sVal = appSettings.getChild(pName).getValue<std::string>(); *((std::string*)mParamList[i].value) = sVal; } break; case _VEC2: if (appSettings.hasChild(pName)){ vec2 p; p.x = appSettings.getChild(pName).getChild("x").getValue<float>(); p.y = appSettings.getChild(pName).getChild("y").getValue<float>(); *((vec2*)mParamList[i].value) = p; } break; case _VEC3: if (appSettings.hasChild(pName)){ vec3 p; p.x = appSettings.getChild(pName).getChild("x").getValue<float>(); p.y = appSettings.getChild(pName).getChild("y").getValue<float>(); p.z = appSettings.getChild(pName).getChild("z").getValue<float>(); *((vec3*)mParamList[i].value) = p; } break; case _COLOR: if (appSettings.hasChild(pName)){ Color p; p.r = appSettings.getChild(pName).getChild("r").getValue<float>(); p.g = appSettings.getChild(pName).getChild("g").getValue<float>(); p.b = appSettings.getChild(pName).getChild("b").getValue<float>(); *((Color*)mParamList[i].value) = p; } break; case _COLORA: if (appSettings.hasChild(pName)){ ColorA p; p.r = appSettings.getChild(pName).getChild("r").getValue<float>(); p.g = appSettings.getChild(pName).getChild("g").getValue<float>(); p.b = appSettings.getChild(pName).getChild("b").getValue<float>(); p.a = appSettings.getChild(pName).getChild("a").getValue<float>(); *((ColorA*)mParamList[i].value) = p; } break; default: CI_LOG_W( "Pretzel :: Unrecognized settings type."); break; } } } signalOnSettingsLoad.emit(); }
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; }