scene_import_settings.h 8.6 KB

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