1/**************************************************************************/
2/* path_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
31#ifndef PATH_3D_EDITOR_PLUGIN_H
32#define PATH_3D_EDITOR_PLUGIN_H
33
34#include "editor/editor_plugin.h"
35#include "editor/plugins/node_3d_editor_gizmos.h"
36#include "scene/3d/camera_3d.h"
37#include "scene/3d/path_3d.h"
38
39class HBoxContainer;
40class MenuButton;
41
42class Path3DGizmo : public EditorNode3DGizmo {
43 GDCLASS(Path3DGizmo, EditorNode3DGizmo);
44
45 // Map handle id to control point id and handle type.
46 enum HandleType {
47 HANDLE_TYPE_IN,
48 HANDLE_TYPE_OUT,
49 HANDLE_TYPE_TILT,
50 };
51
52 struct HandleInfo {
53 int point_idx; // Index of control point.
54 HandleType type; // Type of this handle.
55 };
56
57 Path3D *path = nullptr;
58 mutable Vector3 original;
59 mutable float orig_in_length;
60 mutable float orig_out_length;
61
62 // Cache information of secondary handles.
63 Vector<HandleInfo> _secondary_handles_info;
64
65public:
66 virtual String get_handle_name(int p_id, bool p_secondary) const override;
67 virtual Variant get_handle_value(int p_id, bool p_secondary) const override;
68 virtual void set_handle(int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
69 virtual void commit_handle(int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
70
71 virtual void redraw() override;
72 Path3DGizmo(Path3D *p_path = nullptr);
73};
74
75class Path3DGizmoPlugin : public EditorNode3DGizmoPlugin {
76 GDCLASS(Path3DGizmoPlugin, EditorNode3DGizmoPlugin);
77
78protected:
79 Ref<EditorNode3DGizmo> create_gizmo(Node3D *p_spatial) override;
80
81public:
82 String get_gizmo_name() const override;
83 int get_priority() const override;
84 Path3DGizmoPlugin();
85};
86
87class Path3DEditorPlugin : public EditorPlugin {
88 GDCLASS(Path3DEditorPlugin, EditorPlugin);
89
90 HBoxContainer *topmenu_bar = nullptr;
91 Button *curve_create = nullptr;
92 Button *curve_edit = nullptr;
93 Button *curve_edit_curve = nullptr;
94 Button *curve_del = nullptr;
95 Button *curve_close = nullptr;
96 MenuButton *handle_menu = nullptr;
97
98 enum Mode {
99 MODE_CREATE,
100 MODE_EDIT,
101 MODE_EDIT_CURVE,
102 MODE_DELETE,
103 ACTION_CLOSE
104 };
105
106 Path3D *path = nullptr;
107
108 void _update_theme();
109
110 void _mode_changed(int p_mode);
111 void _close_curve();
112 void _handle_option_pressed(int p_option);
113 bool handle_clicked = false;
114 bool mirror_handle_angle;
115 bool mirror_handle_length;
116
117 enum HandleOption {
118 HANDLE_OPTION_ANGLE,
119 HANDLE_OPTION_LENGTH
120 };
121
122protected:
123 void _notification(int p_what);
124 static void _bind_methods();
125
126public:
127 Path3D *get_edited_path() { return path; }
128
129 static Path3DEditorPlugin *singleton;
130 virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override;
131
132 virtual String get_name() const override { return "Path3D"; }
133 bool has_main_screen() const override { return false; }
134 virtual void edit(Object *p_object) override;
135 virtual bool handles(Object *p_object) const override;
136 virtual void make_visible(bool p_visible) override;
137
138 bool mirror_angle_enabled() { return mirror_handle_angle; }
139 bool mirror_length_enabled() { return mirror_handle_length; }
140 bool is_handle_clicked() { return handle_clicked; }
141 void set_handle_clicked(bool clicked) { handle_clicked = clicked; }
142
143 Path3DEditorPlugin();
144 ~Path3DEditorPlugin();
145};
146
147#endif // PATH_3D_EDITOR_PLUGIN_H
148