scene.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. #include "scene.h"
  2. #include "project.h"
  3. #include "../core.h"
  4. #include "../fs/utils.h"
  5. using namespace wp::core;
  6. scene::scene (
  7. scenes::camera* camera,
  8. irr::video::SColorf ambientColor,
  9. bool bloom,
  10. irr::f64 bloomStrength,
  11. irr::f64 bloomThreshold,
  12. bool cameraFade,
  13. bool cameraParallax,
  14. irr::f64 cameraParallaxAmount,
  15. irr::f64 cameraParallaxDelay,
  16. irr::f64 cameraParallaxMouseInfluence,
  17. bool cameraPreview,
  18. bool cameraShake,
  19. irr::f64 cameraShakeAmplitude,
  20. irr::f64 cameraShakeRoughness,
  21. irr::f64 cameraShakeSpeed,
  22. irr::video::SColorf clearColor,
  23. scenes::projection* orthogonalProjection,
  24. irr::video::SColorf skylightColor) :
  25. m_camera (camera),
  26. m_ambientColor (ambientColor),
  27. m_bloom (bloom),
  28. m_bloomStrength (bloomStrength),
  29. m_bloomThreshold (bloomThreshold),
  30. m_cameraFade (cameraFade),
  31. m_cameraParallax (cameraParallax),
  32. m_cameraParallaxAmount (cameraParallaxAmount),
  33. m_cameraParallaxDelay (cameraParallaxDelay),
  34. m_cameraParallaxMouseInfluence (cameraParallaxMouseInfluence),
  35. m_cameraPreview (cameraPreview),
  36. m_cameraShake (cameraShake),
  37. m_cameraShakeAmplitude (cameraShakeAmplitude),
  38. m_cameraShakeRoughness (cameraShakeRoughness),
  39. m_cameraShakeSpeed (cameraShakeSpeed),
  40. m_clearColor (clearColor),
  41. m_orthogonalProjection (orthogonalProjection),
  42. m_skylightColor (skylightColor)
  43. {
  44. }
  45. scene* scene::fromFile (const irr::io::path& filename)
  46. {
  47. json content = json::parse (wp::fs::utils::loadFullFile (filename));
  48. json::const_iterator camera_it = content.find ("camera");
  49. json::const_iterator general_it = content.find ("general");
  50. json::const_iterator objects_it = content.find ("objects");
  51. if (camera_it == content.end ())
  52. {
  53. throw std::runtime_error ("Scenes must have a defined camera");
  54. }
  55. if (general_it == content.end ())
  56. {
  57. throw std::runtime_error ("Scenes must have a general section");
  58. }
  59. if (objects_it == content.end ())
  60. {
  61. throw std::runtime_error ("Scenes must have a list of objects to display");
  62. }
  63. json::const_iterator ambientcolor_it = (*general_it).find ("ambientcolor");
  64. json::const_iterator bloom_it = (*general_it).find ("bloom");
  65. json::const_iterator bloomstrength_it = (*general_it).find ("bloomstrength");
  66. json::const_iterator bloomthreshold_it = (*general_it).find ("bloomthreshold");
  67. json::const_iterator camerafade_it = (*general_it).find ("camerafade");
  68. json::const_iterator cameraparallax_it = (*general_it).find ("cameraparallax");
  69. json::const_iterator cameraparallaxamount_it = (*general_it).find ("cameraparallaxamount");
  70. json::const_iterator cameraparallaxdelay_it = (*general_it).find ("cameraparallaxdelay");
  71. json::const_iterator cameraparallaxmouseinfluence_it = (*general_it).find ("cameraparallaxmouseinfluence");
  72. json::const_iterator camerapreview_it = (*general_it).find ("camerapreview");
  73. json::const_iterator camerashake_it = (*general_it).find ("camerashake");
  74. json::const_iterator camerashakeamplitude_it = (*general_it).find ("camerashakeamplitude");
  75. json::const_iterator camerashakeroughness_it = (*general_it).find ("camerashakeroughness");
  76. json::const_iterator camerashakespeed_it = (*general_it).find ("camerashakespeed");
  77. json::const_iterator clearcolor_it = (*general_it).find ("clearcolor");
  78. json::const_iterator orthogonalprojection_it = (*general_it).find ("orthogonalprojection");
  79. json::const_iterator skylightcolor_it = (*general_it).find ("skylightcolor");
  80. if (ambientcolor_it == (*general_it).end ())
  81. {
  82. throw std::runtime_error ("General section must have ambient color");
  83. }
  84. if (bloom_it == (*general_it).end ())
  85. {
  86. throw std::runtime_error ("General section must have bloom flag");
  87. }
  88. if (bloomstrength_it == (*general_it).end ())
  89. {
  90. throw std::runtime_error ("General section must have bloom strength");
  91. }
  92. if (bloomthreshold_it == (*general_it).end ())
  93. {
  94. throw std::runtime_error ("General section must have bloom threshold");
  95. }
  96. if (camerafade_it == (*general_it).end ())
  97. {
  98. throw std::runtime_error ("General section must have camera fade");
  99. }
  100. if (cameraparallax_it == (*general_it).end ())
  101. {
  102. throw std::runtime_error ("General section must have camera parallax");
  103. }
  104. if (cameraparallaxamount_it == (*general_it).end ())
  105. {
  106. throw std::runtime_error ("General section must have camera parallax amount");
  107. }
  108. if (cameraparallaxdelay_it == (*general_it).end ())
  109. {
  110. throw std::runtime_error ("General section must have camera parallax delay");
  111. }
  112. if (cameraparallaxmouseinfluence_it == (*general_it).end ())
  113. {
  114. throw std::runtime_error ("General section must have camera parallax mouse influence");
  115. }
  116. if (camerapreview_it == (*general_it).end ())
  117. {
  118. throw std::runtime_error ("General section must have camera preview");
  119. }
  120. if (camerashake_it == (*general_it).end ())
  121. {
  122. throw std::runtime_error ("General section must have camera shake");
  123. }
  124. if (camerashakeamplitude_it == (*general_it).end ())
  125. {
  126. throw std::runtime_error ("General section must have camera shake amplitude");
  127. }
  128. if (camerashakeroughness_it == (*general_it).end ())
  129. {
  130. throw std::runtime_error ("General section must have camera shake roughness");
  131. }
  132. if (camerashakespeed_it == (*general_it).end ())
  133. {
  134. throw std::runtime_error ("General section must have camera shake speed");
  135. }
  136. if (clearcolor_it == (*general_it).end ())
  137. {
  138. throw std::runtime_error ("General section must have clear color");
  139. }
  140. if (orthogonalprojection_it == (*general_it).end ())
  141. {
  142. throw std::runtime_error ("General section must have orthogonal projection info");
  143. }
  144. if (skylightcolor_it == (*general_it).end ())
  145. {
  146. throw std::runtime_error ("General section must have skylight color");
  147. }
  148. scene* scene = new class scene (
  149. scenes::camera::fromJSON (*camera_it),
  150. wp::core::atoSColorf (*ambientcolor_it),
  151. *bloom_it,
  152. *bloomstrength_it,
  153. *bloomthreshold_it,
  154. *camerafade_it,
  155. *cameraparallax_it,
  156. *cameraparallaxamount_it,
  157. *cameraparallaxdelay_it,
  158. *cameraparallaxmouseinfluence_it,
  159. *camerapreview_it,
  160. *camerashake_it,
  161. *camerashakeamplitude_it,
  162. *camerashakeroughness_it,
  163. *camerashakespeed_it,
  164. wp::core::atoSColorf (*clearcolor_it),
  165. scenes::projection::fromJSON (*orthogonalprojection_it),
  166. wp::core::atoSColorf (*skylightcolor_it)
  167. );
  168. json::const_iterator cur = (*objects_it).begin ();
  169. json::const_iterator end = (*objects_it).end ();
  170. for (; cur != end; cur ++)
  171. {
  172. scene->insertObject (
  173. object::fromJSON (*cur)
  174. );
  175. }
  176. return scene;
  177. }
  178. void scene::insertObject (object* object)
  179. {
  180. this->m_objects.push_back (object);
  181. }
  182. project* scene::getProject ()
  183. {
  184. return this->m_project;
  185. }
  186. void scene::setProject (project* project)
  187. {
  188. this->m_project = project;
  189. }
  190. scenes::camera* scene::getCamera ()
  191. {
  192. return this->m_camera;
  193. }
  194. const irr::video::SColorf &scene::getAmbientColor() const
  195. {
  196. return this->m_ambientColor;
  197. }
  198. bool scene::isBloom () const
  199. {
  200. return this->m_bloom;
  201. }
  202. irr::f64 scene::getBloomStrength () const
  203. {
  204. return this->m_bloomStrength;
  205. }
  206. irr::f64 scene::getBloomThreshold () const
  207. {
  208. return this->m_bloomThreshold;
  209. }
  210. bool scene::isCameraFade () const
  211. {
  212. return this->m_cameraFade;
  213. }
  214. bool scene::isCameraParallax () const
  215. {
  216. return this->m_cameraParallax;
  217. }
  218. irr::f64 scene::getCameraParallaxAmount () const
  219. {
  220. return this->m_cameraParallaxAmount;
  221. }
  222. irr::f64 scene::getCameraParallaxDelay () const
  223. {
  224. return this->m_cameraParallaxDelay;
  225. }
  226. irr::f64 scene::getCameraParallaxMouseInfluence () const
  227. {
  228. return this->m_cameraParallaxMouseInfluence;
  229. }
  230. bool scene::isCameraPreview () const
  231. {
  232. return this->m_cameraPreview;
  233. }
  234. bool scene::isCameraShake () const
  235. {
  236. return this->m_cameraShake;
  237. }
  238. irr::f64 scene::getCameraShakeAmplitude () const
  239. {
  240. return this->m_cameraShakeAmplitude;
  241. }
  242. irr::f64 scene::getCameraShakeRoughness () const
  243. {
  244. return this->m_cameraShakeRoughness;
  245. }
  246. irr::f64 scene::getCameraShakeSpeed () const
  247. {
  248. return this->m_cameraShakeSpeed;
  249. }
  250. const irr::video::SColorf &scene::getClearColor () const
  251. {
  252. return this->m_clearColor;
  253. }
  254. scenes::projection *scene::getOrthogonalProjection () const
  255. {
  256. return this->m_orthogonalProjection;
  257. }
  258. const irr::video::SColorf &scene::getSkylightColor () const
  259. {
  260. return this->m_skylightColor;
  261. }