EditorUi.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Ui.h>
  7. #include <AnKi/Editor/ImageViewerUi.h>
  8. #include <AnKi/Editor/ParticleEditorUi.h>
  9. #include <AnKi/Util/Function.h>
  10. #include <filesystem>
  11. namespace anki {
  12. // Forward
  13. class SceneNode;
  14. #define ANKI_DEFINE_SCENE_COMPONENT(class_, weight, sceneNodeCanHaveMany, icon, serializable) class class_##Component;
  15. #include <AnKi/Scene/Components/SceneComponentClasses.def.h>
  16. // A class that builds the editor UI and manipulates the scene directly.
  17. class EditorUi
  18. {
  19. public:
  20. Bool m_quit = false;
  21. Bool m_mouseOverAnyWindow = false; // Mouse is over one of the editor windows.
  22. EditorUi();
  23. ~EditorUi();
  24. void draw(UiCanvas& canvas);
  25. private:
  26. static constexpr F32 kMargin = 4.0f;
  27. static constexpr F32 kConsoleHeight = 400.0f;
  28. static constexpr U32 kMaxTextInputLen = 256;
  29. enum class AssetFileType : U32
  30. {
  31. kNone,
  32. kTexture,
  33. kMaterial,
  34. kMesh,
  35. kLua,
  36. kParticleEmitter
  37. };
  38. class AssetFile
  39. {
  40. public:
  41. String m_basename;
  42. String m_filename;
  43. AssetFileType m_type = AssetFileType::kNone;
  44. };
  45. class AssetPath
  46. {
  47. public:
  48. String m_dirname;
  49. DynamicArray<AssetPath> m_children;
  50. DynamicArray<AssetFile> m_files;
  51. U32 m_id = 0;
  52. };
  53. class ImageCacheEntry
  54. {
  55. public:
  56. ImageResourcePtr m_image;
  57. U32 m_lastSeenInFrame = 0;
  58. };
  59. UiCanvas* m_canvas = nullptr;
  60. ImFont* m_font = nullptr;
  61. ImFont* m_monospaceFont = nullptr;
  62. F32 m_fontSize = 22.0f;
  63. Bool m_showCVarEditorWindow = false;
  64. Bool m_showConsoleWindow = true;
  65. Bool m_showSceneNodePropsWindow = true;
  66. Bool m_showSceneHierarcyWindow = true;
  67. Bool m_showAssetsWindow = true;
  68. Bool m_showDebugRtsWindow = false;
  69. ImageResourcePtr m_materialIcon;
  70. ImageResourcePtr m_meshIcon;
  71. ImageViewerUi m_imageViewer;
  72. ParticleEditorUi m_particlesEditor;
  73. ImGuiTextFilter m_tempFilter;
  74. class
  75. {
  76. public:
  77. U32 m_translationAxisSelected = kMaxU32;
  78. U32 m_scaleAxisSelected = kMaxU32;
  79. U32 m_rotationAxisSelected = kMaxU32;
  80. Vec3 m_pivotPoint;
  81. } m_objectPicking;
  82. class
  83. {
  84. public:
  85. ImGuiTextFilter m_filter;
  86. SceneNode* m_selectedNode = nullptr;
  87. } m_sceneHierarchyWindow;
  88. class
  89. {
  90. public:
  91. ImGuiTextFilter m_filter;
  92. } m_cvarsEditorWindow;
  93. class
  94. {
  95. public:
  96. List<std::pair<LoggerMessageType, String>> m_log;
  97. Bool m_forceLogScrollDown = true;
  98. SpinLock m_logMtx;
  99. ImGuiTextFilter m_logFilter;
  100. } m_consoleWindow;
  101. class
  102. {
  103. public:
  104. I32 m_selectedSceneComponentType = 0;
  105. Bool m_uniformScale = false;
  106. U32 m_scriptComponentThatHasTheTextEditorOpen = 0;
  107. Bool m_textEditorOpen = false;
  108. String m_textEditorTxt;
  109. U32 m_currentSceneNodeUuid = 0;
  110. } m_sceneNodePropsWindow;
  111. class
  112. {
  113. public:
  114. const AssetPath* m_pathSelected = nullptr;
  115. DynamicArray<AssetPath> m_assetPaths;
  116. DynamicArray<ImageCacheEntry> m_imageCache;
  117. ImGuiTextFilter m_fileFilter;
  118. I32 m_cellSize = 8; // Icon size
  119. } m_assetsWindow;
  120. class
  121. {
  122. public:
  123. Bool m_disableTonemapping = false;
  124. } m_debugRtsWindow;
  125. class
  126. {
  127. public:
  128. F32 m_scaleTranslationSnapping = 0.1f;
  129. F32 m_rotationSnappingDeg = 1.0f;
  130. } m_toolbox;
  131. void mainMenu();
  132. // Windows
  133. void sceneHierarchyWindow();
  134. void sceneNodePropertiesWindow();
  135. void cVarsWindow();
  136. void consoleWindow();
  137. void assetsWindow();
  138. void debugRtsWindow();
  139. void sceneNode(SceneNode& node);
  140. void scriptComponent(ScriptComponent& comp);
  141. void materialComponent(MaterialComponent& comp);
  142. void meshComponent(MeshComponent& comp);
  143. void skinComponent(SkinComponent& comp);
  144. void particleEmitterComponent(ParticleEmitter2Component& comp);
  145. void lightComponent(LightComponent& comp);
  146. void jointComponent(JointComponent& comp);
  147. void bodyComponent(BodyComponent& comp);
  148. void decalComponent(DecalComponent& comp);
  149. void dirTree(const AssetPath& path);
  150. // Widget/UI utils
  151. static void filter(ImGuiTextFilter& filter);
  152. Bool textEditorWindow(CString extraWindowTitle, Bool* pOpen, String& inout) const;
  153. static void dummyButton(I32 id);
  154. template<typename TItemArray>
  155. static void comboWithFilter(CString text, const TItemArray& items, CString selectedItemIn, U32& selectedItemOut, ImGuiTextFilter& filter);
  156. // Misc
  157. static void loggerMessageHandler(void* ud, const LoggerMessageInfo& info);
  158. static void listDir(const std::filesystem::path& rootPath, const std::filesystem::path& parentPath, AssetPath& parent, U32& id);
  159. static void gatherAssets(DynamicArray<AssetPath>& paths);
  160. void loadImageToCache(CString fname, ImageResourcePtr& img);
  161. void objectPicking();
  162. static DynamicArray<CString> gatherResourceFilenames(CString filenameContains);
  163. };
  164. } // end namespace anki