Example #1
0
Scene Scene::load(const std::string &filename, const json11::Json &settings) {
    std::ifstream is(filename);
    std::stringstream ss;
    ss << is.rdbuf();

    std::string err;
    Json jsonRoot = Json::parse(ss.str(), err);
    if (jsonRoot.is_null()) {
        throw Exception("Failed to load scene from '%s' (error: %s)", filename, err);
    }

    _resolver = filesystem::resolver();
    _resolver.prepend(filesystem::path(filename).parent_path());

    Scene scene;

    // Patch settings
    auto settingsValues = jsonRoot["settings"].object_items();
    for (auto kv : settings.object_items()) {
        settingsValues[kv.first] = kv.second;
    }
    scene.settings = Properties(json11::Json(settingsValues));

    // Parse scene objects
    Json jsonScene = jsonRoot["scene"];
    if (jsonScene.is_object()) {
        auto jsonCamera = jsonScene["camera"];
        if (jsonCamera.is_object()) {
            Properties props(jsonCamera);
            scene.camera = Camera(jsonCamera);
        }
        auto jsonWorld = jsonScene["world"];
        if (jsonWorld.is_object()) {
            Properties props(jsonWorld);
            scene.world = World(jsonWorld);
        }
        for (auto jsonBox : jsonScene["boxes"].array_items()) {
            scene.boxes.emplace_back(Box(Properties(jsonBox)));
        }
        for (auto jsonSphere : jsonScene["spheres"].array_items()) {
            scene.spheres.emplace_back(Sphere(Properties(jsonSphere)));
        }
        for (auto jsonMesh : jsonScene["meshes"].array_items()) {
            scene.meshes.emplace_back(Mesh(Properties(jsonMesh)));
        }
        for (auto jsonCameraKeyframe : jsonScene["cameraKeyframes"].array_items()) {
            scene.cameraKeyframes.emplace_back(Camera(Properties(jsonCameraKeyframe)));
        }
        // Set default camera
        if (!jsonCamera.is_object()) {
            Vector3f center = scene.world.bounds.center();
            scene.camera.position += center;
            scene.camera.target += center;
        }
    }

    return scene;
}
Example #2
0
 void fromJsonSub(const json11::Json& json) {
     comment = json["comment"].string_value();
     content = json["*"].string_value();
     contentformat = json["contentformat"].string_value();
     contentmodel = json["contentmodel"].string_value();
     if(json.object_items().find("minor") != json.object_items().end()) minor = 1;
     parentid = json["parentid"].int_value();
     parsedcomment = json["parsedcomment"].string_value();
     parsetree = json["parsetree"].string_value();
     revid = json["revid"].int_value();
     size = json["size"].int_value();
     sha1 = json["sha1"].string_value();
     timestamp = json["timestamp"].string_value();
     auto tagsJson = json["tags"].array_items();
     for(auto it : tagsJson) tags.push_back(it.string_value());
     user = json["user"].string_value();
     userid = json["userid"].int_value();
     if(json.object_items().find("anon") != json.object_items().end()) anon = 1;
 }
Example #3
0
  void fromJsonSub(const json11::Json& json) {
   //cout << "[[Revisions::fromJson]]..." << endl;
   batchcomplete = json["batchcomplete"].string_value();
   continue_res.clear();
   continue_2_res.clear();
   if(json.object_items().find("continue") != json.object_items().end()) {
    auto continueJson = json["continue"].object_items();
    if(continueJson.find("rvcontinue") != continueJson.end()) continue_res = continueJson["rvcontinue"].string_value();
    else if(continueJson.find("arvcontinue") != continueJson.end()) continue_res = continueJson["arvcontinue"].string_value();
    continue_2_res = continueJson["continue"].string_value();
   }
   //cout << "[[Revisions::fromJson]] continue_res: " << continue_res << endl;
   auto queryJson = json["query"].object_items();
   if(queryJson.find("normalized") != queryJson.end()) {
    auto normalizedJson = queryJson["normalized"].array_items();
    for(auto inor : normalizedJson) {
     string from = inor["from"].string_value();
     if(pagesNormalizedTitles.find(from) != pagesNormalizedTitles.end()) continue;
     string to = inor["to"].string_value();
     pagesNormalizedTitles[from] = to;
    }
   }

   map<string, json11::Json> pagesJsonObjects = queryJson["pages"].object_items();
   //cout << "[[Revisions::fromJson]] pagesJsonObjects.size(): " << pagesJsonObjects.size() << endl;
   for(auto ipro : pagesJsonObjects) {
    if(pagesById.find(stol(ipro.first)) == pagesById.end()) {
     //Page page(ipro.second);
     Page page;
     page.fromJson(ipro.second);
     pages.push_back(page);
     //cout << "[[Revisions::fromJson]] pages.size(): " << pages.size() << endl;
     //Page* pagePointer = &pages[pages.size()-1];
     //cout << "[[Revisions::fromJson]] page.pageid: " << page.pageid << endl;
     //pagesById[page.pageid] = pagePointer;
     //cout << "[[Revisions::fromJson]] page.title: " << page.title << endl;
     //pagesByTitle[page.title] = pagePointer;
     pagesById[page.pageid] = pages.size()-1;
     pagesByTitle[page.title] = pages.size()-1;
     /*
     pagesById[page.pageid] = page;
     pagesByTitle[page.title] = page;
     */
    } else {
     //cout << "[[Revisions::fromJson]] stol(ipro.first): " << stol(ipro.first) << endl;
     cout << "[[Revisions::fromJson]] pagesById[stol(ipro.first)]: " << pagesById[stol(ipro.first)] << endl;
     //pagesById[stol(ipro.first)]->fromJson(ipro.second);
     //pagesById[stol(ipro.first)].fromJson(ipro.second);
     pages[pagesById[stol(ipro.first)]].fromJson(ipro.second);
    }
   }

   vector<json11::Json> pagesJsonArray = queryJson["allrevisions"].array_items();;
   //cout << "[[Revisions::fromJson]] pagesJsonArray.size(): " << pagesJsonArray.size() << endl;
   for(auto ipra : pagesJsonArray) {
    //Page page(ipra);
    Page page;
    page.fromJson(ipra);
    //cout << "[[Revisions::fromJson]] page.pageid: " << page.pageid << endl;
    if(pagesById.find(page.pageid) == pagesById.end()) {
     pages.push_back(page);
     //cout << "[[Revisions::fromJson]] pages.size(): " << pages.size() << endl;
     //Page* pagePointer = &pages[pages.size()-1];
     //cout << "[[Revisions::fromJson]] pagePointer: " << pagePointer << endl;
     //cout << "[[Revisions::fromJson]] page.pageid (new): " << page.pageid << endl;
     //pagesById[page.pageid] = pagePointer;
     //cout << "[[Revisions::fromJson]] page.title: " << page.title << endl;
     //pagesByTitle[page.title] = pagePointer;
     pagesById[page.pageid] = pages.size()-1;
     pagesByTitle[page.title] = pages.size()-1;
     /*
     pagesById[page.pageid] = page;
     pagesByTitle[page.title] = page;
     */
    } else {
     //cout << "[[Revisions::fromJson]] page.pageid (old): " << page.pageid << endl;
     //Page* pagePointer = pagesById[page.pageid];
     //cout << "[[Revisions::fromJson]] pagesById[page.pageid]: pagePointer" << pagePointer << endl;
     //pagePointer->fromJson(ipra);
     pages[pagesById[page.pageid]].fromJson(ipra);
     //pagesById[page.pageid]->fromJson(ipra);
     //pagesById[pageRevisions.pageid].fromJson(ipra);
    }
   }

   //cout << "[[Revisions::fromJson]] pages.size(): " << pages.size() << endl;
   revisions.clear();
   for(Page prs : pages) {
    for(Revision r : prs.revisions) {
     revisions.push_back(r);
    }
   }

   //cout << "[[Revisions::fromJson]] revisions.size(): " << revisions.size() << endl;
   if(dir.compare("older") == 0) sort(revisions.begin( ), revisions.end( ), [] (const Revision& lhs, const Revision& rhs) {return lhs.revid < rhs.revid;});
   else sort(revisions.begin( ), revisions.end( ), [] (const Revision& lhs, const Revision& rhs) {return lhs.revid > rhs.revid;});   
  }