Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.98 KB | None | 0 0
  1. function<void(string &)> find_marker_response = [](string &data)
  2. {
  3.     string err, image, guid;
  4.     bool group = false;
  5.     json11::Json marker = json11::Json::parse(data, err);
  6.     image = marker["image"].string_value();
  7.     guid = marker["marker_id"].string_value();
  8.     if (!marker["group"].is_null())
  9.         group = marker["group"].bool_value();
  10.  
  11.     if (markers.getRID(guid) != -1 /*&& markers.beenLoaded(guid)*/)
  12.     {
  13.         return;
  14.     }
  15.  
  16.     FILE *out = fopen((WorkPath + "/Augment/" + guid).c_str(), "wb");
  17.     if (!out)
  18.     {
  19.         return;
  20.     }
  21.     loading = true;
  22.     string img = WebUtil::base64_decode(image);
  23.     fwrite(img.data(), img.size(), sizeof(char), out);
  24.     fclose(out);
  25.  
  26.     int id;
  27.     easyar::Vec2F sz;
  28.     auto target = loadFromImage(trackers[0], (WorkPath + "/Augment/" + guid), guid, sz);
  29.     markers.addMarkerInfo(guid, target, target->runtimeID(), group);
  30.     remove((WorkPath + "/Augment/" + guid).c_str());
  31.  
  32.     if (!scene.GetSceneObject(guid).empty())
  33.     {
  34.         loading = false;
  35.         return;
  36.     }
  37.  
  38.     LoadingEffect* effect = new LoadingEffect;
  39.     effect->setRectSize(sz.data[0], sz.data[1]);
  40.     effect->enableEffect();
  41.     scene.AddObject(effect, guid);
  42.  
  43.     net.GetMarkerResources(guid, [&](json11::Json &in)
  44.     {
  45.         MarkerInfo.addInfo(guid, guid, in["likes"].int_value(), in["liked"].bool_value());
  46.         auto arr = in["resources"].array_items();
  47.         for (int i = 0; i < arr.size(); i++)
  48.         {
  49.             if (arr[i]["type"].string_value() == "contact")
  50.             {
  51.                 string contact;
  52.                 net.GetContact(arr[i]["id"].string_value(), contact);
  53.                 ContactManager.addContact(guid, contact);
  54.             }
  55.             if (arr[i]["type"].string_value() == "document")
  56.             {
  57.                 ContactManager.addDocument(guid, arr[i]["name"].string_value(), arr[i]["id"].string_value());
  58.             }
  59.             if (arr[i]["type"].string_value() == "video")
  60.             {
  61.                 VideoRect* resource = new VideoRect;
  62.                 resource->SetRectSize(sz.data[0], sz.data[1]);
  63.                 scene.AddObject(resource, guid);
  64.                 std::string mask_img = "";
  65.                 if (!arr[i]["mask"].is_null())
  66.                 {
  67.                     mask_img = WebUtil::base64_decode(arr[i]["mask"].string_value());
  68.                 }
  69.                 resource->SetupVideoSource(net.GetAddres() + ":3005/video/" + arr[i]["id"].string_value(), mask_img);
  70.                 //resource->SetupVideoSource("http://192.168.88.253:8080/video/mjpeg", mask_img);
  71.                 //resource->SetupVideoSource(net.GetAddres() + "/video/" + arr[i]["id"].string_value());
  72.                 VideoManager.add_player(&resource->player);
  73.             }
  74.             if (arr[i]["type"].string_value() == "audio")
  75.             {
  76.                 AudioSource* resource = new AudioSource;
  77.                 scene.AddObject(resource, guid);
  78.                 resource->SetupAudioSource(net.GetAddres() + ":3005/audio/" + arr[i]["id"].string_value());
  79.                 VideoManager.add_player(&resource->player);
  80.             }
  81.             if (arr[i]["type"].string_value() == "model")
  82.             {
  83.                 map<string, CTexture*> textures;
  84.                 Mesh *m = new Mesh;
  85.                 vector<json11::Json> pos, rot, scl;
  86.                 json11::Json trs = arr[i]["position"];
  87.                 if (!trs.is_null())
  88.                 {
  89.                     pos = trs["translation"].array_items();
  90.                     rot = trs["rotation"].array_items();
  91.                     scl = trs["scale"].array_items();
  92.                 }
  93.                 else
  94.                 {
  95.                     pos = arr[i]["translation"].array_items();
  96.                     rot = arr[i]["rotation"].array_items();
  97.                     scl = arr[i]["scale"].array_items();
  98.                 }
  99.  
  100.                 json11::Json j;
  101.                 net.GetModel(arr[i]["id"].string_value(), j);
  102.                 //m->SetBaseScale(scl[0].number_value()*0.175, scl[1].number_value()*0.175, scl[2].number_value()*0.175);
  103.                 m->SetBaseScale(-scl[0].number_value(), scl[1].number_value(), scl[2].number_value());
  104.                 string decoded = WebUtil::base64_decode(j["model"].string_value());
  105.                 auto tex = j["files"].array_items();
  106.                 for (int j = 0; j < tex.size(); j++)
  107.                 {
  108.                     string data = WebUtil::base64_decode(tex[j]["file"].string_value());
  109.                     textures[tex[j]["name"].string_value()] = new CTexture;
  110.                     textures[tex[j]["name"].string_value()]->loadTexture2DDeffered((unsigned char*)&data[0], (int)data.size(), true, 0);
  111.                 }
  112.                 m->LoadFromMemory(decoded, textures);
  113.                 scene.AddObject(m, guid);
  114.             }
  115.         }
  116.     });
  117.     effect->disableEffect();
  118.     loading = false;
  119. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement