Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

meshviewer.h 7.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. //
  2. // Lol Engine — EasyMesh tutorial
  3. //
  4. // Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
  5. // © 2012—2018 Sam Hocevar <sam@hocevar.net>
  6. //
  7. // Lol Engine is free software. It comes without any warranty, to
  8. // the extent permitted by applicable law. You can redistribute it
  9. // and/or modify it under the terms of the Do What the Fuck You Want
  10. // to Public License, Version 2, as published by the WTFPL Task Force.
  11. // See http://www.wtfpl.net/ for more details.
  12. //
  13. #pragma once
  14. #include <string>
  15. #include <map>
  16. namespace lol
  17. {
  18. enum
  19. {
  20. IPT_MV_KBOARD = 0,
  21. IPT_MV_MOUSE,
  22. INPUT_MAX
  23. };
  24. enum MVKeyboardList
  25. {
  26. KEY_CAM_RESET = 0,
  27. KEY_CAM_POS,
  28. KEY_CAM_FOV,
  29. KEY_CAM_UP,
  30. KEY_CAM_DOWN,
  31. KEY_CAM_LEFT,
  32. KEY_CAM_RIGHT,
  33. KEY_MESH_NEXT,
  34. KEY_MESH_PREV,
  35. KEY_F1,
  36. KEY_F2,
  37. KEY_F3,
  38. KEY_F4,
  39. KEY_F5,
  40. KEY_ESC,
  41. KEY_MAX
  42. };
  43. enum MVMouseKeyList
  44. {
  45. MSE_CAM_ROT = KEY_MAX,
  46. MSE_CAM_POS,
  47. MSE_CAM_FOV,
  48. MSE_FOCUS,
  49. MSE_MAX
  50. };
  51. enum MVMouseAxisList
  52. {
  53. MSEX_CAM_Y = 0,
  54. MSEX_CAM_X,
  55. MSEX_MAX
  56. };
  57. #define MAX_KEYS MSE_MAX
  58. #define MAX_AXIS MSEX_MAX
  59. //MeshViewerInput ---------------------------------------------------------
  60. struct MeshViewerKeyInputBase : public StructSafeEnum
  61. {
  62. enum Type
  63. {
  64. KBD_BEG = 0,
  65. Exit = KBD_BEG,
  66. KBD_END,
  67. MSE_BEG = KBD_END,
  68. LeftClick = MSE_BEG,
  69. RightClick,
  70. MiddleClick,
  71. Focus,
  72. MSE_END,
  73. MAX = MSE_END,
  74. };
  75. protected:
  76. virtual bool BuildEnumMap(std::map<int64_t, std::string>& enum_map)
  77. {
  78. enum_map[Exit] = g_name_key_Escape;
  79. enum_map[LeftClick] = g_name_mouse_key_left;
  80. enum_map[RightClick] = g_name_mouse_key_right;
  81. enum_map[MiddleClick] = g_name_mouse_key_middle;
  82. enum_map[Focus] = g_name_mouse_key_in_screen;
  83. return true;
  84. }
  85. };
  86. typedef SafeEnum<MeshViewerKeyInputBase> MeshViewerKeyInput;
  87. #define ALL_FEATURES 1
  88. #define NO_SC_SETUP 0
  89. enum GizmoType
  90. {
  91. GZ_Editor = 0,
  92. GZ_LightPos,
  93. GZ_LightDir,
  94. GZ_MAX
  95. };
  96. struct LightData
  97. {
  98. LightData(vec3 pos, vec4 col)
  99. {
  100. m_pos = pos;
  101. m_col = col;
  102. }
  103. vec3 m_pos;
  104. vec4 m_col;
  105. };
  106. //ViewerObject ----------------------------------------------------------------
  107. class ViewerObject
  108. {
  109. public:
  110. ViewerObject() { }
  111. ViewerObject(std::string const& name) : m_name(name) { }
  112. virtual ~ViewerObject() { }
  113. virtual void tick_draw(float seconds, Scene &scene) { }
  114. std::string GetName() { return m_name; }
  115. protected:
  116. std::string m_name;
  117. };
  118. //EasyMeshViewerObject --------------------------------------------------------
  119. class EasyMeshViewerObject : public ViewerObject
  120. {
  121. typedef ViewerObject super;
  122. public:
  123. EasyMeshViewerObject()
  124. : ViewerObject() { }
  125. EasyMeshViewerObject(std::string const& name, EasyMesh const& mesh)
  126. : ViewerObject(name)
  127. {
  128. Init(name, mesh);
  129. }
  130. virtual ~EasyMeshViewerObject() { }
  131. virtual void tick_draw(float seconds, Scene &scene);
  132. void Init(std::string const& name, EasyMesh const& mesh)
  133. {
  134. m_name = name;
  135. m_mesh = mesh;
  136. }
  137. protected:
  138. EasyMesh m_mesh;
  139. };
  140. //MeshViewerLoadJob -----------------------------------------------------------
  141. class MeshViewerLoadJob : public ThreadJob
  142. {
  143. friend class BaseThreadManager;
  144. typedef ThreadJob super;
  145. public:
  146. inline MeshViewerLoadJob() : ThreadJob() { }
  147. inline MeshViewerLoadJob(std::string const& path)
  148. : ThreadJob(ThreadJobType::WORK_TODO), m_path(path) { }
  149. virtual ~MeshViewerLoadJob() { }
  150. virtual void RetrieveResult(class MeshViewer* app) { }
  151. protected:
  152. virtual bool DoWork() { return super::DoWork(); }
  153. protected:
  154. std::string m_path;
  155. };
  156. //EasyMeshLoadJob -------------------------------------------------------------
  157. class EasyMeshLoadJob : public MeshViewerLoadJob
  158. {
  159. friend class BaseThreadManager;
  160. typedef EasyMeshLoadJob super;
  161. public:
  162. inline EasyMeshLoadJob() : MeshViewerLoadJob() { }
  163. inline EasyMeshLoadJob(std::string const& path)
  164. : MeshViewerLoadJob(path) { }
  165. virtual ~EasyMeshLoadJob() { }
  166. static MeshViewerLoadJob* GetInstance(std::string const& path);
  167. virtual void RetrieveResult(class MeshViewer* app);
  168. protected:
  169. static bool Check(std::string const& path) { return path.find(".easymesh") != std::string::npos; }
  170. virtual bool DoWork();
  171. protected:
  172. EasyMeshLuaLoader m_loader;
  173. array<EasyMeshViewerObject*> m_meshes;
  174. };
  175. //MeshViewer ------------------------------------------------------------------
  176. class MeshViewer : public WorldEntity
  177. {
  178. typedef WorldEntity super;
  179. public:
  180. MeshViewer(char const *file_name = "../data/meshviewer.easymesh.lua");
  181. ~MeshViewer();
  182. void Start();
  183. void Stop();
  184. void UpdateSceneSetup(bool only_destroy = false);
  185. MeshViewerLoadJob* GetLoadJob(std::string const& path);
  186. void AddViewerObj(ViewerObject* obj) { m_objs << obj; }
  187. virtual void tick_game(float seconds);
  188. virtual void tick_draw(float seconds, Scene &scene);
  189. bool KeyReleased(MVKeyboardList index);
  190. bool KeyPressed(MVKeyboardList index);
  191. bool KeyDown(MVKeyboardList index);
  192. bool KeyReleased(MVMouseKeyList index);
  193. bool KeyPressed(MVMouseKeyList index);
  194. bool KeyDown(MVMouseKeyList index);
  195. float AxisValue(MVMouseAxisList index);
  196. void Prepare();
  197. void Unprepare();
  198. void Update(float seconds);
  199. void Draw(float seconds, Scene &scene);
  200. private:
  201. //Main stuff --------------------------------------------------------------
  202. bool m_init = false;
  203. bool m_first_tick = false;
  204. InputProfile m_profile;
  205. Camera* m_camera = nullptr;
  206. Text* m_text = nullptr;
  207. //ImGui stuff
  208. bool m_menu_cam_useage = true;
  209. float m_menu_cam_fov = radians(40.f);
  210. vec3 m_menu_cam_pos = vec3(20.f, 45.f, 45.f);
  211. int m_menu_mesh_idx = 0;
  212. array<char const *> m_menu_mesh_names_char;
  213. array<std::string> m_menu_mesh_names_str;
  214. //Scene setup data
  215. SceneSetupLuaLoader m_ssetup_loader;
  216. FileUpdateStatus *m_ssetup_file_status = nullptr;
  217. std::string m_ssetup_file_name;
  218. std::string m_ssetup_name;
  219. std::map<std::string, SceneSetup*> m_ssetups;
  220. //File data
  221. std::string m_file_name;
  222. FileUpdateStatus* m_file_status;
  223. //Object data
  224. array<ViewerObject*> m_objs;
  225. //Entities listing
  226. array<Entity*> m_entities;
  227. //Input
  228. Controller* m_controller = nullptr;
  229. //Thread stuff
  230. FileUpdateTester* m_file_check = nullptr;
  231. DefaultThreadManager* m_file_loader = nullptr;
  232. //OLD ---------------------------------------------------------------------
  233. SceneSetup *m_ssetup = nullptr;
  234. array<LightData> m_light_datas;
  235. short m_input_usage;
  236. mat4 m_mat;
  237. mat4 m_mat_prev;
  238. //Camera Setup
  239. float m_reset_timer;
  240. float m_fov;
  241. float m_fov_mesh;
  242. float m_fov_speed;
  243. float m_zoom;
  244. float m_zoom_mesh;
  245. float m_zoom_speed;
  246. vec2 m_rot;
  247. vec2 m_rot_mesh;
  248. vec2 m_rot_speed;
  249. vec2 m_pos;
  250. vec2 m_pos_mesh;
  251. vec2 m_pos_speed;
  252. vec2 m_hist_scale;
  253. vec2 m_hist_scale_mesh;
  254. vec2 m_hist_scale_speed;
  255. vec2 m_screen_offset;
  256. //Mesh update timer
  257. float m_build_timer;
  258. float m_build_time;
  259. //Mesh infos
  260. vec2 m_render_max;
  261. int m_mesh_render;
  262. int m_mesh_id;
  263. float m_mesh_id1;
  264. array<EasyMesh*, EasyMesh*> m_meshes;
  265. array<EasyMesh*> m_gizmos;
  266. //File data
  267. array<std::string> m_cmdlist;
  268. float m_stream_update_time;
  269. float m_stream_update_timer;
  270. //misc datas
  271. Shader * m_texture_shader;
  272. TileSet * m_default_texture;
  273. Texture * m_texture;
  274. ShaderUniform m_texture_uni;
  275. };
  276. } /* namespace lol */