Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/scene/3d/path_3d_editor_plugin.h
9902 views
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
#pragma once
32
33
#include "editor/plugins/editor_plugin.h"
34
#include "editor/scene/3d/node_3d_editor_gizmos.h"
35
#include "scene/3d/camera_3d.h"
36
#include "scene/3d/path_3d.h"
37
38
class HBoxContainer;
39
class MenuButton;
40
class ConfirmationDialog;
41
42
class 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
Ref<StandardMaterial3D> debug_material;
59
mutable Vector3 original;
60
mutable float orig_in_length;
61
mutable float orig_out_length;
62
mutable float disk_size = 0.8;
63
64
// Index that should have swapped control points for achieving an outwards curve.
65
int swapped_control_points_idx = -1;
66
bool control_points_overlapped = false;
67
68
// Cache information of secondary handles.
69
Vector<HandleInfo> _secondary_handles_info;
70
71
void _update_transform_gizmo();
72
73
public:
74
virtual String get_handle_name(int p_id, bool p_secondary) const override;
75
virtual Variant get_handle_value(int p_id, bool p_secondary) const override;
76
virtual void set_handle(int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
77
virtual void commit_handle(int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
78
79
virtual void redraw() override;
80
Path3DGizmo(Path3D *p_path = nullptr, float p_disk_size = 0.8);
81
};
82
83
class Path3DGizmoPlugin : public EditorNode3DGizmoPlugin {
84
GDCLASS(Path3DGizmoPlugin, EditorNode3DGizmoPlugin);
85
86
float disk_size = 0.8;
87
88
// Locking basis is meant to ensure a predictable behavior during translation of the curve points in "local space transform mode".
89
// Without the locking, the gizmo/point, in "local space transform mode", wouldn't follow a straight path and would curve and twitch in an unpredictable way.
90
HashMap<int, Basis> transformation_locked_basis;
91
92
protected:
93
Ref<EditorNode3DGizmo> create_gizmo(Node3D *p_spatial) override;
94
95
public:
96
virtual bool has_gizmo(Node3D *p_spatial) override;
97
String get_gizmo_name() const override;
98
99
virtual void redraw(EditorNode3DGizmo *p_gizmo) override;
100
101
virtual int subgizmos_intersect_ray(const EditorNode3DGizmo *p_gizmo, Camera3D *p_camera, const Vector2 &p_point) const override;
102
virtual Vector<int> subgizmos_intersect_frustum(const EditorNode3DGizmo *p_gizmo, const Camera3D *p_camera, const Vector<Plane> &p_frustum) const override;
103
virtual Transform3D get_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id) const override;
104
virtual void set_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id, Transform3D p_transform) override;
105
virtual void commit_subgizmos(const EditorNode3DGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel = false) override;
106
107
int get_priority() const override;
108
Path3DGizmoPlugin(float p_disk_size);
109
};
110
111
class Path3DEditorPlugin : public EditorPlugin {
112
GDCLASS(Path3DEditorPlugin, EditorPlugin);
113
114
friend class Path3DGizmo;
115
friend class Path3DGizmoPlugin;
116
117
Ref<Path3DGizmoPlugin> path_3d_gizmo_plugin;
118
119
HBoxContainer *topmenu_bar = nullptr;
120
121
HBoxContainer *toolbar = nullptr;
122
Button *curve_create = nullptr;
123
Button *curve_edit = nullptr;
124
Button *curve_edit_curve = nullptr;
125
Button *curve_edit_tilt = nullptr;
126
Button *curve_del = nullptr;
127
Button *curve_closed = nullptr;
128
Button *curve_clear_points = nullptr;
129
MenuButton *handle_menu = nullptr;
130
131
Button *create_curve_button = nullptr;
132
ConfirmationDialog *clear_points_dialog = nullptr;
133
134
float disk_size = 0.8;
135
136
enum Mode {
137
MODE_CREATE,
138
MODE_EDIT,
139
MODE_EDIT_CURVE,
140
MODE_EDIT_TILT,
141
MODE_DELETE,
142
ACTION_CLOSE
143
};
144
145
Path3D *path = nullptr;
146
147
void _update_theme();
148
void _update_toolbar();
149
150
void _mode_changed(int p_mode);
151
void _toggle_closed_curve();
152
void _handle_option_pressed(int p_option);
153
bool handle_clicked = false;
154
bool mirror_handle_angle = true;
155
bool mirror_handle_length = true;
156
157
void _create_curve();
158
void _confirm_clear_points();
159
void _clear_points();
160
void _clear_curve_points();
161
void _restore_curve_points(const PackedVector3Array &p_points);
162
163
enum HandleOption {
164
HANDLE_OPTION_ANGLE,
165
HANDLE_OPTION_LENGTH
166
};
167
168
protected:
169
static void _bind_methods();
170
171
public:
172
Path3D *get_edited_path() { return path; }
173
174
inline static Path3DEditorPlugin *singleton = nullptr;
175
virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override;
176
177
virtual String get_plugin_name() const override { return "Path3D"; }
178
bool has_main_screen() const override { return false; }
179
virtual void edit(Object *p_object) override;
180
virtual bool handles(Object *p_object) const override;
181
virtual void make_visible(bool p_visible) override;
182
183
bool mirror_angle_enabled() { return mirror_handle_angle; }
184
bool mirror_length_enabled() { return mirror_handle_length; }
185
bool is_handle_clicked() { return handle_clicked; }
186
void set_handle_clicked(bool clicked) { handle_clicked = clicked; }
187
188
Path3DEditorPlugin();
189
};
190
191