merge_group_editor_plugin.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**************************************************************************/
  2. /* merge_group_editor_plugin.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 MERGE_GROUP_EDITOR_PLUGIN_H
  31. #define MERGE_GROUP_EDITOR_PLUGIN_H
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_plugin.h"
  34. #include "scene/3d/merge_group.h"
  35. #include "scene/resources/material.h"
  36. class MergeGroupEditorPlugin;
  37. class MergeGroupEditorBakeDialog : public ConfirmationDialog {
  38. GDCLASS(MergeGroupEditorBakeDialog, ConfirmationDialog);
  39. MergeGroupEditorPlugin *_owner_plugin = nullptr;
  40. CheckBox *_single_scene = nullptr;
  41. SpinBox *_subscene_polycount_threshold = nullptr;
  42. CheckBox *_shadow_proxy = nullptr;
  43. CheckBox *_convert_csgs = nullptr;
  44. CheckBox *_convert_gridmaps = nullptr;
  45. CheckBox *_combine_surfaces = nullptr;
  46. CheckBox *_clean_meshes = nullptr;
  47. SpinBox *_group_size = nullptr;
  48. SpinBox *_splits_horz = nullptr;
  49. SpinBox *_splits_vert = nullptr;
  50. SpinBox *_min_split_poly_count = nullptr;
  51. void _bake_confirm();
  52. void _add_bake_checkbox(Node *p_parent, CheckBox **pp_checkbox, const String &p_text, const String &p_tooltip, bool p_default = false);
  53. void _add_bake_spinbox(VBoxContainer *p_parent, SpinBox **pp_spinbox, const String &p_text, const String &p_tooltip, int32_t p_min, int32_t p_max, int32_t p_step, int32_t p_default);
  54. protected:
  55. static void _bind_methods();
  56. public:
  57. void fill_merge_group_params(MergeGroup &r_merge_group);
  58. MergeGroupEditorBakeDialog(MergeGroupEditorPlugin *p_owner);
  59. };
  60. class MergeGroupEditorPlugin : public EditorPlugin {
  61. GDCLASS(MergeGroupEditorPlugin, EditorPlugin);
  62. MergeGroup *_merge_group;
  63. ToolButton *button_bake;
  64. EditorFileDialog *file_dialog;
  65. EditorNode *editor;
  66. MergeGroupEditorBakeDialog *bake_dialog;
  67. struct Params {
  68. bool single_scene = false;
  69. int subscene_polycount_threshold = 1024;
  70. } _params;
  71. static EditorProgress *tmp_progress;
  72. static EditorProgress *tmp_subprogress;
  73. static bool bake_func_step(float p_progress, const String &p_description, void *, bool p_force_refresh);
  74. static bool bake_func_substep(float p_progress, const String &p_description, void *, bool p_force_refresh);
  75. static void bake_func_end(uint32_t p_time_started);
  76. void _bake();
  77. void _bake_select_file(const String &p_file);
  78. void _duplicate_branch(Node *p_branch, Node *p_new_parent);
  79. bool _save_scene(Node *p_branch, String p_filename);
  80. void _remove_queue_deleted_nodes_recursive(Node *p_node);
  81. void _push_mesh_data_to_gpu_recursive(Node *p_node);
  82. Spatial *_convert_merge_group_to_spatial(MergeGroup *p_merge_group);
  83. bool _find_visual_instances_recursive(Node *p_node);
  84. void _save_mesh_subscenes_recursive(Node *p_root, Node *p_node, String p_base_filename, int &r_subscene_count);
  85. bool _save_subscene(Node *p_root, Node *p_branch, String p_base_filename, int &r_subscene_count);
  86. bool _replace_with_branch_scene(const String &p_file, Node *p_base);
  87. uint32_t _get_mesh_poly_count(const MeshInstance &p_mi) const;
  88. protected:
  89. static void _bind_methods();
  90. public:
  91. virtual String get_name() const { return "MergeGroup"; }
  92. bool has_main_screen() const { return false; }
  93. virtual void edit(Object *p_object);
  94. virtual bool handles(Object *p_object) const;
  95. virtual void make_visible(bool p_visible);
  96. void dialog_pressed_bake(bool p_single_scene, int p_subscene_polycount_threshold);
  97. MergeGroupEditorPlugin(EditorNode *p_node);
  98. ~MergeGroupEditorPlugin();
  99. };
  100. #endif // MERGE_GROUP_EDITOR_PLUGIN_H