object.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include <irrlicht/irrlicht.h>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <nlohmann/json.hpp>
  5. #include <wallpaperengine/object.h>
  6. #include <wallpaperengine/core.h>
  7. #include <wallpaperengine/object3d.h>
  8. #include <wallpaperengine/image.h>
  9. namespace wp
  10. {
  11. using json = nlohmann::json;
  12. object::object (json json_data, wp::scene* scene) : m_object3d (nullptr)
  13. {
  14. this->m_scene = scene;
  15. json::const_iterator size = json_data.find ("size");
  16. json::const_iterator scale = json_data.find ("scale");
  17. json::const_iterator origin = json_data.find ("origin");
  18. if (size != json_data.end () && size.value ().is_string () == true)
  19. {
  20. std::string size_s = *size;
  21. this->m_size = core::ato2vf (size_s.c_str ());
  22. }
  23. if (scale != json_data.end () && scale.value ().is_string () == true)
  24. {
  25. std::string scale_s = *scale;
  26. this->m_scale = core::ato3vf (scale_s.c_str ());
  27. }
  28. if (origin != json_data.end () && origin.value ().is_string () == true)
  29. {
  30. std::string origin_s = *origin;
  31. this->m_origin = core::ato3vf (origin_s.c_str ());
  32. }
  33. json::const_iterator angles = json_data.find ("angles");
  34. json::const_iterator id = json_data.find ("id");
  35. json::const_iterator name = json_data.find ("name");
  36. if (angles != json_data.end () && (*angles).is_string () == true)
  37. {
  38. std::string angles_s = *angles;
  39. this->m_angles = core::ato3vf (angles_s.c_str ());
  40. }
  41. if (id != json_data.end () && (*id).is_null () == false)
  42. {
  43. this->m_id = *id;
  44. }
  45. if (name != json_data.end () && (*name).is_string () == true)
  46. {
  47. this->m_name = *name;
  48. }
  49. json::const_iterator image = json_data.find ("image");
  50. json::const_iterator model = json_data.find ("model");
  51. json::const_iterator particle = json_data.find ("particle");
  52. object3d::Type _type = object3d::Type::Type_None;
  53. if (image != json_data.end () && (*image).is_null () == false)
  54. {
  55. _type = object3d::Type::Type_Material;
  56. }
  57. if (model != json_data.end () && (*model).is_null () == false)
  58. {
  59. _type = object3d::Type::Type_Model;
  60. }
  61. if (particle != json_data.end () && (*particle).is_null () == false)
  62. {
  63. _type = object3d::Type::Type_Particle;
  64. }
  65. switch (_type)
  66. {
  67. case object3d::Type::Type_Material:
  68. this->m_object3d = new wp::image (json_data, this->m_scene);
  69. break;
  70. case object3d::Type::Type_Model:
  71. break;
  72. case object3d::Type::Type_Particle:
  73. break;
  74. }
  75. json::const_iterator effects = json_data.find ("effects");
  76. if (effects != json_data.end () && (*effects).is_array () == true)
  77. {
  78. json::const_iterator cur = (*effects).begin ();
  79. json::const_iterator end = (*effects).end ();
  80. for (; cur != end; cur ++)
  81. {
  82. this->m_effects.push_back (new effect (*cur));
  83. }
  84. }
  85. }
  86. object::~object ()
  87. {
  88. if (this->m_object3d != nullptr)
  89. {
  90. delete this->m_object3d;
  91. }
  92. }
  93. void object::render ()
  94. {
  95. if (this->m_object3d != nullptr)
  96. {
  97. this->m_object3d->render ();
  98. }
  99. }
  100. }