mesh_library_editor_plugin.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**************************************************************************/
  2. /* mesh_library_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 MESH_LIBRARY_EDITOR_PLUGIN_H
  31. #define MESH_LIBRARY_EDITOR_PLUGIN_H
  32. #include "editor/plugins/editor_plugin.h"
  33. #include "scene/resources/3d/mesh_library.h"
  34. class EditorFileDialog;
  35. class ConfirmationDialog;
  36. class MenuButton;
  37. class MeshInstance3D;
  38. class MeshLibraryEditor : public Control {
  39. GDCLASS(MeshLibraryEditor, Control);
  40. Ref<MeshLibrary> mesh_library;
  41. MenuButton *menu = nullptr;
  42. ConfirmationDialog *cd_remove = nullptr;
  43. ConfirmationDialog *cd_update = nullptr;
  44. EditorFileDialog *file = nullptr;
  45. bool apply_xforms = false;
  46. int to_erase = 0;
  47. enum {
  48. MENU_OPTION_ADD_ITEM,
  49. MENU_OPTION_REMOVE_ITEM,
  50. MENU_OPTION_UPDATE_FROM_SCENE,
  51. MENU_OPTION_IMPORT_FROM_SCENE,
  52. MENU_OPTION_IMPORT_FROM_SCENE_APPLY_XFORMS
  53. };
  54. int option = 0;
  55. void _import_scene_cbk(const String &p_str);
  56. void _menu_cbk(int p_option);
  57. void _menu_remove_confirm();
  58. void _menu_update_confirm(bool p_apply_xforms);
  59. static void _import_scene(Node *p_scene, Ref<MeshLibrary> p_library, bool p_merge, bool p_apply_xforms);
  60. static void _import_scene_parse_node(Ref<MeshLibrary> p_library, HashMap<int, MeshInstance3D *> &p_mesh_instances, Node *p_node, bool p_merge, bool p_apply_xforms);
  61. public:
  62. MenuButton *get_menu_button() const { return menu; }
  63. void edit(const Ref<MeshLibrary> &p_mesh_library);
  64. static Error update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml, bool p_merge = true, bool p_apply_xforms = false);
  65. MeshLibraryEditor();
  66. };
  67. class MeshLibraryEditorPlugin : public EditorPlugin {
  68. GDCLASS(MeshLibraryEditorPlugin, EditorPlugin);
  69. MeshLibraryEditor *mesh_library_editor = nullptr;
  70. public:
  71. virtual String get_name() const override { return "MeshLibrary"; }
  72. bool has_main_screen() const override { return false; }
  73. virtual void edit(Object *p_node) override;
  74. virtual bool handles(Object *p_node) const override;
  75. virtual void make_visible(bool p_visible) override;
  76. MeshLibraryEditorPlugin();
  77. };
  78. #endif // MESH_LIBRARY_EDITOR_PLUGIN_H