mesh_instance_3d_editor_plugin.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**************************************************************************/
  2. /* mesh_instance_3d_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_INSTANCE_3D_EDITOR_PLUGIN_H
  31. #define MESH_INSTANCE_3D_EDITOR_PLUGIN_H
  32. #include "editor/plugins/editor_plugin.h"
  33. #include "scene/3d/mesh_instance_3d.h"
  34. #include "scene/gui/option_button.h"
  35. class AcceptDialog;
  36. class AspectRatioContainer;
  37. class ConfirmationDialog;
  38. class MenuButton;
  39. class SpinBox;
  40. class MeshInstance3DEditor : public Control {
  41. GDCLASS(MeshInstance3DEditor, Control);
  42. enum Menu {
  43. MENU_OPTION_CREATE_COLLISION_SHAPE,
  44. MENU_OPTION_CREATE_NAVMESH,
  45. MENU_OPTION_CREATE_OUTLINE_MESH,
  46. MENU_OPTION_CREATE_DEBUG_TANGENTS,
  47. MENU_OPTION_CREATE_UV2,
  48. MENU_OPTION_DEBUG_UV1,
  49. MENU_OPTION_DEBUG_UV2,
  50. };
  51. enum ShapePlacement {
  52. SHAPE_PLACEMENT_SIBLING,
  53. SHAPE_PLACEMENT_STATIC_BODY_CHILD,
  54. };
  55. enum ShapeType {
  56. SHAPE_TYPE_TRIMESH,
  57. SHAPE_TYPE_SINGLE_CONVEX,
  58. SHAPE_TYPE_SIMPLIFIED_CONVEX,
  59. SHAPE_TYPE_MULTIPLE_CONVEX,
  60. };
  61. MeshInstance3D *node = nullptr;
  62. MenuButton *options = nullptr;
  63. ConfirmationDialog *outline_dialog = nullptr;
  64. SpinBox *outline_size = nullptr;
  65. ConfirmationDialog *shape_dialog = nullptr;
  66. OptionButton *shape_type = nullptr;
  67. OptionButton *shape_placement = nullptr;
  68. AcceptDialog *err_dialog = nullptr;
  69. AcceptDialog *debug_uv_dialog = nullptr;
  70. AspectRatioContainer *debug_uv_arc = nullptr;
  71. Control *debug_uv = nullptr;
  72. Vector<Vector2> uv_lines;
  73. ConfirmationDialog *navigation_mesh_dialog = nullptr;
  74. void _create_collision_shape();
  75. Vector<Ref<Shape3D>> create_shape_from_mesh(Ref<Mesh> p_mesh, int p_option, bool p_verbose);
  76. void _menu_option(int p_option);
  77. void _create_outline_mesh();
  78. void _create_navigation_mesh();
  79. void _create_uv_lines(int p_layer);
  80. friend class MeshInstance3DEditorPlugin;
  81. void _debug_uv_draw();
  82. protected:
  83. void _node_removed(Node *p_node);
  84. void _notification(int p_what);
  85. public:
  86. void edit(MeshInstance3D *p_mesh);
  87. MeshInstance3DEditor();
  88. };
  89. class MeshInstance3DEditorPlugin : public EditorPlugin {
  90. GDCLASS(MeshInstance3DEditorPlugin, EditorPlugin);
  91. MeshInstance3DEditor *mesh_editor = nullptr;
  92. public:
  93. virtual String get_plugin_name() const override { return "MeshInstance3D"; }
  94. bool has_main_screen() const override { return false; }
  95. virtual void edit(Object *p_object) override;
  96. virtual bool handles(Object *p_object) const override;
  97. virtual void make_visible(bool p_visible) override;
  98. MeshInstance3DEditorPlugin();
  99. ~MeshInstance3DEditorPlugin();
  100. };
  101. #endif // MESH_INSTANCE_3D_EDITOR_PLUGIN_H