scene_import_settings.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /**************************************************************************/
  2. /* scene_import_settings.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef SCENE_IMPORT_SETTINGS_H
  31. #define SCENE_IMPORT_SETTINGS_H
  32. #include "editor/import/resource_importer_scene.h"
  33. #include "scene/3d/camera_3d.h"
  34. #include "scene/3d/light_3d.h"
  35. #include "scene/3d/mesh_instance_3d.h"
  36. #include "scene/gui/dialogs.h"
  37. #include "scene/gui/item_list.h"
  38. #include "scene/gui/menu_button.h"
  39. #include "scene/gui/option_button.h"
  40. #include "scene/gui/split_container.h"
  41. #include "scene/gui/subviewport_container.h"
  42. #include "scene/gui/tab_container.h"
  43. #include "scene/gui/tree.h"
  44. #include "scene/resources/primitive_meshes.h"
  45. class EditorFileDialog;
  46. class EditorInspector;
  47. class SceneImportSettingsData;
  48. class SceneImportSettings : public ConfirmationDialog {
  49. GDCLASS(SceneImportSettings, ConfirmationDialog)
  50. static SceneImportSettings *singleton;
  51. enum Actions {
  52. ACTION_EXTRACT_MATERIALS,
  53. ACTION_CHOOSE_MESH_SAVE_PATHS,
  54. ACTION_CHOOSE_ANIMATION_SAVE_PATHS,
  55. };
  56. Node *scene = nullptr;
  57. HSplitContainer *tree_split = nullptr;
  58. HSplitContainer *property_split = nullptr;
  59. TabContainer *data_mode = nullptr;
  60. Tree *scene_tree = nullptr;
  61. Tree *mesh_tree = nullptr;
  62. Tree *material_tree = nullptr;
  63. EditorInspector *inspector = nullptr;
  64. SubViewport *base_viewport = nullptr;
  65. Camera3D *camera = nullptr;
  66. Ref<CameraAttributesPractical> camera_attributes;
  67. bool first_aabb = false;
  68. AABB contents_aabb;
  69. DirectionalLight3D *light = nullptr;
  70. Ref<ArrayMesh> selection_mesh;
  71. MeshInstance3D *node_selected = nullptr;
  72. MeshInstance3D *mesh_preview = nullptr;
  73. Ref<SphereMesh> material_preview;
  74. Ref<StandardMaterial3D> collider_mat;
  75. float cam_rot_x = 0.0f;
  76. float cam_rot_y = 0.0f;
  77. float cam_zoom = 0.0f;
  78. void _update_scene();
  79. struct MaterialData {
  80. bool has_import_id;
  81. Ref<Material> material;
  82. TreeItem *scene_node = nullptr;
  83. TreeItem *mesh_node = nullptr;
  84. TreeItem *material_node = nullptr;
  85. float cam_rot_x = -Math_PI / 4;
  86. float cam_rot_y = -Math_PI / 4;
  87. float cam_zoom = 1;
  88. HashMap<StringName, Variant> settings;
  89. };
  90. HashMap<String, MaterialData> material_map;
  91. HashMap<Ref<Material>, String> unnamed_material_name_map;
  92. struct MeshData {
  93. bool has_import_id;
  94. Ref<Mesh> mesh;
  95. TreeItem *scene_node = nullptr;
  96. TreeItem *mesh_node = nullptr;
  97. float cam_rot_x = -Math_PI / 4;
  98. float cam_rot_y = -Math_PI / 4;
  99. float cam_zoom = 1;
  100. HashMap<StringName, Variant> settings;
  101. };
  102. HashMap<String, MeshData> mesh_map;
  103. struct AnimationData {
  104. Ref<Animation> animation;
  105. TreeItem *scene_node = nullptr;
  106. HashMap<StringName, Variant> settings;
  107. };
  108. HashMap<String, AnimationData> animation_map;
  109. struct NodeData {
  110. Node *node = nullptr;
  111. TreeItem *scene_node = nullptr;
  112. HashMap<StringName, Variant> settings;
  113. };
  114. HashMap<String, NodeData> node_map;
  115. void _fill_material(Tree *p_tree, const Ref<Material> &p_material, TreeItem *p_parent);
  116. void _fill_mesh(Tree *p_tree, const Ref<Mesh> &p_mesh, TreeItem *p_parent);
  117. void _fill_animation(Tree *p_tree, const Ref<Animation> &p_anim, const String &p_name, TreeItem *p_parent);
  118. void _fill_scene(Node *p_node, TreeItem *p_parent_item);
  119. HashSet<Ref<Mesh>> mesh_set;
  120. String selected_type;
  121. String selected_id;
  122. bool selecting = false;
  123. void _update_view_gizmos();
  124. void _update_camera();
  125. void _select(Tree *p_from, String p_type, String p_id);
  126. void _material_tree_selected();
  127. void _mesh_tree_selected();
  128. void _scene_tree_selected();
  129. void _viewport_input(const Ref<InputEvent> &p_input);
  130. HashMap<StringName, Variant> defaults;
  131. SceneImportSettingsData *scene_import_settings_data = nullptr;
  132. void _re_import();
  133. String base_path;
  134. MenuButton *action_menu = nullptr;
  135. ConfirmationDialog *external_paths = nullptr;
  136. Tree *external_path_tree = nullptr;
  137. EditorFileDialog *save_path = nullptr;
  138. OptionButton *external_extension_type = nullptr;
  139. EditorFileDialog *item_save_path = nullptr;
  140. void _menu_callback(int p_id);
  141. void _save_dir_callback(const String &p_path);
  142. int current_action = 0;
  143. Vector<TreeItem *> save_path_items;
  144. TreeItem *save_path_item = nullptr;
  145. void _save_path_changed(const String &p_path);
  146. void _browse_save_callback(Object *p_item, int p_column, int p_id, MouseButton p_button);
  147. void _save_dir_confirm();
  148. Dictionary base_subresource_settings;
  149. void _load_default_subresource_settings(HashMap<StringName, Variant> &settings, const String &p_type, const String &p_import_id, ResourceImporterScene::InternalImportCategory p_category);
  150. bool editing_animation = false;
  151. bool generate_collider = false;
  152. Timer *update_view_timer = nullptr;
  153. protected:
  154. void _notification(int p_what);
  155. public:
  156. bool is_editing_animation() const { return editing_animation; }
  157. void request_generate_collider();
  158. void update_view();
  159. void open_settings(const String &p_path, bool p_for_animation = false);
  160. static SceneImportSettings *get_singleton();
  161. Node *get_selected_node();
  162. SceneImportSettings();
  163. ~SceneImportSettings();
  164. };
  165. #endif // SCENE_IMPORT_SETTINGS_H