scene_import_settings.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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/3d/skeleton_3d.h"
  37. #include "scene/gui/dialogs.h"
  38. #include "scene/gui/item_list.h"
  39. #include "scene/gui/menu_button.h"
  40. #include "scene/gui/option_button.h"
  41. #include "scene/gui/panel_container.h"
  42. #include "scene/gui/slider.h"
  43. #include "scene/gui/split_container.h"
  44. #include "scene/gui/subviewport_container.h"
  45. #include "scene/gui/tab_container.h"
  46. #include "scene/gui/tree.h"
  47. #include "scene/resources/primitive_meshes.h"
  48. class EditorFileDialog;
  49. class EditorInspector;
  50. class SceneImportSettingsData;
  51. class SceneImportSettings : public ConfirmationDialog {
  52. GDCLASS(SceneImportSettings, ConfirmationDialog)
  53. static SceneImportSettings *singleton;
  54. enum Actions {
  55. ACTION_EXTRACT_MATERIALS,
  56. ACTION_CHOOSE_MESH_SAVE_PATHS,
  57. ACTION_CHOOSE_ANIMATION_SAVE_PATHS,
  58. };
  59. Node *scene = nullptr;
  60. HSplitContainer *tree_split = nullptr;
  61. HSplitContainer *property_split = nullptr;
  62. TabContainer *data_mode = nullptr;
  63. Tree *scene_tree = nullptr;
  64. Tree *mesh_tree = nullptr;
  65. Tree *material_tree = nullptr;
  66. EditorInspector *inspector = nullptr;
  67. SubViewport *base_viewport = nullptr;
  68. Camera3D *camera = nullptr;
  69. Ref<CameraAttributesPractical> camera_attributes;
  70. bool first_aabb = false;
  71. AABB contents_aabb;
  72. DirectionalLight3D *light = nullptr;
  73. Ref<ArrayMesh> selection_mesh;
  74. MeshInstance3D *node_selected = nullptr;
  75. MeshInstance3D *mesh_preview = nullptr;
  76. Ref<SphereMesh> material_preview;
  77. AnimationPlayer *animation_player = nullptr;
  78. List<Skeleton3D *> skeletons;
  79. PanelContainer *animation_preview = nullptr;
  80. HSlider *animation_slider = nullptr;
  81. Button *animation_play_button = nullptr;
  82. Button *animation_stop_button = nullptr;
  83. Animation::LoopMode animation_loop_mode = Animation::LOOP_NONE;
  84. bool animation_pingpong = false;
  85. Ref<StandardMaterial3D> collider_mat;
  86. float cam_rot_x = 0.0f;
  87. float cam_rot_y = 0.0f;
  88. float cam_zoom = 0.0f;
  89. void _update_scene();
  90. struct MaterialData {
  91. bool has_import_id;
  92. Ref<Material> material;
  93. TreeItem *scene_node = nullptr;
  94. TreeItem *mesh_node = nullptr;
  95. TreeItem *material_node = nullptr;
  96. float cam_rot_x = -Math_PI / 4;
  97. float cam_rot_y = -Math_PI / 4;
  98. float cam_zoom = 1;
  99. HashMap<StringName, Variant> settings;
  100. };
  101. HashMap<String, MaterialData> material_map;
  102. HashMap<Ref<Material>, String> unnamed_material_name_map;
  103. struct MeshData {
  104. bool has_import_id;
  105. Ref<Mesh> mesh;
  106. TreeItem *scene_node = nullptr;
  107. TreeItem *mesh_node = nullptr;
  108. float cam_rot_x = -Math_PI / 4;
  109. float cam_rot_y = -Math_PI / 4;
  110. float cam_zoom = 1;
  111. HashMap<StringName, Variant> settings;
  112. };
  113. HashMap<String, MeshData> mesh_map;
  114. struct AnimationData {
  115. Ref<Animation> animation;
  116. TreeItem *scene_node = nullptr;
  117. HashMap<StringName, Variant> settings;
  118. };
  119. HashMap<String, AnimationData> animation_map;
  120. struct NodeData {
  121. Node *node = nullptr;
  122. TreeItem *scene_node = nullptr;
  123. HashMap<StringName, Variant> settings;
  124. };
  125. HashMap<String, NodeData> node_map;
  126. void _fill_material(Tree *p_tree, const Ref<Material> &p_material, TreeItem *p_parent);
  127. void _fill_mesh(Tree *p_tree, const Ref<Mesh> &p_mesh, TreeItem *p_parent);
  128. void _fill_animation(Tree *p_tree, const Ref<Animation> &p_anim, const String &p_name, TreeItem *p_parent);
  129. void _fill_scene(Node *p_node, TreeItem *p_parent_item);
  130. HashSet<Ref<Mesh>> mesh_set;
  131. String selected_type;
  132. String selected_id;
  133. bool selecting = false;
  134. void _update_view_gizmos();
  135. void _update_camera();
  136. void _select(Tree *p_from, String p_type, String p_id);
  137. void _inspector_property_edited(const String &p_name);
  138. void _reset_bone_transforms();
  139. void _play_animation();
  140. void _stop_current_animation();
  141. void _reset_animation(const String &p_animation_name = "");
  142. void _animation_slider_value_changed(double p_value);
  143. void _animation_finished(const StringName &p_name);
  144. void _material_tree_selected();
  145. void _mesh_tree_selected();
  146. void _scene_tree_selected();
  147. void _cleanup();
  148. void _viewport_input(const Ref<InputEvent> &p_input);
  149. HashMap<StringName, Variant> defaults;
  150. SceneImportSettingsData *scene_import_settings_data = nullptr;
  151. void _re_import();
  152. String base_path;
  153. MenuButton *action_menu = nullptr;
  154. ConfirmationDialog *external_paths = nullptr;
  155. Tree *external_path_tree = nullptr;
  156. EditorFileDialog *save_path = nullptr;
  157. OptionButton *external_extension_type = nullptr;
  158. EditorFileDialog *item_save_path = nullptr;
  159. void _menu_callback(int p_id);
  160. void _save_dir_callback(const String &p_path);
  161. int current_action = 0;
  162. Vector<TreeItem *> save_path_items;
  163. TreeItem *save_path_item = nullptr;
  164. void _save_path_changed(const String &p_path);
  165. void _browse_save_callback(Object *p_item, int p_column, int p_id, MouseButton p_button);
  166. void _save_dir_confirm();
  167. Dictionary base_subresource_settings;
  168. void _load_default_subresource_settings(HashMap<StringName, Variant> &settings, const String &p_type, const String &p_import_id, ResourceImporterScene::InternalImportCategory p_category);
  169. bool editing_animation = false;
  170. bool generate_collider = false;
  171. Timer *update_view_timer = nullptr;
  172. protected:
  173. void _notification(int p_what);
  174. public:
  175. bool is_editing_animation() const { return editing_animation; }
  176. void request_generate_collider();
  177. void update_view();
  178. void open_settings(const String &p_path, bool p_for_animation = false);
  179. static SceneImportSettings *get_singleton();
  180. Node *get_selected_node();
  181. SceneImportSettings();
  182. ~SceneImportSettings();
  183. };
  184. #endif // SCENE_IMPORT_SETTINGS_H