Scene.cpp 994 B

12345678910111213141516171819202122232425262728293031
  1. #include <irrlicht/irrlicht.h>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <nlohmann/json.hpp>
  5. #include "Scene.h"
  6. using json = nlohmann::json;
  7. Scene::Scene(irr::io::path file)
  8. {
  9. std::ifstream _in (file.c_str ());
  10. this->m_content = "";
  11. this->m_content.append (std::istreambuf_iterator<char> (_in), std::istreambuf_iterator<char> ());
  12. this->m_json = json::parse (this->m_content);
  13. // check basic elements
  14. json::const_iterator camera_it = this->m_json.find ("camera");
  15. json::const_iterator general_it = this->m_json.find ("general");
  16. json::const_iterator objects_it = this->m_json.find ("objects");
  17. if (objects_it != this->m_json.end () && objects_it.value ().is_array() == true)
  18. {
  19. json::const_iterator cur = this->m_json ["objects"].begin ();
  20. json::const_iterator end = this->m_json ["objects"].end ();
  21. for (; cur != end; cur ++)
  22. {
  23. this->m_objects.push_back (new Object (*cur));
  24. }
  25. }
  26. }