material.cpp 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "material.h"
  2. #include <irrlicht/irrlicht.h>
  3. #include <nlohmann/json.hpp>
  4. #include "../../../fs/utils.h"
  5. using namespace wp::core::objects::images;
  6. material::material ()
  7. {
  8. }
  9. material* material::fromFile (irr::io::path filename)
  10. {
  11. json content = json::parse (wp::fs::utils::loadFullFile (filename));
  12. json::const_iterator passes_it = content.find ("passes");
  13. if (passes_it == content.end ())
  14. {
  15. throw std::runtime_error ("Material must have at least one pass");
  16. }
  17. material* material = new class material ();
  18. json::const_iterator cur = (*passes_it).begin ();
  19. json::const_iterator end = (*passes_it).end ();
  20. for (; cur != end; cur ++)
  21. {
  22. material->insertPass (
  23. materials::passes::fromJSON (*cur)
  24. );
  25. }
  26. return material;
  27. }
  28. void material::insertPass (materials::passes* mass)
  29. {
  30. this->m_passes.push_back (mass);
  31. }
  32. std::vector <materials::passes*>* material::getPasses ()
  33. {
  34. return &this->m_passes;
  35. }