navigation_obstacle_3d_editor_plugin.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**************************************************************************/
  2. /* navigation_obstacle_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 NAVIGATION_OBSTACLE_3D_EDITOR_PLUGIN_H
  31. #define NAVIGATION_OBSTACLE_3D_EDITOR_PLUGIN_H
  32. #include "editor/plugins/editor_plugin.h"
  33. #include "editor/plugins/node_3d_editor_gizmos.h"
  34. #include "scene/gui/box_container.h"
  35. class Button;
  36. class ConfirmationDialog;
  37. class NavigationObstacle3D;
  38. class NavigationObstacle3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  39. GDCLASS(NavigationObstacle3DGizmoPlugin, EditorNode3DGizmoPlugin);
  40. public:
  41. virtual bool has_gizmo(Node3D *p_spatial) override;
  42. virtual String get_gizmo_name() const override;
  43. virtual void redraw(EditorNode3DGizmo *p_gizmo) override;
  44. bool can_be_hidden() const override;
  45. int get_priority() const override;
  46. virtual int subgizmos_intersect_ray(const EditorNode3DGizmo *p_gizmo, Camera3D *p_camera, const Vector2 &p_point) const override;
  47. virtual Vector<int> subgizmos_intersect_frustum(const EditorNode3DGizmo *p_gizmo, const Camera3D *p_camera, const Vector<Plane> &p_frustum) const override;
  48. virtual Transform3D get_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id) const override;
  49. virtual void set_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id, Transform3D p_transform) override;
  50. virtual void commit_subgizmos(const EditorNode3DGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel = false) override;
  51. NavigationObstacle3DGizmoPlugin();
  52. };
  53. class NavigationObstacle3DEditorPlugin : public EditorPlugin {
  54. GDCLASS(NavigationObstacle3DEditorPlugin, EditorPlugin);
  55. Ref<NavigationObstacle3DGizmoPlugin> obstacle_3d_gizmo_plugin;
  56. NavigationObstacle3D *obstacle_node = nullptr;
  57. Ref<StandardMaterial3D> line_material;
  58. Ref<StandardMaterial3D> handle_material;
  59. RID point_lines_mesh_rid;
  60. RID point_lines_instance_rid;
  61. RID point_handle_mesh_rid;
  62. RID point_handles_instance_rid;
  63. public:
  64. enum Mode {
  65. MODE_CREATE = 0,
  66. MODE_EDIT,
  67. MODE_DELETE,
  68. ACTION_FLIP,
  69. ACTION_CLEAR,
  70. };
  71. private:
  72. int mode = MODE_EDIT;
  73. int edited_point = 0;
  74. Vector3 edited_point_pos;
  75. Vector<Vector3> pre_move_edit;
  76. Vector<Vector3> wip_vertices;
  77. bool wip_active = false;
  78. bool snap_ignore = false;
  79. void _wip_close();
  80. void _wip_cancel();
  81. void _update_theme();
  82. Button *button_create = nullptr;
  83. Button *button_edit = nullptr;
  84. Button *button_delete = nullptr;
  85. Button *button_flip = nullptr;
  86. Button *button_clear = nullptr;
  87. ConfirmationDialog *button_clear_dialog = nullptr;
  88. protected:
  89. void _notification(int p_what);
  90. void _node_removed(Node *p_node);
  91. public:
  92. HBoxContainer *obstacle_editor = nullptr;
  93. static NavigationObstacle3DEditorPlugin *singleton;
  94. void redraw();
  95. void set_mode(int p_mode);
  96. int get_mode() { return mode; }
  97. void action_flip_vertices();
  98. void action_clear_vertices();
  99. virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override;
  100. virtual String get_name() const override { return "NavigationObstacle3D"; }
  101. bool has_main_screen() const override { return false; }
  102. virtual void edit(Object *p_object) override;
  103. virtual bool handles(Object *p_object) const override;
  104. virtual void make_visible(bool p_visible) override;
  105. NavigationObstacle3DEditorPlugin();
  106. ~NavigationObstacle3DEditorPlugin();
  107. };
  108. #endif // NAVIGATION_OBSTACLE_3D_EDITOR_PLUGIN_H